Search in sources :

Example 36 with IndexedFastaSequenceFile

use of htsjdk.samtools.reference.IndexedFastaSequenceFile in project ASCIIGenome by dariober.

the class TrackPileup method getConsensusSequence.

private char[] getConsensusSequence() throws IOException {
    // We could get the refseq from genomicCoords but maybe safer to extract it again from scratch.
    byte[] refSeq = null;
    if (this.getGc().getFastaFile() != null) {
        IndexedFastaSequenceFile faSeqFile = new IndexedFastaSequenceFile(new File(this.getGc().getFastaFile()));
        refSeq = faSeqFile.getSubsequenceAt(this.getGc().getChrom(), this.getGc().getFrom(), this.getGc().getTo()).getBases();
        faSeqFile.close();
    }
    char[] consensusSequence = new char[this.getGc().getTo() - this.getGc().getFrom() + 1];
    int i = 0;
    for (int pos = this.getGc().getFrom(); pos <= this.getGc().getTo(); pos++) {
        // Empty char assuming there is no coverage.
        char consensus = ' ';
        if (this.loci.get(this.getGc().getChrom()).containsKey(pos)) {
            // If containsKey then the position has coverage.
            Locus loc = this.loci.get(this.getGc().getChrom()).get(pos);
            consensus = loc.getConsensus();
            if (refSeq != null) {
                char ref = Character.toUpperCase((char) refSeq[loc.pos - this.getGc().getFrom()]);
                if (ref == Character.toUpperCase(consensus)) {
                    consensus = '=';
                }
            }
        }
        consensusSequence[i] = consensus;
        i++;
    }
    return consensusSequence;
}
Also used : File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile)

Example 37 with IndexedFastaSequenceFile

use of htsjdk.samtools.reference.IndexedFastaSequenceFile 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 38 with IndexedFastaSequenceFile

use of htsjdk.samtools.reference.IndexedFastaSequenceFile 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 39 with IndexedFastaSequenceFile

use of htsjdk.samtools.reference.IndexedFastaSequenceFile 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 40 with IndexedFastaSequenceFile

use of htsjdk.samtools.reference.IndexedFastaSequenceFile 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

IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)57 File (java.io.File)34 SamReader (htsjdk.samtools.SamReader)22 SAMRecord (htsjdk.samtools.SAMRecord)20 GenomicSequence (com.github.lindenb.jvarkit.util.picard.GenomicSequence)16 SAMFileHeader (htsjdk.samtools.SAMFileHeader)16 ArrayList (java.util.ArrayList)16 IOException (java.io.IOException)15 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)14 SAMRecordIterator (htsjdk.samtools.SAMRecordIterator)13 SamReaderFactory (htsjdk.samtools.SamReaderFactory)12 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)11 CigarElement (htsjdk.samtools.CigarElement)11 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)11 List (java.util.List)11 FileNotFoundException (java.io.FileNotFoundException)10 BufferedReader (java.io.BufferedReader)9 Collectors (java.util.stream.Collectors)9 Cigar (htsjdk.samtools.Cigar)8 CigarOperator (htsjdk.samtools.CigarOperator)7