Search in sources :

Example 1 with SimpleBEDFeature

use of htsjdk.tribble.bed.SimpleBEDFeature in project gridss by PapenfussLab.

the class BamToBed method getSpanningDeletion.

public static List<SimpleBEDFeature> getSpanningDeletion(final SAMRecord r, final int minMapq, final int minIndelSize, final int maxMappedBases, final int minIndelComponentSize) {
    List<SimpleBEDFeature> list = new ArrayList<SimpleBEDFeature>();
    if (r.getMappingQuality() < minMapq)
        return list;
    List<CigarElement> ce = r.getCigar().getCigarElements();
    int offset = 0;
    for (int i = 0; i < ce.size(); i++) {
        CigarElement e = ce.get(i);
        if (e.getOperator() == CigarOperator.D) {
            if (maxMappedBases > 0) {
                throw new RuntimeException("Indel merging via MAX_INTERVENING_MAPPED_BASES not yet implemented.");
            }
            if (e.getLength() > minIndelSize) {
                list.add(new SimpleBEDFeature(r.getAlignmentStart() + offset, r.getAlignmentStart() + offset + e.getLength(), r.getReferenceName()));
            }
        }
        if (e.getOperator().consumesReferenceBases()) {
            offset += e.getLength();
        }
    }
    return list;
}
Also used : SimpleBEDFeature(htsjdk.tribble.bed.SimpleBEDFeature) ArrayList(java.util.ArrayList) CigarElement(htsjdk.samtools.CigarElement)

Example 2 with SimpleBEDFeature

use of htsjdk.tribble.bed.SimpleBEDFeature in project gridss by PapenfussLab.

the class BamToBed method extract.

public static void extract(File input, File splitReads, File spanningReads, final double minLengthPortion, final int minMapq, final int minIndelSize, final int maxMappedBases, final int minIndelComponentSize) throws IOException {
    SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT);
    SamReader reader = factory.open(input);
    BufferedWriter srwriter = null;
    if (splitReads != null) {
        srwriter = new BufferedWriter(new FileWriter(splitReads));
    }
    BufferedWriter spwriter = null;
    if (spanningReads != null) {
        spwriter = new BufferedWriter(new FileWriter(spanningReads));
    }
    SAMRecordIterator it = reader.iterator();
    while (it.hasNext()) {
        final SAMRecord r = it.next();
        if (r.isSecondaryOrSupplementary())
            continue;
        if (splitReads != null) {
            for (SimpleBEDFeature f : ChimericAlignment.getChimericAlignments(r).stream().map(ca -> getSplitReadDeletion(r, ca, minLengthPortion, minMapq, minIndelSize)).filter(f -> f != null).collect(Collectors.toList())) {
                writeBed(srwriter, f);
            }
        }
        if (spanningReads != null) {
            for (SimpleBEDFeature f : getSpanningDeletion(r, minMapq, minIndelSize, maxMappedBases, minIndelComponentSize)) {
                writeBed(spwriter, f);
            }
        }
    }
    CloserUtil.close(srwriter);
    CloserUtil.close(spwriter);
}
Also used : CommandLineProgramProperties(org.broadinstitute.barclay.argparser.CommandLineProgramProperties) BufferedWriter(java.io.BufferedWriter) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) Argument(org.broadinstitute.barclay.argparser.Argument) CigarElement(htsjdk.samtools.CigarElement) FileWriter(java.io.FileWriter) CigarOperator(htsjdk.samtools.CigarOperator) IOException(java.io.IOException) SamReader(htsjdk.samtools.SamReader) Collectors(java.util.stream.Collectors) ValidationStringency(htsjdk.samtools.ValidationStringency) File(java.io.File) SAMRecord(htsjdk.samtools.SAMRecord) StandardOptionDefinitions(picard.cmdline.StandardOptionDefinitions) ArrayList(java.util.ArrayList) SimpleBEDFeature(htsjdk.tribble.bed.SimpleBEDFeature) CommandLineProgram(picard.cmdline.CommandLineProgram) List(java.util.List) Writer(java.io.Writer) CigarUtil(au.edu.wehi.idsv.sam.CigarUtil) SamReaderFactory(htsjdk.samtools.SamReaderFactory) ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) CloserUtil(htsjdk.samtools.util.CloserUtil) SamReader(htsjdk.samtools.SamReader) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) SimpleBEDFeature(htsjdk.tribble.bed.SimpleBEDFeature) FileWriter(java.io.FileWriter) SAMRecord(htsjdk.samtools.SAMRecord) BufferedWriter(java.io.BufferedWriter)

Aggregations

CigarElement (htsjdk.samtools.CigarElement)2 SimpleBEDFeature (htsjdk.tribble.bed.SimpleBEDFeature)2 ArrayList (java.util.ArrayList)2 ChimericAlignment (au.edu.wehi.idsv.sam.ChimericAlignment)1 CigarUtil (au.edu.wehi.idsv.sam.CigarUtil)1 CigarOperator (htsjdk.samtools.CigarOperator)1 SAMRecord (htsjdk.samtools.SAMRecord)1 SAMRecordIterator (htsjdk.samtools.SAMRecordIterator)1 SamReader (htsjdk.samtools.SamReader)1 SamReaderFactory (htsjdk.samtools.SamReaderFactory)1 ValidationStringency (htsjdk.samtools.ValidationStringency)1 CloserUtil (htsjdk.samtools.util.CloserUtil)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Argument (org.broadinstitute.barclay.argparser.Argument)1