use of htsjdk.samtools.fastq.FastqRecord in project gridss by PapenfussLab.
the class StubFastqAligner method align.
public StubFastqAligner align(SAMRecord r, BreakendDirection direction, int referenceIndex, int pos, boolean isNegativeStrand, String cigar) {
List<FastqRecord> srs = SplitReadIdentificationHelper.getSplitReadRealignments(r, false, eidgen);
FastqRecord fqr = srs.get(0);
if (srs.size() == 2) {
if (direction == BreakendDirection.Forward ^ r.getReadNegativeStrandFlag()) {
fqr = srs.get(1);
}
}
map.put(fqr.getReadName(), new ChimericAlignment(r.getHeader().getSequenceDictionary().getSequence(referenceIndex).getSequenceName(), pos, isNegativeStrand, TextCigarCodec.decode(cigar), 40, 0));
nameLookup.put(fqr.getReadName(), r);
return this;
}
use of htsjdk.samtools.fastq.FastqRecord in project gridss by PapenfussLab.
the class StubFastqAligner method align.
@Override
public void align(File fastq, File output, File reference, int threads) throws IOException {
SAMFileHeader header = context.getBasicSamHeader();
try (FastqReader reader = new FastqReader(fastq)) {
try (SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, true, output)) {
for (FastqRecord fqr : reader) {
SAMRecord source = nameLookup.get(fqr.getReadName());
SAMRecord r = new SAMRecord(header);
r.setReadName(fqr.getReadName());
r.setReadBases(fqr.getReadString().getBytes());
r.setBaseQualities(SAMUtils.fastqToPhred(fqr.getBaseQualityString()));
if (source == null) {
r.setReadUnmappedFlag(true);
} else {
ChimericAlignment aln = map.get(fqr.getReadName());
r.setReferenceName(aln.rname);
r.setAlignmentStart(aln.pos);
r.setCigar(aln.cigar);
r.setMappingQuality(aln.mapq);
r.setAttribute("NM", aln.nm);
if (aln.isNegativeStrand) {
SequenceUtil.reverseComplement(r.getReadBases());
ArrayUtils.reverse(r.getBaseQualities());
}
}
writer.addAlignment(r);
}
}
}
}
use of htsjdk.samtools.fastq.FastqRecord in project gridss by PapenfussLab.
the class SplitReadRealigner method processInputRecord.
private void processInputRecord(StreamingAligner aligner, SplitReadFastqExtractor rootExtractor, Map<String, SplitReadRealignmentInfo> realignments, SAMFileWriter writer, SAMRecord r) throws IOException {
List<FastqRecord> softclipRealignments = rootExtractor.extract(r);
if (softclipRealignments.size() == 0) {
// nothing to do - just output the record
writer.addAlignment(r);
} else {
// perform split read realignment
SplitReadRealignmentInfo info = new SplitReadRealignmentInfo(r);
realignments.put(info.lookupKey, info);
for (FastqRecord fq : softclipRealignments) {
aligner.asyncAlign(fq);
info.outstandingRealignments++;
}
}
}
use of htsjdk.samtools.fastq.FastqRecord in project gridss by PapenfussLab.
the class SmithWatermanFastqAligner method align.
@Override
public void align(File fastq, File output, File reference, int threads) throws IOException {
try (ReferenceSequenceFile ref = new IndexedFastaSequenceFile(reference)) {
SAMFileHeader header = new SAMFileHeader();
header.setSequenceDictionary(ref.getSequenceDictionary());
byte[] bases = ref.getSequence(ref.getSequenceDictionary().getSequence(referenceIndex).getSequenceName()).getBases();
try (FastqReader reader = new FastqReader(fastq)) {
try (SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, true, output)) {
for (FastqRecord fqr : reader) {
Alignment aln = aligner.align_smith_waterman(fqr.getReadString().getBytes(), bases);
SAMRecord r = new SAMRecord(header);
r.setReadName(fqr.getReadName());
r.setReferenceIndex(referenceIndex);
r.setAlignmentStart(aln.getStartPosition() + 1);
r.setCigarString(aln.getCigar());
r.setReadBases(fqr.getReadString().getBytes());
r.setBaseQualities(SAMUtils.fastqToPhred(fqr.getBaseQualityString()));
writer.addAlignment(r);
}
}
}
}
}
use of htsjdk.samtools.fastq.FastqRecord in project jvarkit by lindenb.
the class FourLinesFastqReader method readNextRecord.
@Override
protected FastqRecord readNextRecord() {
try {
// Read sequence header
this.seqHeader = this.readLine();
if (this.seqHeader == null)
return null;
++nLines;
if (StringUtil.isBlank(this.seqHeader)) {
throw new RuntimeException(error("Missing sequence header"));
}
if (!this.seqHeader.startsWith(FastqConstants.SEQUENCE_HEADER)) {
throw new RuntimeException(error("Sequence header must start with " + FastqConstants.SEQUENCE_HEADER));
}
// Read sequence line
final String seqLine = this.readLine();
++nLines;
checkLine(seqLine, "sequence line");
// Read quality header
final String qualHeader = this.readLine();
++nLines;
checkLine(qualHeader, "quality header");
if (!qualHeader.startsWith(FastqConstants.QUALITY_HEADER)) {
throw new RuntimeException(error("Quality header must start with " + FastqConstants.QUALITY_HEADER + ": " + qualHeader));
}
// Read quality line
final String qualLine = this.readLine();
++nLines;
checkLine(qualLine, "quality line");
// Check sequence and quality lines are same length
if (seqLine.length() != qualLine.length()) {
throw new RuntimeException(error("Sequence and quality line must be the same length"));
}
final FastqRecord frec = new FastqRecord(seqHeader.substring(1, seqHeader.length()), seqLine, qualHeader.substring(1, qualHeader.length()), qualLine);
this.seqHeader = null;
return frec;
} catch (IOException e) {
throw new RuntimeException(String.format("Error reading fastq '%s'", getAbsolutePath()), e);
}
}
Aggregations