Skip to content

Commit

Permalink
checkpoint -- all working for 1 expanded insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Aug 26, 2023
1 parent 883ce13 commit 5fb3911
Show file tree
Hide file tree
Showing 21 changed files with 528 additions and 820 deletions.
87 changes: 3 additions & 84 deletions src/main/java/org/broad/igv/sam/AlignmentDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ public CoverageTrack getCoverageTrack() {
return coverageTrack;
}

public double getMinVisibleScale() {
return getVisibilityWindow() / 700;
}

public double getVisibilityWindow() {
return getPreferences().getAsFloat(SAM_MAX_VISIBLE_RANGE) * 1000;
}
Expand Down Expand Up @@ -269,12 +265,13 @@ public AlignmentInterval getLoadedInterval(ReferenceFrame frame) {
}

public AlignmentInterval getLoadedInterval(ReferenceFrame frame, boolean includeOverlaps) {
// Search for interval completely containining reference frame region
for (AlignmentInterval interval : intervalCache) {
if (interval.contains(frame.getCurrentRange())) {
return interval;
}
}
// No contains, look for overlap
// No interval contains entire region of frame, look for intervael with at least some overlap
if (includeOverlaps) {
for (AlignmentInterval interval : intervalCache) {
if (interval.overlaps(frame.getCurrentRange())) {
Expand Down Expand Up @@ -315,7 +312,7 @@ public void load(ReferenceFrame frame,
AlignmentTrack.RenderOptions renderOptions,
boolean expandEnds) {

if (frame.getChrName().equals(Globals.CHR_ALL) || frame.getScale() > getMinVisibleScale())
if (frame.getChrName().equals(Globals.CHR_ALL) || (frame.getEnd() - frame.getOrigin()) > getVisibilityWindow())
return; // should not happen

if (isLoaded(frame)) {
Expand Down Expand Up @@ -458,10 +455,6 @@ private AlignmentTrack.ExperimentType getExperimentType() {
return alignmentTrack == null ? null : alignmentTrack.getExperimentType();
}

private void setExperimentType(AlignmentTrack.ExperimentType type) {
if (alignmentTrack != null) alignmentTrack.setExperimentType(type);
}


public PackedAlignments getGroups(AlignmentInterval interval, AlignmentTrack.RenderOptions renderOptions) {
//AlignmentInterval interval = getLoadedInterval(context.getReferenceFrame());
Expand Down Expand Up @@ -573,18 +566,10 @@ public void alleleThresholdChanged() {
coverageTrack.setSnpThreshold(PreferencesManager.getPreferences().getAsFloat(SAM_ALLELE_THRESHOLD));
}

public boolean isTenX() {
return getLoader().isTenX();
}

public boolean isPhased() {
return getLoader().isPhased();
}

public boolean isMoleculo() {
return getLoader().isMoleculo();
}

public Collection<AlignmentInterval> getLoadedIntervals() {
return intervalCache;
}
Expand Down Expand Up @@ -629,71 +614,5 @@ public int getMaxReadCount() {

}

static class IntervalCache {

private int maxSize;
ArrayList<AlignmentInterval> intervals;

public IntervalCache() {
this(1);
}

public IntervalCache(int ms) {
this.maxSize = Math.max(1, ms);
intervals = new ArrayList<>(maxSize);
}

void setMaxSize(int ms, List<ReferenceFrame> frames) {
this.maxSize = Math.max(1, ms);
if (intervals.size() > maxSize) {
// Reduce size. Try to keep intervals that cover frame ranges. This involves a linear search
// of potentially (intervals.size X frames.size) elements. Don't attempt if this number is too large
if (frames.size() * intervals.size() < 25) {
ArrayList<AlignmentInterval> tmp = new ArrayList<>(maxSize);
for (AlignmentInterval interval : intervals) {
if (tmp.size() == maxSize) break;
for (ReferenceFrame frame : frames) {
Range range = frame.getCurrentRange();
if (interval.contains(range.getChr(), range.getStart(), range.getEnd())) {
tmp.add(interval);
break;
}
}
}
intervals = tmp;
} else {
intervals = new ArrayList(intervals.subList(0, maxSize));
intervals.trimToSize();
}
}
}

public void add(AlignmentInterval interval) {
if (intervals.size() >= maxSize) {
intervals.remove(0);
}
intervals.add(interval);
}

public AlignmentInterval getIntervalForRange(Range range) {

for (AlignmentInterval interval : intervals) {
if (interval.contains(range.getChr(), range.getStart(), range.getEnd())) {
return interval;
}
}

return null;

}

public Collection<AlignmentInterval> values() {
return intervals;
}

public void clear() {
intervals.clear();
}
}
}

72 changes: 7 additions & 65 deletions src/main/java/org/broad/igv/sam/AlignmentInterval.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class AlignmentInterval extends Locus {
private List<Alignment> alignments;
private SpliceJunctionHelper spliceJunctionHelper;
private List<DownsampledInterval> downsampledIntervals;

private PackedAlignments packedAlignments;

public AlignmentInterval(String chr, int start, int end,
Expand Down Expand Up @@ -99,7 +100,8 @@ static Alignment getFeatureContaining(List<Alignment> features, int right) {

/**
* Sort rows group by group
* @param option
*
* @param option
* @param location
*/
public void sortRows(SortOption option, double location, String tag, boolean invertSort, Set<String> priorityRecords) {
Expand All @@ -111,11 +113,11 @@ public void sortRows(SortOption option, double location, String tag, boolean inv

final int center = (int) location;
byte referenceBase = this.getReference(center);
Comparator<Row> rowComparator = option.getComparator(center, referenceBase, tag, invertSort);
Comparator<Row> rowComparator = option.getComparator(center, referenceBase, tag, invertSort);

if( priorityRecords != null && !priorityRecords.isEmpty()){
if (priorityRecords != null && !priorityRecords.isEmpty()) {
rowComparator = Comparator.comparing((Row row) -> row.getAlignments().stream()
.anyMatch( aln -> priorityRecords.contains(aln.getReadName())))
.anyMatch(aln -> priorityRecords.contains(aln.getReadName())))
.reversed()
.thenComparing(rowComparator);
}
Expand Down Expand Up @@ -183,6 +185,7 @@ public List<DownsampledInterval> getDownsampledIntervals() {
return downsampledIntervals;
}


public SpliceJunctionHelper getSpliceJunctionHelper() {
return this.spliceJunctionHelper;
}
Expand All @@ -207,65 +210,4 @@ public void dumpAlignments() {
}


/**
* An alignment iterator that iterates over packed rows. Used for
* repacking. Using the iterator avoids the need to copy alignments
* from the rows
*/
static class AlignmentIterator implements Iterator<Alignment> {

PriorityQueue<Row> rows;
Alignment nextAlignment;

AlignmentIterator(Map<String, List<Row>> groupedAlignmentRows) {
rows = new PriorityQueue(5, new Comparator<Row>() {

public int compare(Row o1, Row o2) {
return o1.getNextStartPos() - o2.getNextStartPos();
}
});

for (List<Row> alignmentRows : groupedAlignmentRows.values()) {
for (Row r : alignmentRows) {
r.resetIdx();
rows.add(r);
}
}

advance();
}

public boolean hasNext() {
return nextAlignment != null;
}

public Alignment next() {
Alignment tmp = nextAlignment;
if (tmp != null) {
advance();
}
return tmp;
}

private void advance() {

nextAlignment = null;
Row nextRow = null;
while (nextAlignment == null && !rows.isEmpty()) {
while ((nextRow = rows.poll()) != null) {
if (nextRow.hasNext()) {
nextAlignment = nextRow.nextAlignment();
break;
}
}
}
if (nextRow != null && nextAlignment != null) {
rows.add(nextRow);
}
}

public void remove() {
// ignore
}
}
}
Loading

0 comments on commit 5fb3911

Please sign in to comment.