Search in sources :

Example 16 with ChimericAlignment

use of au.edu.wehi.idsv.sam.ChimericAlignment in project gridss by PapenfussLab.

the class SplitReadEvidenceTest method involvesPrimaryReadAlignment_should_allow_primary_local.

@Test
public void involvesPrimaryReadAlignment_should_allow_primary_local() {
    List<SingleReadEvidence> list;
    SAMRecord r = Read(0, 1, "10M10S");
    r.setAttribute("SA", new ChimericAlignment(Read(0, 10, "10S10M")).toString());
    list = SingleReadEvidence.createEvidence(SES(), 0, r);
    assertTrue(list.stream().allMatch(e -> e.involvesPrimaryReadAlignment()));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) InMemoryReferenceSequenceFile(au.edu.wehi.idsv.picard.InMemoryReferenceSequenceFile) Assert.assertNotNull(org.junit.Assert.assertNotNull) Header(htsjdk.samtools.metrics.Header) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) SAMRecordUtil(au.edu.wehi.idsv.sam.SAMRecordUtil) Category(org.junit.experimental.categories.Category) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) Assert.assertFalse(org.junit.Assert.assertFalse) BiConsumer(java.util.function.BiConsumer) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) SAMRecord(htsjdk.samtools.SAMRecord) Test(org.junit.Test)

Example 17 with ChimericAlignment

use of au.edu.wehi.idsv.sam.ChimericAlignment in project gridss by PapenfussLab.

the class SplitReadEvidence method getRemoteEvidenceID.

@Override
public String getRemoteEvidenceID() {
    SAMRecord remote = this.getSAMRecord().deepCopy();
    remote.setReferenceName(remoteAlignment.rname);
    remote.setAlignmentStart(remoteAlignment.pos);
    remote.setReadUnmappedFlag(false);
    remote.setReadNegativeStrandFlag(remoteAlignment.isNegativeStrand);
    remote.setCigar(remoteAlignment.cigar);
    remote.setAttribute(SAMTag.SA.name(), new ChimericAlignment(this.getSAMRecord()).toString());
    SplitReadEvidence remoteEvidence = SplitReadEvidence.create(source, remote).get(0);
    return source.getContext().getEvidenceIDGenerator().getEvidenceID(remoteEvidence);
}
Also used : ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) SAMRecord(htsjdk.samtools.SAMRecord)

Example 18 with ChimericAlignment

use of au.edu.wehi.idsv.sam.ChimericAlignment in project gridss by PapenfussLab.

the class SplitReadEvidence method getBreakpointQual.

@Override
public float getBreakpointQual() {
    if (AssemblyAttributes.isAssembly(getSAMRecord())) {
        return scoreAssembly();
    }
    int softClipLength = getBreakendSequence().length;
    if (getSAMRecord().getSupplementaryAlignmentFlag()) {
        ChimericAlignment caThis = new ChimericAlignment(getSAMRecord());
        // The first record should be the primary
        ChimericAlignment caPrimary = ChimericAlignment.getChimericAlignments(getSAMRecord()).get(0);
        // before
        BreakendDirection primaryDirectionTowardThis = caThis.getFirstAlignedBaseReadOffset() < caPrimary.getFirstAlignedBaseReadOffset() ^ caPrimary.isNegativeStrand ? BreakendDirection.Backward : BreakendDirection.Forward;
        softClipLength = SAMRecordUtil.getSoftClipLength(caPrimary.cigar.getCigarElements(), primaryDirectionTowardThis);
    }
    return (float) getEvidenceSource().getContext().getConfig().getScoring().getModel().scoreSplitRead(getEvidenceSource().getMetrics(), softClipLength, getLocalMapq(), getRemoteMapq());
}
Also used : ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment)

Example 19 with ChimericAlignment

use of au.edu.wehi.idsv.sam.ChimericAlignment in project gridss by PapenfussLab.

the class ExtractSVReadsTest method regression_should_extract_split_read_alignments_as_group.

