Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making changes to reduce size of giant interval lists #1309

Merged
merged 3 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/htsjdk/samtools/util/IntervalList.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ public static IntervalList fromReader(final BufferedReader in) {

// Then read in the intervals
final FormatUtil format = new FormatUtil();
String lastSeq = null;
do {
if (line.trim().isEmpty()) {
continue; // skip over blank lines
Expand All @@ -544,7 +545,12 @@ public static IntervalList fromReader(final BufferedReader in) {
}

// Then parse them out
final String seq = fields[SEQUENCE_POS];
String seq = fields[SEQUENCE_POS];
if (seq.equals(lastSeq)) {
seq = lastSeq;
}
lastSeq = seq;

final int start = format.parseInt(fields[START_POS]);
final int end = format.parseInt(fields[END_POS]);
if (start < 1) {
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/htsjdk/samtools/util/OverlapDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,19 @@ public void addLhs(final T object, final Locatable interval) {
final int start = interval.getStart() + this.lhsBuffer;
final int end = interval.getEnd() - this.lhsBuffer;

final Set<T> objects = new HashSet<>(1);
objects.add(object);
final Set<T> newValue = Collections.singleton(object);
if (start <= end) { // Don't put in sequences that have no overlappable bases
final Set<T> alreadyThere = tree.put(start, end, objects);
final Set<T> alreadyThere = tree.put(start, end, newValue);
if (alreadyThere != null) {
alreadyThere.add(object);
tree.put(start, end, alreadyThere);
if( alreadyThere.size() == 1){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should be implemented within the IntervalTree class as a computeIfPresent method...

Set<T> mutableSet = new HashSet<>(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm. better find out if you got a mutable one and just add the new element if so...no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean with an instanceof check? As it's written it should be immutable always if it's exactly size 1 and mutable otherwise. It's a bit awkward but I thought maybe relying on the size was better than relying on the class. I can change that though.

mutableSet.addAll(alreadyThere);
mutableSet.add(object);
tree.put(start, end, mutableSet);
} else {
alreadyThere.add(object);
tree.put(start, end, alreadyThere);
}
}
}
}
Expand Down