use of au.edu.wehi.idsv.sam.NmTagIterator in project gridss by PapenfussLab.
the class ComputeSamTags method compute.
public static void compute(Iterator<SAMRecord> rawit, SAMFileWriter writer, ReferenceLookup reference, Set<String> tags, boolean softenHardClips, boolean fixMates, boolean recalculateSupplementary, String threadprefix) throws IOException {
ProgressLogger progress = new ProgressLogger(log);
try (CloseableIterator<SAMRecord> aysncit = new AsyncBufferedIterator<SAMRecord>(rawit, threadprefix + "raw")) {
Iterator<SAMRecord> it = aysncit;
if (tags.contains(SAMTag.NM.name()) || tags.contains(SAMTag.SA.name())) {
it = new AsyncBufferedIterator<SAMRecord>(it, threadprefix + "nm");
it = new NmTagIterator(it, reference);
}
if (!Sets.intersection(tags, SAMRecordUtil.TEMPLATE_TAGS).isEmpty() || softenHardClips) {
it = new TemplateTagsIterator(it, softenHardClips, fixMates, recalculateSupplementary, tags);
it = new AsyncBufferedIterator<SAMRecord>(it, threadprefix + "tags");
}
while (it.hasNext()) {
SAMRecord r = it.next();
writer.addAlignment(r);
progress.record(r);
}
}
}
use of au.edu.wehi.idsv.sam.NmTagIterator in project gridss by PapenfussLab.
the class SplitReadRealigner method mergeSupplementaryAlignment.
private void mergeSupplementaryAlignment(File input, List<File> aligned, File output) throws IOException {
log.info("Merging split read alignments for ", output);
File suppMerged = FileSystemContext.getWorkingFileFor(output, "gridss.tmp.SplitReadAligner.sa.");
File tmpoutput = FileSystemContext.getWorkingFileFor(output);
tmpFiles.add(suppMerged);
tmpFiles.add(tmpoutput);
List<SamReader> suppReaders = new ArrayList<>();
List<PeekingIterator<SAMRecord>> suppIt = new ArrayList<>();
SAMFileHeader header;
try (SamReader reader = readerFactory.open(input)) {
header = reader.getFileHeader();
for (File sf : aligned) {
SamReader suppReader = readerFactory.open(sf);
suppReaders.add(suppReader);
suppIt.add(new AsyncBufferedIterator<>(new NmTagIterator(suppReader.iterator(), pc.getReference()), sf.getName()));
}
try (SAMFileWriter inputWriter = writerFactory.makeSAMOrBAMWriter(header, true, tmpoutput)) {
try (SAMFileWriter suppWriter = writerFactory.makeSAMOrBAMWriter(header, false, suppMerged)) {
try (AsyncBufferedIterator<SAMRecord> bufferedIt = new AsyncBufferedIterator<>(new NmTagIterator(reader.iterator(), pc.getReference()), input.getName())) {
mergeSupplementaryAlignment(bufferedIt, suppIt, inputWriter, suppWriter);
}
}
}
} finally {
for (Iterator<SAMRecord> it : suppIt) {
CloserUtil.close(it);
}
for (SamReader sr : suppReaders) {
sr.close();
}
}
if (header.getSortOrder() != null && header.getSortOrder() != SortOrder.unsorted) {
File suppMergedsorted = FileSystemContext.getWorkingFileFor(output, "gridss.tmp.SplitReadAligner.sorted.sa.");
tmpFiles.add(suppMergedsorted);
SAMFileUtil.sort(pc.getFileSystemContext(), suppMerged, suppMergedsorted, header.getSortOrder());
FileHelper.move(suppMergedsorted, suppMerged, true);
}
SAMFileUtil.merge(ImmutableList.of(tmpoutput, suppMerged), output);
}
Aggregations