Search in sources :

Example 1 with SynchronousReferenceLookupAdapter

use of au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter in project gridss by PapenfussLab.

the class ExtractSVReadsTest method regression_should_extract_split_read_alignments_as_group_2.

// @Test
@Category(Hg38Tests.class)
public void regression_should_extract_split_read_alignments_as_group_2() throws IOException {
    File ref = Hg38Tests.findHg38Reference();
    ReferenceLookup lookup = new SynchronousReferenceLookupAdapter(new IndexedFastaSequenceFile(ref));
    Files.copy(new File("src/test/resources/sa.split/test2.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());
		}*/
    // primary read pair alignment implies an unexpected library fragment size = extract them all
    Assert.assertEquals(ImmutableList.of(true, true, true, true), 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 2 with SynchronousReferenceLookupAdapter

use of au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter in project gridss by PapenfussLab.

the class SingleReadEvidenceTest method assembly_scoring_should_be_symmetrical.

@Test
@Category(Hg19Tests.class)
public void assembly_scoring_should_be_symmetrical() throws FileNotFoundException {
    File sam = new File("src/test/resources/assembly_score_mismatch.sam");
    File ref = Hg19Tests.findHg19Reference();
    ProcessingContext pc = new ProcessingContext(getFSContext(), ref, new SynchronousReferenceLookupAdapter(new IndexedFastaSequenceFile(ref)), null, getConfig());
    SAMEvidenceSource ses = SES(pc);
    SamReader sr = SamReaderFactory.make().open(sam);
    List<SAMRecord> in = Lists.newArrayList(sr.iterator());
    List<SingleReadEvidence> sreList = in.stream().flatMap(record -> SingleReadEvidence.createEvidence(ses, 0, record).stream()).collect(Collectors.toList());
    ImmutableListMultimap<String, SingleReadEvidence> mm = Multimaps.index(sreList, sre -> sre.getSAMRecord().getReadName());
    for (Entry<String, Collection<SingleReadEvidence>> entry : mm.asMap().entrySet()) {
        float bequal = entry.getValue().iterator().next().getBreakendQual();
        float bpqual = ((SplitReadEvidence) entry.getValue().iterator().next()).getBreakpointQual();
        for (SingleReadEvidence sre : entry.getValue()) {
            assertEquals(bequal, sre.getBreakendQual(), 0);
            assertEquals(bpqual, ((SplitReadEvidence) sre).getBreakpointQual(), 0);
        }
    }
}
Also used : SequenceUtil(htsjdk.samtools.util.SequenceUtil) InMemoryReferenceSequenceFile(au.edu.wehi.idsv.picard.InMemoryReferenceSequenceFile) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) Category(org.junit.experimental.categories.Category) SamReader(htsjdk.samtools.SamReader) Collectors(java.util.stream.Collectors) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) SAMRecord(htsjdk.samtools.SAMRecord) Multimaps(com.google.common.collect.Multimaps) List(java.util.List) Lists(com.google.common.collect.Lists) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) Assert.assertFalse(org.junit.Assert.assertFalse) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Entry(java.util.Map.Entry) SamReaderFactory(htsjdk.samtools.SamReaderFactory) Assert.assertEquals(org.junit.Assert.assertEquals) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) SamReader(htsjdk.samtools.SamReader) SAMRecord(htsjdk.samtools.SAMRecord) Collection(java.util.Collection) InMemoryReferenceSequenceFile(au.edu.wehi.idsv.picard.InMemoryReferenceSequenceFile) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 3 with SynchronousReferenceLookupAdapter

use of au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter in project gridss by PapenfussLab.

the class SplitReadEvidenceTest method indel_mismapping_false_positive_assembly_should_not_throw_homology_error.

