Skip to content

Commit

Permalink
- made progress logger emit read-names if it detects that the coordin…
Browse files Browse the repository at this point in the history
…ates are not strictly increasing.
  • Loading branch information
Yossi Farjoun committed Feb 22, 2019
1 parent 7300d76 commit 8c2b4de
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/main/java/htsjdk/samtools/util/AbstractProgressLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ abstract public class AbstractProgressLogger implements ProgressLoggerInterface
private String lastChrom = null;
private int lastPos = 0;
private String lastReadName = null;
private long countNonIncreasing = 0;
final private long PRINT_READ_NAME_THRESHOLD = 1000;

/**
* Construct an AbstractProgressLogger.
Expand Down Expand Up @@ -62,10 +64,10 @@ private synchronized void record() {
else readInfo = this.lastChrom + ":" + fmt.format(this.lastPos);

final String rnInfo;
if(lastReadName != null) {

if (lastReadName != null && countNonIncreasing > PRINT_READ_NAME_THRESHOLD) {
rnInfo = ". Last read name: " + lastReadName;
}
else {
} else {
rnInfo = "";
}

Expand All @@ -80,7 +82,7 @@ private synchronized void record() {
* @return boolean true if logging was triggered, false otherwise
*/
public synchronized boolean log() {
if (this.processed % this.n != 0) {
if (processed % this.n != 0) {
record();
return true;
}
Expand All @@ -90,13 +92,21 @@ public synchronized boolean log() {
}

protected synchronized boolean record(final String chrom, final int pos, final String rname) {
this.lastChrom = chrom;
this.lastPos = pos;
this.lastReadName = rname;
if (this.lastStartTime == -1) {
this.lastStartTime = System.currentTimeMillis();
lastChrom = chrom;
if (pos >= lastPos) {
countNonIncreasing = Math.max(0, countNonIncreasing--);
} else {
countNonIncreasing++;
if (countNonIncreasing == PRINT_READ_NAME_THRESHOLD) {
log("Seen many non-increasing record positions. Printing Readnames as well.");
}
}
if (++this.processed % this.n == 0) {
lastPos = pos;
lastReadName = rname;
if (lastStartTime == -1) {
lastStartTime = System.currentTimeMillis();
}
if (++processed % n == 0) {
record();
return true;
}
Expand All @@ -118,8 +128,7 @@ public synchronized boolean record(final String chrom, final int pos) {
public synchronized boolean record(final SAMRecord rec) {
if (SAMRecord.NO_ALIGNMENT_REFERENCE_NAME.equals(rec.getReferenceName())) {
return record(null, 0, rec.getReadName());
}
else {
} else {
return record(rec.getReferenceName(), rec.getAlignmentStart(), rec.getReadName());
}
}
Expand All @@ -140,9 +149,11 @@ public boolean record(final SAMRecord... recs) {

/** Left pads a string until it is at least the given length. */
private String pad (String in, final int length) {
while (in.length() < length) {
in = " " + in;
StringBuilder inBuilder = new StringBuilder(in);
while (inBuilder.length() < length) {
inBuilder.insert(0, " ");
}
in = inBuilder.toString();

return in;
}
Expand Down

0 comments on commit 8c2b4de

Please sign in to comment.