diff --git a/qsv/src/org/qcmg/qsv/splitread/SplitReadContig.java b/qsv/src/org/qcmg/qsv/splitread/SplitReadContig.java index 191377726..9c0073a03 100644 --- a/qsv/src/org/qcmg/qsv/splitread/SplitReadContig.java +++ b/qsv/src/org/qcmg/qsv/splitread/SplitReadContig.java @@ -219,6 +219,7 @@ public SplitReadAlignment getRight() { } public static SplitReadAlignment getSingleSplitReadAlignment(SplitReadAlignment left, SplitReadAlignment right) { + if (left == null && right != null) { return right; } else if (right == null && left != null) { @@ -492,7 +493,7 @@ public void parseConsensusAlign(List records) throws QSVException, I left = null; right = null; - if (confidenceLevel.equals(QSVConstants.LEVEL_SINGLE_CLIP) || knownSV.equalReference()) { + if (confidenceLevel.equals(QSVConstants.LEVEL_SINGLE_CLIP) || knownSV.equalReference()) { getSplitReadAlignments(null, records); } else { List leftRecords = new ArrayList<>(); @@ -506,12 +507,10 @@ public void parseConsensusAlign(List records) throws QSVException, I rightRecords.add(r); } } - getTranslocationSplitReadAlignments(null, leftRecords, rightRecords); + getTranslocationSplitReadAlignments(null, leftRecords, rightRecords); } - - - if (left != null & right != null) { + if (left != null & right != null & knownAndPotentialReferencesMatch(knownSV, left, right)) { //rearrange reorder(); @@ -609,6 +608,14 @@ public void parseConsensusAlign(List records) throws QSVException, I } } + public static boolean knownAndPotentialReferencesMatch(StructuralVariant currentSV, SplitReadAlignment leftAlign, SplitReadAlignment rightAlign) { + if (leftAlign != null & rightAlign != null) { + return (leftAlign.getReference().equals(currentSV.getLeftReference()) && rightAlign.getReference().equals(currentSV.getRightReference())) || + (rightAlign.getReference().equals(currentSV.getLeftReference()) && leftAlign.getReference().equals(currentSV.getRightReference())); + } + return false; + } + public static boolean leftLower(int leftStart, int rightStart) { return leftStart < rightStart; } @@ -652,7 +659,6 @@ void calculateMicrohomology() { } void recheckMicrohomologyForSingleAlignment() { - String leftRef = getReferenceSequence(splitreadSV.getLeftReference(), splitreadSV.getLeftBreakpoint() + 1, 0, 50, chromosomes); String rightRef = getReferenceSequence(splitreadSV.getRightReference(), splitreadSV.getRightBreakpoint() - 1, 50, 0, chromosomes); int end = leftSequence.length(); @@ -698,7 +704,11 @@ public static String getReferenceSequence(String reference, int breakpoint, int ConcurrentMap referenceMap = QSVUtil.getReferenceMap(); byte[] basesArray = referenceMap.get(reference); - + + if (start > end) { + logger.info("In getReferenceSequence method - Reference: " + reference + "breakpoint: " + breakpoint + " chromosome: " + c.getName() + " chromosome length: " + c.getTotalLength() + " start: " + start + " end: " + end + " basesArray length: " + basesArray.length); + throw new IllegalArgumentException("Start of reference sequence to retrieve is greater than end: " + start + " " + end); + } // array is zero-based, and picard is 1-based return new String(Arrays.copyOfRange(basesArray, start - 1, end - 1)); } @@ -937,7 +947,8 @@ private void getTranslocationSplitReadAlignments(SplitReadAlignment align, List< } if (index2 != -1) { rightRecords.remove(index2); - } + } + getTranslocationSplitReadAlignments(getSingleSplitReadAlignment(left, right), leftRecords, rightRecords); } } @@ -1101,4 +1112,5 @@ public static boolean matchingQueryString(int difference, int queryStart, int qu public String getMutationType() { return this.mutationType; } + } diff --git a/qsv/test/org/qcmg/qsv/splitread/SplitReadContigTest.java b/qsv/test/org/qcmg/qsv/splitread/SplitReadContigTest.java index d6b853870..d0f2c2395 100644 --- a/qsv/test/org/qcmg/qsv/splitread/SplitReadContigTest.java +++ b/qsv/test/org/qcmg/qsv/splitread/SplitReadContigTest.java @@ -233,6 +233,41 @@ public void setSplitReadAlignments() { assertEquals(true, right == null); } + @Test + public void testknownAndPotentialReferencesMatch() { + StructuralVariant knownSV = new StructuralVariant("chr10", "chr10", 89700299, 89712341, "1"); + SplitReadAlignment left = new SplitReadAlignment("chr10", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + SplitReadAlignment right = new SplitReadAlignment("chr10", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + assertTrue(SplitReadContig.knownAndPotentialReferencesMatch(knownSV, left, right)); + + knownSV = new StructuralVariant("chr10", "chr10", 89700299, 89712341, "1"); + left = new SplitReadAlignment("chr12", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + right = new SplitReadAlignment("chr10", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + assertFalse(SplitReadContig.knownAndPotentialReferencesMatch(knownSV, left, right)); + + knownSV = new StructuralVariant("chr10", "chr10", 89700299, 89712341, "1"); + left = new SplitReadAlignment("chr10", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + right = new SplitReadAlignment("chr12", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + assertFalse(SplitReadContig.knownAndPotentialReferencesMatch(knownSV, left, right)); + + knownSV = new StructuralVariant("chr10", "chr12", 89700299, 89712341, "1"); + left = new SplitReadAlignment("chr12", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + right = new SplitReadAlignment("chr10", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + assertTrue(SplitReadContig.knownAndPotentialReferencesMatch(knownSV, left, right)); + + knownSV = new StructuralVariant("chr10", "chr12", 89700299, 89712341, "1"); + left = new SplitReadAlignment("chr10", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + right = new SplitReadAlignment("chr12", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + assertTrue(SplitReadContig.knownAndPotentialReferencesMatch(knownSV, left, right)); + + knownSV = new StructuralVariant("chr10", "chr12", 89700299, 89712341, "1"); + left = new SplitReadAlignment("chr10", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + right = new SplitReadAlignment("chr10", QSVUtil.MINUS, 89700210, 89700299, 109, 282); + assertFalse(SplitReadContig.knownAndPotentialReferencesMatch(knownSV, left, right)); + + + } + @Test public void setSplitReadAlignments2() { /*