// @Test
@Category(Hg38Tests.class)
public void regression_should_extract_split_read_alignments_as_group() throws IOException {
    File ref = Hg38Tests.findHg38Reference();
    ReferenceLookup lookup = new SynchronousReferenceLookupAdapter(new IndexedFastaSequenceFile(ref));
    Files.copy(new File("src/test/resources/sa.split/test1.sam"), input);
    ExtractSVReads extract = new ExtractSVReads();
    // new ProcessingContext(getFSContext(), ref, lookup, null, getConfig());
    extract.setReference(lookup);
    extract.MIN_CLIP_LENGTH = 4;
    extract.INSERT_SIZE_METRICS = new File("src/test/resources/sa.split/test.insert_size_metrics");
    extract.READ_PAIR_CONCORDANCE_METHOD = ReadPairConcordanceMethod.PERCENTAGE;
    extract.OUTPUT = output;
    extract.INPUT = input;
    try (SamReader reader = SamReaderFactory.make().open(input)) {
        extract.setup(reader.getFileHeader(), input);
    }
    List<SAMRecord> records = getRecords(input);
    List<Boolean> result = records.stream().map(r -> extract.shouldExtract(ImmutableList.of(r), lookup)[0]).collect(Collectors.toList());
    /*
		for (int i = 0; i < records.size(); i++) {
			SAMRecord r = records.get(i);
			System.out.print(r.getSupplementaryAlignmentFlag() ? "S" : " ");
			System.out.print(r.getFirstOfPairFlag() ? "1" : "2");
			System.out.print(" Extracted=" + (result.get(i) ? "y" : "n"));
			System.out.print(" HasConcPair=" + (ExtractSVReads.hasReadPairingConsistentWithReference(extract.getReadPairConcordanceCalculator(), ImmutableList.of(r)) ? "y" : "n"));
			boolean[] ra = ExtractSVReads.hasReadAlignmentConsistentWithReference(ImmutableList.of(r));
			System.out.print(" HasConcRead=" + (ra[0] ? "y" : "n") + (ra[1] ? "y" : "n"));
			System.out.println(" " + new ChimericAlignment(r).toString());
		}
		*/
    Assert.assertEquals(records.stream().map(r -> r.getSecondOfPairFlag()).collect(Collectors.toList()), result);
    lookup.close();
}
Also used : FixedSizeReadPairConcordanceCalculator(au.edu.wehi.idsv.FixedSizeReadPairConcordanceCalculator) Iterables(com.google.common.collect.Iterables) ReadPairConcordanceMethod(au.edu.wehi.idsv.ReadPairConcordanceMethod) Iterators(com.google.common.collect.Iterators) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) StructuralVariantReadMetrics(gridss.analysis.StructuralVariantReadMetrics) ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) ReferenceLookup(au.edu.wehi.idsv.picard.ReferenceLookup) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) Category(org.junit.experimental.categories.Category) SamReader(htsjdk.samtools.SamReader) MetricsFile(htsjdk.samtools.metrics.MetricsFile) Collectors(java.util.stream.Collectors) File(java.io.File) SAMRecord(htsjdk.samtools.SAMRecord) List(java.util.List) Hg38Tests(au.edu.wehi.idsv.Hg38Tests) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) Assert.assertFalse(org.junit.Assert.assertFalse) Assert(org.junit.Assert) SamReaderFactory(htsjdk.samtools.SamReaderFactory) Assert.assertEquals(org.junit.Assert.assertEquals) SamReader(htsjdk.samtools.SamReader) ReferenceLookup(au.edu.wehi.idsv.picard.ReferenceLookup) SAMRecord(htsjdk.samtools.SAMRecord) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) Category(org.junit.experimental.categories.Category)

Example 20 with ChimericAlignment

use of au.edu.wehi.idsv.sam.ChimericAlignment in project gridss by PapenfussLab.

the class ExtractSVReadsTest method hasReadPairingConsistentWithReference_should_use_primary_alignment_for_split_alignments.

@Test
public void hasReadPairingConsistentWithReference_should_use_primary_alignment_for_split_alignments() {
    SAMRecord r = Read(0, 1, "5M5S");
    r.setAttribute("SA", new ChimericAlignment(Read(1, 50, "10M")).toString());
    r.setMateAlignmentStart(100);
    r.setMateNegativeStrandFlag(true);
    r.setMateReferenceIndex(1);
    r.setReadPairedFlag(true);
    r.setMateUnmappedFlag(false);
    r.setSupplementaryAlignmentFlag(true);
    Assert.assertTrue(ExtractSVReads.hasReadPairingConsistentWithReference(new FixedSizeReadPairConcordanceCalculator(0, 100), ImmutableList.of(r)));
}
Also used : ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) SAMRecord(htsjdk.samtools.SAMRecord) FixedSizeReadPairConcordanceCalculator(au.edu.wehi.idsv.FixedSizeReadPairConcordanceCalculator) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Test(org.junit.Test)

Aggregations

ChimericAlignment (au.edu.wehi.idsv.sam.ChimericAlignment)20 SAMRecord (htsjdk.samtools.SAMRecord)16 Test (org.junit.Test)11 List (java.util.List)5 IntermediateFilesTest (au.edu.wehi.idsv.IntermediateFilesTest)4 SynchronousReferenceLookupAdapter (au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter)4 ImmutableList (com.google.common.collect.ImmutableList)4 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)4 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Assert (org.junit.Assert)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertFalse (org.junit.Assert.assertFalse)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Category (org.junit.experimental.categories.Category)4 FixedSizeReadPairConcordanceCalculator (au.edu.wehi.idsv.FixedSizeReadPairConcordanceCalculator)3 SAMRecordUtil (au.edu.wehi.idsv.sam.SAMRecordUtil)3 Lists (com.google.common.collect.Lists)3 SAMFileHeader (htsjdk.samtools.SAMFileHeader)3