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;
}
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);
}
}
}
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();
}
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());
}
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());
}
Aggregations