Skip to content

Commit

Permalink
Merge pull request arq5x#1030 from brentp/genomeCoverageFormat
Browse files Browse the repository at this point in the history
genomecov: use integer when scale == 1.0
  • Loading branch information
arq5x authored Nov 30, 2022
2 parents a6fc2ea + e470be7 commit a658b71
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions src/genomeCoverageBed/genomeCoverageBed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void BedGenomeCoverage::StartNewChrom(const string& newChrom) {
if (_visitedChromosomes.find(newChrom) != _visitedChromosomes.end()) {
cerr << "Input error: Chromosome "
<< _currChromName
<< " found in non-sequential lines. This suggests that the input file is not sorted correctly."
<< " found in non-sequential lines. This suggests that the input file is not sorted correctly."
<< endl;
}
_visitedChromosomes.insert(newChrom);
Expand All @@ -121,9 +121,9 @@ void BedGenomeCoverage::StartNewChrom(const string& newChrom) {
if (_currChromSize >= 0)
_currChromCoverage.resize(_currChromSize);
else {
cerr << "Input error: Chromosome "
<< _currChromName
<< " found in your input file but not in your genome file."
cerr << "Input error: Chromosome "
<< _currChromName
<< " found in your input file but not in your genome file."
<< endl;
exit(1);
}
Expand All @@ -132,7 +132,7 @@ void BedGenomeCoverage::StartNewChrom(const string& newChrom) {

void BedGenomeCoverage::AddCoverage(CHRPOS start, CHRPOS end) {
// process the first line for this chromosome.
// make sure the coordinates fit within the chrom
// make sure the coordinates fit within the chrom
if (start < _currChromSize)
_currChromCoverage[start].starts++;
if (end >= 0 && end < _currChromSize)
Expand Down Expand Up @@ -165,16 +165,16 @@ void BedGenomeCoverage::CoverageBed() {
if (_bed->_status == BED_VALID) {
if (_filterByStrand == true) {
if (a.strand.empty()) {
cerr << "Input error: Interval is missing a strand value on line "
<< _bed->_lineNum
cerr << "Input error: Interval is missing a strand value on line "
<< _bed->_lineNum
<< "." <<endl;
exit(1);
}
if ( ! (a.strand == "-" || a.strand == "+") ) {
cerr << "Input error: Invalid strand value ("
<< a.strand << ") on line "
<< _bed->_lineNum
<< "."
cerr << "Input error: Invalid strand value ("
<< a.strand << ") on line "
<< _bed->_lineNum
<< "."
<< endl;
exit(1);
}
Expand Down Expand Up @@ -258,8 +258,8 @@ void BedGenomeCoverage::CoverageBam(string bamFile) {
// open the BAM file
BamReader reader;
if (!reader.Open(bamFile)) {
cerr << "Failed to open BAM file "
<< bamFile
cerr << "Failed to open BAM file "
<< bamFile
<< endl;
exit(1);
}
Expand Down Expand Up @@ -384,8 +384,11 @@ void BedGenomeCoverage::ReportChromCoverage(const vector<DEPTH> &chromCov, const

depth += chromCov[pos].starts;
// report the depth for this position.
if (depth>0 || !_eachBaseZeroBased)
cout << chrom << "\t" << pos+offset << "\t" << depth * _scale << endl;
if (depth>0 || !_eachBaseZeroBased) {
cout << chrom << "\t" << pos+offset << "\t"
<< (_scale == 1.0 ? depth : depth * _scale)
<< endl;
}
depth = depth - chromCov[pos].ends;
}
}
Expand Down Expand Up @@ -488,13 +491,13 @@ void BedGenomeCoverage::ReportChromCoverageBedGraph(const vector<DEPTH> &chromCo
if (lastDepth >= _max) {
lastDepth = _max;
}
cout << chrom
<< "\t"
<< lastStart
<< "\t"
<< pos
<< "\t"
<< lastDepth * _scale
cout << chrom
<< "\t"
<< lastStart
<< "\t"
<< pos
<< "\t"
<< (_scale == 1.0 ? lastDepth : lastDepth * _scale)
<< endl;
}
//Set current position as the new interval start + depth
Expand All @@ -508,13 +511,13 @@ void BedGenomeCoverage::ReportChromCoverageBedGraph(const vector<DEPTH> &chromCo
}
//Print information about the last position
if ( (lastDepth != -1) && (lastDepth > 0 || _bedGraphAll) ) {
cout << chrom
<< "\t"
<< lastStart
<< "\t"
<< chromSize
<< "\t"
<< lastDepth * _scale
cout << chrom
<< "\t"
<< lastStart
<< "\t"
<< chromSize
<< "\t"
<< (_scale == 1.0 ? lastDepth : lastDepth * _scale)
<< endl;
}
}

0 comments on commit a658b71

Please sign in to comment.