Skip to content

Commit

Permalink
Merge pull request #21 from compgen-io/bed-combine-2
Browse files Browse the repository at this point in the history
Bed combine 2
  • Loading branch information
mbreese authored Dec 10, 2024
2 parents 93fb93c + b381e06 commit 657b479
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 262 deletions.
43 changes: 43 additions & 0 deletions src/java/io/compgen/ngsutils/bed/BedStrandFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.compgen.ngsutils.bed;

import java.util.Iterator;

import io.compgen.ngsutils.bam.Strand;

public class BedStrandFilter implements Iterator<BedRecord>{
protected final Iterator<BedRecord> it;
protected final Strand strand;

protected BedRecord cur = null;

public BedStrandFilter(Iterator<BedRecord> it, Strand strand) {
this.it = it;
this.strand = strand;
}
@Override
public boolean hasNext() {
if (cur == null && it.hasNext()) {
populate();
}
return cur != null;
}
@Override
public BedRecord next() {
BedRecord ret = cur;
cur = null;
populate();

return ret;
}

private void populate() {
while (it.hasNext()) {
BedRecord tmp = it.next();
if (strand.matches(tmp.coord.strand)) {
cur = tmp;
return;
}
}
}
}

Loading

0 comments on commit 657b479

Please sign in to comment.