Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -532,29 +532,30 @@ public static List<BLATRecord> removeOverlappingRecords(List<BLATRecord> origina
if (null == originalList) {
throw new IllegalArgumentException("Null list supplied as argument to removeOverlappingRecords!");
}
// if (originalList.size() < 2) return originalList;
int size = originalList.size();
if (size < 2) {
return originalList;
}
List<BLATRecord> nonOverlappingList = new ArrayList<>(size);

List<BLATRecord> nonOverlappingList = new ArrayList<>(size + 1);

/*
* sort the original list
* sort the original list
*/
originalList.sort(null);
/*
* add the entry with the highest score to the new list
*/
nonOverlappingList.add(originalList.get(size - 1));

for (int i = size - 2 ; i >= 0 ; i--) {
if ( ! doesRecordOverlapEntriesInList(nonOverlappingList, originalList.get(i))) {
nonOverlappingList.add(originalList.get(i));
}
}
return nonOverlappingList;

}

/**
Expand Down Expand Up @@ -593,17 +594,18 @@ public static boolean doesRecordOverlapEntriesInList(List<BLATRecord> records, B
* @return
*/
public static boolean doRecordsOverlapReference(BLATRecord r1, BLATRecord r2) {
if (null != r1 && null != r2 && r1.getTName().equals(r2.getTName())) {
int r1Start = r1.getStartPos();
int r1End = r1.getEndPos();
int r2Start = r2.getStartPos();
int r2End = r2.getEndPos();

if ((r2Start >= r1Start && r2Start < r1End) || (r2End > r1Start && r2End <= r1End)) {
return true;
}
}
return false;
if (r1 == null || r2 == null) return false;
final String c1 = r1.getTName();
final String c2 = r2.getTName();
if (c1 == null || !c1.equals(c2)) return false;

final int s1 = r1.getStartPos();
final int e1 = r1.getEndPos();
final int s2 = r2.getStartPos();
final int e2 = r2.getEndPos();

// overlap if max(start) < min(end)
return (s1 < e2) && (s2 < e1);
}

/**
Expand Down
36 changes: 18 additions & 18 deletions q3tiledaligner/src/au/edu/qimr/tiledaligner/util/TARecordUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void trimRangesToRemoveOverlap(int[][] ranges, ChrPosition[] cps)
* trim ranges if there is an overlap
*/
for (int j = 0 ; j < ranges.length - 1; j++) {
if (j + 1 < ranges.length) {
// if (j + 1 < ranges.length) {
int [] thisIntArray = ranges[j];
int [] nextIntArray = ranges[j + 1];
ChrPosition thisCP = cps[j];
Expand Down Expand Up @@ -253,7 +253,7 @@ public static void trimRangesToRemoveOverlap(int[][] ranges, ChrPosition[] cps)

}
}
}
// }
}
}

Expand All @@ -269,16 +269,16 @@ public static void trimRangesToRemoveOverlap(int[][] ranges, ChrPosition[] cps)
* @return
*/
public static int[] sortTileCount(int[] tileCounts) {
return Arrays.stream(tileCounts)
.mapToObj(k -> NumberUtils.splitIntInto2(k))
.sorted((a,b) -> {int diff = Integer.compare((a[0] - a[1]), (b[0] - b[1]));
if (diff == 0) {
diff = b[1] - a[1];
}
return diff;})
.mapToInt(a -> NumberUtils.pack2IntsInto1(a[0], a[1]))
.toArray();

return Arrays.stream(tileCounts)
.mapToObj(NumberUtils::splitIntInto2)
.sorted((a,b) -> {int diff = Integer.compare((a[0] - a[1]), (b[0] - b[1]));
if (diff == 0) {
diff = b[1] - a[1];
}
return diff;})
.mapToInt(a -> NumberUtils.pack2IntsInto1(a[0], a[1]))
.toArray();
}


Expand Down Expand Up @@ -378,7 +378,7 @@ public static TIntObjectMap<Set<IntLongPairs>> getSplitStartPositions(TARecord r
* check that pairs is not a subset of existing pairs
*/
if ( ! IntLongPairsUtil.isPairsASubSetOfExistingPairs(getPairsFromMap(results), pairs)) {
Set<IntLongPairs> resultsListList = results.putIfAbsent(IntLongPairsUtil.getBasesCoveredByIntLongPairs(pairs, seqLength, TILE_LENGTH), new HashSet<>(Arrays.asList(pairs)));
Set<IntLongPairs> resultsListList = results.putIfAbsent(IntLongPairsUtil.getBasesCoveredByIntLongPairs(pairs, seqLength, TILE_LENGTH), new HashSet<>(List.of(pairs)));
if (null != resultsListList) {
resultsListList.add(pairs);
}
Expand Down Expand Up @@ -419,7 +419,7 @@ public static TIntObjectMap<Set<IntLongPairs>> getSplitStartPositions(TARecord r
* check that pairs is not a subset of existing pairs
*/
if ( ! IntLongPairsUtil.isPairsASubSetOfExistingPairs(getPairsFromMap(results), pairs)) {
Set<IntLongPairs> resultsListList = results.putIfAbsent(IntLongPairsUtil.getBasesCoveredByIntLongPairs(pairs, seqLength, TILE_LENGTH), new HashSet<>(Arrays.asList(pairs)));
Set<IntLongPairs> resultsListList = results.putIfAbsent(IntLongPairsUtil.getBasesCoveredByIntLongPairs(pairs, seqLength, TILE_LENGTH), new HashSet<>(List.of(pairs)));
if (null != resultsListList) {
resultsListList.add(pairs);
}
Expand Down Expand Up @@ -455,17 +455,17 @@ public static TIntObjectMap<Set<IntLongPairs>> getSplitStartPositions(TARecord r

public static List<IntLongPairs> getPairsFromMap(TIntObjectMap<Set<IntLongPairs>> map) {
List<IntLongPairs> list = new ArrayList<>();
map.forEachValue(s -> list.addAll(s));
map.forEachValue(list::addAll);
return list;
}

public static IntLongPairs getILPSFromLists(List<IntLongPair> list1, List<IntLongPair> list2, IntLongPair pair) {
List<IntLongPair> results = new ArrayList<>(4);
results.add(pair);
Optional<IntLongPair> list1ILP = getBestILPFromList(list1, pair);
list1ILP.ifPresent(ilp -> results.add(ilp));
list1ILP.ifPresent(results::add);
Optional<IntLongPair> list2ILP = getBestILPFromList(list2, pair);
list2ILP.ifPresent(ilp -> results.add(ilp));
list2ILP.ifPresent(results::add);
results.sort(null);
return new IntLongPairs(results.toArray(new IntLongPair[]{}));
}
Expand Down Expand Up @@ -496,7 +496,7 @@ public static Optional<IntLongPair> getBestILPFromList(List<IntLongPair> list, I
/*
* if leading candidate is too far away from original entry, return empty optional
*/
IntLongPair ilp = list.get(0);
IntLongPair ilp = list.getFirst();
return Optional.of(ilp);

} else {
Expand Down
Loading