@Test
@Category(Hg19Tests.class)
public void indel_mismapping_false_positive_assembly_should_not_throw_homology_error() throws IOException {
    File ref = Hg19Tests.findHg19Reference();
    IndexedFastaSequenceFile indexed = new IndexedFastaSequenceFile(ref);
    TemporaryFolder folder = new TemporaryFolder();
    folder.create();
    ProcessingContext pc = new ProcessingContext(new FileSystemContext(folder.getRoot(), folder.getRoot(), 500000), ref, new SynchronousReferenceLookupAdapter(indexed), new ArrayList<Header>(), getConfig());
    // File bam = new File(folder.getRoot(), "input.bam");
    // Files.copy(new File("src/test/resources/indel_mismapping_false_positive_assembly.sv.bam"), bam);
    SAMEvidenceSource ses = new MockSAMEvidenceSource(pc);
    List<SAMRecord> records = IntermediateFilesTest.getRecords(new File("src/test/resources/indel_mismapping_false_positive_assembly.sv.bam"));
    for (SAMRecord r : records) {
        if ("asm5".equals(r.getReadName())) {
            for (SplitReadEvidence e : SplitReadEvidence.create(ses, r)) {
                assertTrue(e.isReference());
            }
        }
    }
    folder.delete();
}
Also used : IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) Header(htsjdk.samtools.metrics.Header) SAMFileHeader(htsjdk.samtools.SAMFileHeader) SAMRecord(htsjdk.samtools.SAMRecord) TemporaryFolder(org.junit.rules.TemporaryFolder) InMemoryReferenceSequenceFile(au.edu.wehi.idsv.picard.InMemoryReferenceSequenceFile) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 4 with SynchronousReferenceLookupAdapter

use of au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter in project gridss by PapenfussLab.

the class SAMEvidenceSourceTest method regression_indel_should_not_throw_exception.

// @Test
@Category(Hg38Tests.class)
public void regression_indel_should_not_throw_exception() throws IOException {
    File ref = Hg38Tests.findHg38Reference();
    ProcessingContext pc = new ProcessingContext(getFSContext(), ref, new SynchronousReferenceLookupAdapter(new IndexedFastaSequenceFile(ref)), null, getConfig());
    Files.copy(new File("src/test/resources/indelerror.bam"), input);
    SAMEvidenceSource source = new SAMEvidenceSource(pc, input, null, 0);
    Lists.newArrayList(source.iterator());
}
Also used : 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 5 with SynchronousReferenceLookupAdapter

use of au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter in project gridss by PapenfussLab.

the class Manual method should_not_include_concordant_read_pairs.

// @Test
@Category(Hg38Tests.class)
public void should_not_include_concordant_read_pairs() throws FileNotFoundException {
    File sam = new File("W:/hg38debug/D1_S1_L001_R1_001.bam.gridss.working/D1_S1_L001_R1_001.bam");
    File ref = Hg38Tests.findHg38Reference();
    ProcessingContext pc = new ProcessingContext(getFSContext(), ref, new SynchronousReferenceLookupAdapter(new IndexedFastaSequenceFile(ref)), null, getConfig());
    SAMEvidenceSource ses = new SAMEvidenceSource(pc, sam, null, 0, 0.995);
    List<DirectedEvidence> list = ses.iterator().stream().collect(Collectors.toList());
    List<DirectedEvidence> reads = list.stream().filter(e -> e instanceof DiscordantReadPair).map(e -> (DiscordantReadPair) e).filter(e -> e.getLocalledMappedRead().getReadName().equals("D00360:95:H2YWMBCXX:1:2107:5758:68093")).collect(Collectors.toList());
    Assert.assertEquals(0, reads.size());
}
Also used : Iterator(java.util.Iterator) Header(htsjdk.samtools.metrics.Header) IOException(java.io.IOException) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList) GridssConfiguration(au.edu.wehi.idsv.configuration.GridssConfiguration) List(java.util.List) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) Assert(org.junit.Assert) ConfigurationException(org.apache.commons.configuration.ConfigurationException) 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)

Aggregations

SynchronousReferenceLookupAdapter (au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter)7 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)7 File (java.io.File)7 Category (org.junit.experimental.categories.Category)7 SAMRecord (htsjdk.samtools.SAMRecord)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 IOException (java.io.IOException)4 Assert (org.junit.Assert)4 Test (org.junit.Test)4 Lists (com.google.common.collect.Lists)3 SamReader (htsjdk.samtools.SamReader)3 SamReaderFactory (htsjdk.samtools.SamReaderFactory)3 Header (htsjdk.samtools.metrics.Header)3 FileNotFoundException (java.io.FileNotFoundException)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 FixedSizeReadPairConcordanceCalculator (au.edu.wehi.idsv.FixedSizeReadPairConcordanceCalculator)2 Hg38Tests (au.edu.wehi.idsv.Hg38Tests)2