Search in sources :

Example 26 with SAMReadGroupRecord

use of htsjdk.samtools.SAMReadGroupRecord in project jvarkit by lindenb.

the class SoftClipAnnotator method initialize.

public void initialize() {
    final Set<VCFHeaderLine> hInfo = new HashSet<>();
    final List<String> rodName = Arrays.asList(variantCollection.variants.getName());
    final Set<String> samples = SampleUtils.getUniqueSamplesFromRods(getToolkit(), rodName);
    for (final String sample : samples) {
        this.sample2bam.put(sample, new ArrayList<>());
    }
    for (final VCFHeaderLine line : GATKVCFUtils.getHeaderFields(getToolkit(), rodName)) {
        if (isUniqueHeaderLine(line, hInfo))
            hInfo.add(line);
    }
    VCFHeader vcfHeader = new VCFHeader(hInfo, samples);
    VCFHeader header2 = new VCFHeader(vcfHeader);
    header2.addMetaDataLine(this.numClipInGenotypeFormatHeaderLine);
    header2.addMetaDataLine(this.filterHaveClipInVariant);
    vcfWriter.writeHeader(header2);
    final SamReaderFactory srf = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT);
    for (final File samFilename : IOUtil.unrollFiles(this.samFilenames, ".bam")) {
        logger.info("opening " + samFilename);
        final SamReader r = srf.open(samFilename);
        final Set<String> sampleset = new HashSet<>();
        for (final SAMReadGroupRecord g : r.getFileHeader().getReadGroups()) {
            if (g.getSample() == null || !this.sample2bam.containsKey(g.getSample()))
                continue;
            sampleset.add(g.getSample());
        }
        if (sampleset.isEmpty()) {
            logger.info("no VCF sample in " + samFilename);
            CloserUtil.close(r);
            continue;
        }
        this.samReaders.add(r);
        for (final String sample : sampleset) {
            if (!this.sample2bam.containsKey(sample))
                continue;
            this.sample2bam.get(sample).add(r);
        }
    }
}
Also used : SamReader(htsjdk.samtools.SamReader) VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) HashSet(java.util.HashSet)

Example 27 with SAMReadGroupRecord

use of htsjdk.samtools.SAMReadGroupRecord in project jvarkit by lindenb.

the class MiniCaller method doWork.

@Override
public int doWork(final List<String> args) {
    ConcatSam.ConcatSamIterator iter = null;
    try {
        if (this.fastaFile == null) {
            LOG.error("no REF");
            return -1;
        }
        /* load faid */
        final ReferenceGenomeFactory referenceGenomeFactory = new ReferenceGenomeFactory();
        this.referenceGenome = referenceGenomeFactory.openFastaFile(this.fastaFile);
        this.dictionary = this.referenceGenome.getDictionary();
        if (this.dictionary == null) {
            LOG.error(JvarkitException.FastaDictionaryMissing.getMessage(this.fastaFile.getPath()));
        }
        /* create sam record iterator */
        iter = new ConcatSam.Factory().addInterval(this.rgnStr).setEnableUnrollList(true).open(args);
        final SAMFileHeader samFileheader = iter.getFileHeader();
        final SAMSequenceDictionary dict = samFileheader.getSequenceDictionary();
        if (dict == null) {
            LOG.error(JvarkitException.BamDictionaryMissing.getMessage(String.join(", ", args)));
            return -1;
        }
        if (!SequenceUtil.areSequenceDictionariesEqual(dict, this.dictionary)) {
            LOG.error(JvarkitException.DictionariesAreNotTheSame.getMessage(dict, this.dictionary));
            return -1;
        }
        final List<SAMReadGroupRecord> groups = samFileheader.getReadGroups();
        if (groups == null || groups.isEmpty()) {
            LOG.error("No group defined in input");
            return -1;
        }
        final Set<String> sampleSet = groups.stream().map(srgr -> this.samRecordPartition.apply(srgr, samRecordPartition.name())).collect(Collectors.toSet());
        /* create VCF metadata */
        final Set<VCFHeaderLine> metaData = new HashSet<VCFHeaderLine>();
        metaData.add(VCFStandardHeaderLines.getFormatLine(VCFConstants.GENOTYPE_KEY));
        metaData.add(VCFStandardHeaderLines.getFormatLine(VCFConstants.DEPTH_KEY));
        metaData.add(VCFStandardHeaderLines.getInfoLine(VCFConstants.DEPTH_KEY));
        metaData.add(VCFStandardHeaderLines.getInfoLine(VCFConstants.ALLELE_COUNT_KEY));
        metaData.add(VCFStandardHeaderLines.getInfoLine(VCFConstants.ALLELE_NUMBER_KEY));
        metaData.add(VCFStandardHeaderLines.getInfoLine(VCFConstants.ALLELE_FREQUENCY_KEY));
        metaData.add(new VCFFormatHeaderLine("DPG", // one value of each genotype
        VCFHeaderLineCount.G, VCFHeaderLineType.Integer, "Depth for each allele"));
        metaData.add(new VCFFormatHeaderLine("DP4", 4, VCFHeaderLineType.Integer, "Depth ReforAlt|Strand : RF,RR,AF,AR"));
        metaData.add(new VCFInfoHeaderLine("INDEL", 1, VCFHeaderLineType.Flag, "Variant is indel"));
        // addMetaData(metaData);
        final VCFHeader vcfHeader = new VCFHeader(metaData, sampleSet);
        vcfHeader.setSequenceDictionary(this.dictionary);
        /* create variant context */
        this.variantContextWriter = super.openVariantContextWriter(outputFile);
        this.variantContextWriter.writeHeader(vcfHeader);
        ReferenceContig genomicSeq = null;
        SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(this.dictionary);
        for (; ; ) {
            SAMRecord rec = null;
            if (iter.hasNext()) {
                rec = progress.watch(iter.next());
                if (rec.getReadUnmappedFlag())
                    continue;
                if (this.readFilter.filterOut(rec))
                    continue;
                /* flush buffer if needed */
                while (!this.buffer.isEmpty() && (this.buffer.get(0).tid < rec.getReferenceIndex() || (this.buffer.get(0).tid == rec.getReferenceIndex() && (this.buffer.get(0).getEnd()) < rec.getAlignmentStart()))) {
                    this.buffer.remove(0).print();
                }
                /* get genomic sequence at this position */
                if (genomicSeq == null || !genomicSeq.getContig().equals(rec.getContig())) {
                    genomicSeq = this.referenceGenome.getContig(rec.getContig());
                }
                final Cigar cigar = rec.getCigar();
                if (cigar == null)
                    continue;
                int readPos = 0;
                // 0 based-reference
                int refPos0 = rec.getAlignmentStart() - 1;
                final byte[] bases = rec.getReadBases();
                final byte[] quals = rec.getBaseQualities();
                final String sampleName = this.samRecordPartition.getPartion(rec, samRecordPartition.name());
                for (final CigarElement ce : cigar.getCigarElements()) {
                    final CigarOperator op = ce.getOperator();
                    switch(op) {
                        case P:
                            break;
                        case H:
                            break;
                        case S:
                            readPos += ce.getLength();
                            break;
                        // go
                        case N:
                        case D:
                            {
                                if (// we need base before deletion
                                refPos0 > 0) {
                                    char refBase = genomicSeq.charAt(refPos0 - 1);
                                    /* we use base before deletion */
                                    final StringBuilder sb = new StringBuilder(ce.getLength());
                                    sb.append(refBase);
                                    for (int i = 0; i < ce.getLength(); ++i) {
                                        sb.append(genomicSeq.charAt(refPos0 + i));
                                    }
                                    findContext(rec.getReferenceIndex(), // we use base *before deletion */
                                    refPos0 - 1, Allele.create(sb.toString(), true)).getSample(sampleName).getAllele(Allele.create(String.valueOf(refBase), false)).incr(rec.getReadNegativeStrandFlag());
                                }
                                refPos0 += ce.getLength();
                                break;
                            }
                        case I:
                            {
                                if (refPos0 > 0) {
                                    // float qual=0;
                                    char refBase = Character.toUpperCase(genomicSeq.charAt(refPos0 - 1));
                                    final StringBuilder sb = new StringBuilder(1 + ce.getLength());
                                    sb.append(refBase);
                                    for (int i = 0; i < ce.getLength(); ++i) {
                                        sb.append((char) bases[readPos + i]);
                                    // qual+=(readPos + i < quals.length?quals[ readPos + i]:0);
                                    }
                                    findContext(rec.getReferenceIndex(), // we use base *before deletion */
                                    refPos0 - 1, Allele.create(String.valueOf(refBase), true)).getSample(sampleName).getAllele(Allele.create(sb.toString().toUpperCase(), false)).incr(rec.getReadNegativeStrandFlag());
                                }
                                readPos += ce.getLength();
                                break;
                            }
                        case EQ:
                        case M:
                        case X:
                            {
                                for (int i = 0; i < ce.getLength(); ++i) {
                                    findContext(rec.getReferenceIndex(), refPos0 + i, Allele.create(String.valueOf(genomicSeq.charAt(refPos0 + i)), true)).getSample(sampleName).getAllele(Allele.create(String.valueOf((char) bases[readPos + i]), false)).incr(rec.getReadNegativeStrandFlag());
                                }
                                readPos += ce.getLength();
                                refPos0 += ce.getLength();
                                break;
                            }
                        default:
                            throw new IllegalStateException("Case statement didn't deal with cigar op: " + op);
                    }
                }
            } else {
                break;
            }
        }
        while (!buffer.isEmpty()) buffer.remove(0).print();
        progress.finish();
        iter.close();
        iter = null;
        this.variantContextWriter.close();
        this.variantContextWriter = null;
        return RETURN_OK;
    } catch (Exception e) {
        LOG.error(e);
        return -1;
    } finally {
        CloserUtil.close(iter);
        CloserUtil.close(this.referenceGenome);
        CloserUtil.close(this.variantContextWriter);
    }
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) Arrays(java.util.Arrays) Program(com.github.lindenb.jvarkit.util.jcommander.Program) VCFStandardHeaderLines(htsjdk.variant.vcf.VCFStandardHeaderLines) VCFHeader(htsjdk.variant.vcf.VCFHeader) CigarElement(htsjdk.samtools.CigarElement) SAMSequenceDictionaryProgress(com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress) CigarOperator(htsjdk.samtools.CigarOperator) SAMRecordPartition(com.github.lindenb.jvarkit.util.samtools.SAMRecordPartition) IntervalParser(com.github.lindenb.jvarkit.util.bio.IntervalParser) SAMFileHeader(htsjdk.samtools.SAMFileHeader) ReferenceGenomeFactory(com.github.lindenb.jvarkit.util.bio.fasta.ReferenceGenomeFactory) Map(java.util.Map) CloserUtil(htsjdk.samtools.util.CloserUtil) GenotypeBuilder(htsjdk.variant.variantcontext.GenotypeBuilder) Logger(com.github.lindenb.jvarkit.util.log.Logger) Set(java.util.Set) Collectors(java.util.stream.Collectors) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) SAMRecord(htsjdk.samtools.SAMRecord) List(java.util.List) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VCFInfoHeaderLine(htsjdk.variant.vcf.VCFInfoHeaderLine) VariantContext(htsjdk.variant.variantcontext.VariantContext) VCFHeaderLineCount(htsjdk.variant.vcf.VCFHeaderLineCount) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) Genotype(htsjdk.variant.variantcontext.Genotype) VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) Cigar(htsjdk.samtools.Cigar) SequenceUtil(htsjdk.samtools.util.SequenceUtil) Parameter(com.beust.jcommander.Parameter) HashMap(java.util.HashMap) Term(com.github.lindenb.semontology.Term) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Launcher(com.github.lindenb.jvarkit.util.jcommander.Launcher) VCFConstants(htsjdk.variant.vcf.VCFConstants) Counter(com.github.lindenb.jvarkit.util.Counter) Locatable(htsjdk.samtools.util.Locatable) VCFHeaderLineType(htsjdk.variant.vcf.VCFHeaderLineType) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) ReferenceContig(com.github.lindenb.jvarkit.util.bio.fasta.ReferenceContig) File(java.io.File) SamRecordFilter(htsjdk.samtools.filter.SamRecordFilter) SamRecordJEXLFilter(com.github.lindenb.jvarkit.util.samtools.SamRecordJEXLFilter) ConcatSam(com.github.lindenb.jvarkit.tools.misc.ConcatSam) VCFFormatHeaderLine(htsjdk.variant.vcf.VCFFormatHeaderLine) ReferenceGenome(com.github.lindenb.jvarkit.util.bio.fasta.ReferenceGenome) ReferenceContig(com.github.lindenb.jvarkit.util.bio.fasta.ReferenceContig) VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) ReferenceGenomeFactory(com.github.lindenb.jvarkit.util.bio.fasta.ReferenceGenomeFactory) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) VCFHeader(htsjdk.variant.vcf.VCFHeader) HashSet(java.util.HashSet) VCFFormatHeaderLine(htsjdk.variant.vcf.VCFFormatHeaderLine) SAMSequenceDictionaryProgress(com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress) ReferenceGenomeFactory(com.github.lindenb.jvarkit.util.bio.fasta.ReferenceGenomeFactory) CigarOperator(htsjdk.samtools.CigarOperator) CigarElement(htsjdk.samtools.CigarElement) VCFInfoHeaderLine(htsjdk.variant.vcf.VCFInfoHeaderLine) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) Cigar(htsjdk.samtools.Cigar) SAMRecord(htsjdk.samtools.SAMRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) ConcatSam(com.github.lindenb.jvarkit.tools.misc.ConcatSam)

Example 28 with SAMReadGroupRecord

use of htsjdk.samtools.SAMReadGroupRecord in project jvarkit by lindenb.

the class BlastToSam method doWork.

@Override
public int doWork(List<String> args) {
    if (this.faidx == null || !this.faidx.exists() || !this.faidx.isFile()) {
        LOG.error("Option -R was not defined or dictionary missing");
        return -1;
    }
    final boolean interleaved_input = this.EXPECTED_SIZE > 0;
    final int maxRecordsInRam = 5000;
    SAMFileWriter sfw = null;
    XMLEventReader rx = null;
    final SAMFileWriterFactory sfwf = new SAMFileWriterFactory();
    sfwf.setCreateIndex(false);
    sfwf.setMaxRecordsInRam(maxRecordsInRam);
    sfwf.setCreateMd5File(false);
    sfwf.setUseAsyncIo(false);
    final SAMFileHeader header = new SAMFileHeader();
    try {
        LOG.info("opening " + faidx);
        this.dictionary = SAMSequenceDictionaryExtractor.extractDictionary(faidx);
        header.setSortOrder(SortOrder.unsorted);
        header.setSequenceDictionary(this.dictionary);
        final JAXBContext jc = JAXBContext.newInstance("gov.nih.nlm.ncbi.blast");
        this.unmarshaller = jc.createUnmarshaller();
        final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
        xmlInputFactory.setXMLResolver(new XMLResolver() {

            @Override
            public Object resolveEntity(String arg0, String arg1, String arg2, String arg3) throws XMLStreamException {
                LOG.info("resolveEntity:" + arg0 + "/" + arg1 + "/" + arg2);
                return null;
            }
        });
        final String inputName = oneFileOrNull(args);
        if (inputName == null) {
            LOG.info("Reading from stdin");
            rx = xmlInputFactory.createXMLEventReader(stdin());
        } else if (args.size() == 1) {
            LOG.info("Reading from " + inputName);
            rx = xmlInputFactory.createXMLEventReader(IOUtils.openURIForBufferedReading(inputName));
        } else {
            LOG.error("Illegal number of args");
            return -1;
        }
        final SAMProgramRecord prg2 = header.createProgramRecord();
        fillHeader(rx, prg2);
        final SAMProgramRecord prg1 = header.createProgramRecord();
        prg1.setCommandLine(getProgramCommandLine());
        prg1.setProgramVersion(getVersion());
        prg1.setProgramName(getProgramName());
        prg1.setPreviousProgramGroupId(prg2.getId());
        final SAMReadGroupRecord rg1 = new SAMReadGroupRecord("g1");
        rg1.setLibrary("blast");
        rg1.setSample("blast");
        rg1.setDescription("blast");
        header.addReadGroup(rg1);
        sfw = this.writingBamArgs.openSAMFileWriter(outputFile, header, true);
        if (interleaved_input) {
            run_paired(sfw, rx, header);
        } else {
            run_single(sfw, rx, header);
        }
        return RETURN_OK;
    } catch (final Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(sfw);
        CloserUtil.close(rx);
    }
}
Also used : SAMFileWriter(htsjdk.samtools.SAMFileWriter) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) SAMFileWriterFactory(htsjdk.samtools.SAMFileWriterFactory) JAXBContext(javax.xml.bind.JAXBContext) SAMProgramRecord(htsjdk.samtools.SAMProgramRecord) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventReader(javax.xml.stream.XMLEventReader) XMLResolver(javax.xml.stream.XMLResolver) SAMFileHeader(htsjdk.samtools.SAMFileHeader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 29 with SAMReadGroupRecord

use of htsjdk.samtools.SAMReadGroupRecord in project jvarkit by lindenb.

the class BamStage method createReadGroupPane.

private Tab createReadGroupPane(final SAMFileHeader header) {
    final TableView<SAMReadGroupRecord> table = new TableView<>(header == null ? FXCollections.observableArrayList() : FXCollections.observableArrayList(header.getReadGroups()));
    table.getColumns().add(makeColumn("ID", G -> G.getId()));
    table.getColumns().add(makeColumn("Sample", G -> G.getSample()));
    table.getColumns().add(makeColumn("Center", G -> G.getSequencingCenter()));
    table.getColumns().add(makeColumn("Platform", G -> G.getPlatform()));
    table.getColumns().add(makeColumn("PlatformModel", G -> G.getPlatformModel()));
    table.getColumns().add(makeColumn("PlatformUnit", G -> G.getPlatformUnit()));
    table.getColumns().add(makeColumn("MedianInsertSize", G -> G.getPredictedMedianInsertSize()));
    table.getColumns().add(makeColumn("Desc", G -> G.getDescription()));
    table.getColumns().add(makeColumn("PU", G -> G.getPlatformUnit()));
    table.getColumns().add(makeColumn("Lib", G -> G.getLibrary()));
    table.getColumns().add(makeColumn("Run-Date", G -> G.getRunDate()));
    final Tab tab = new Tab("ReadGroups", table);
    tab.setClosable(false);
    table.setPlaceholder(new Label("No BAM read-greoup."));
    return tab;
}
Also used : Arrays(java.util.Arrays) VCFHeader(htsjdk.variant.vcf.VCFHeader) CigarOperator(htsjdk.samtools.CigarOperator) ChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.ChartFactory) VariantContextChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.VariantContextChartFactory) ScrollPane(javafx.scene.control.ScrollPane) TabPane(javafx.scene.control.TabPane) Map(java.util.Map) Hershey(com.github.lindenb.jvarkit.util.Hershey) CigarOpPerPositionChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.CigarOpPerPositionChartFactory) ScriptException(javax.script.ScriptException) CloserUtil(htsjdk.samtools.util.CloserUtil) Rectangle2D(javafx.geometry.Rectangle2D) SplitPane(javafx.scene.control.SplitPane) SAMTagUtil(htsjdk.samtools.SAMTagUtil) GraphicsContext(javafx.scene.canvas.GraphicsContext) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) Event(javafx.event.Event) Set(java.util.Set) SAMFileWriter(htsjdk.samtools.SAMFileWriter) Screen(javafx.stage.Screen) SAMTagAndValue(htsjdk.samtools.SAMRecord.SAMTagAndValue) FastqRecord(htsjdk.samtools.fastq.FastqRecord) Platform(javafx.application.Platform) Separator(javafx.scene.control.Separator) Stream(java.util.stream.Stream) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) FlowPane(javafx.scene.layout.FlowPane) SAMFlag(htsjdk.samtools.SAMFlag) BorderPane(javafx.scene.layout.BorderPane) SamFlagsChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.SamFlagsChartFactory) CloseableIterator(htsjdk.samtools.util.CloseableIterator) FXCollections(javafx.collections.FXCollections) LogCloseableIterator(com.github.lindenb.jvarkit.tools.vcfviewgui.NgsStage.LogCloseableIterator) TextFlow(javafx.scene.text.TextFlow) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Color(javafx.scene.paint.Color) SAMFileWriterFactory(htsjdk.samtools.SAMFileWriterFactory) StringWriter(java.io.StringWriter) CheckBox(javafx.scene.control.CheckBox) IOException(java.io.IOException) File(java.io.File) Menu(javafx.scene.control.Menu) FileChooser(javafx.stage.FileChooser) SamInputResource(htsjdk.samtools.SamInputResource) TreeMap(java.util.TreeMap) Tab(javafx.scene.control.Tab) CompiledScript(javax.script.CompiledScript) ObservableValue(javafx.beans.value.ObservableValue) EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) CigarElement(htsjdk.samtools.CigarElement) CheckMenuItem(javafx.scene.control.CheckMenuItem) OverrunStyle(javafx.scene.control.OverrunStyle) VBox(javafx.scene.layout.VBox) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BasesPerPositionChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.BasesPerPositionChartFactory) ComboBox(javafx.scene.control.ComboBox) AlertType(javafx.scene.control.Alert.AlertType) ContextMenu(javafx.scene.control.ContextMenu) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) ReadLengthChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.ReadLengthChartFactory) Orientation(javafx.geometry.Orientation) Alert(javafx.scene.control.Alert) MenuItem(javafx.scene.control.MenuItem) Predicate(java.util.function.Predicate) Logger(com.github.lindenb.jvarkit.util.log.Logger) Font(javafx.scene.text.Font) Chart(javafx.scene.chart.Chart) Collectors(java.util.stream.Collectors) SAMRecord(htsjdk.samtools.SAMRecord) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Text(javafx.scene.text.Text) SimpleBindings(javax.script.SimpleBindings) QualityPerPositionChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.QualityPerPositionChartFactory) List(java.util.List) SAMProgramRecord(htsjdk.samtools.SAMProgramRecord) Optional(java.util.Optional) VariantContext(htsjdk.variant.variantcontext.VariantContext) Pattern(java.util.regex.Pattern) SamReaderFactory(htsjdk.samtools.SamReaderFactory) FastqReader(htsjdk.samtools.fastq.FastqReader) ReadQualityChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.ReadQualityChartFactory) Cigar(htsjdk.samtools.Cigar) Scene(javafx.scene.Scene) SequenceUtil(htsjdk.samtools.util.SequenceUtil) SAMUtils(htsjdk.samtools.SAMUtils) TextArea(javafx.scene.control.TextArea) ButtonType(javafx.scene.control.ButtonType) HashMap(java.util.HashMap) GCPercentChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.GCPercentChartFactory) MapqChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.MapqChartFactory) Function(java.util.function.Function) ValidationStringency(htsjdk.samtools.ValidationStringency) SAMTextHeaderCodec(htsjdk.samtools.SAMTextHeaderCodec) TableColumn(javafx.scene.control.TableColumn) HashSet(java.util.HashSet) Interval(htsjdk.samtools.util.Interval) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) Locatable(htsjdk.samtools.util.Locatable) Label(javafx.scene.control.Label) MenuBar(javafx.scene.control.MenuBar) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) ReadChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.ReadChartFactory) SamReader(htsjdk.samtools.SamReader) ScrollEvent(javafx.scene.input.ScrollEvent) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) ChangeListener(javafx.beans.value.ChangeListener) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) Collections(java.util.Collections) ScrollBar(javafx.scene.control.ScrollBar) Tab(javafx.scene.control.Tab) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) Label(javafx.scene.control.Label) TableView(javafx.scene.control.TableView)

Example 30 with SAMReadGroupRecord

use of htsjdk.samtools.SAMReadGroupRecord in project jvarkit by lindenb.

the class SamScanSplitReads method analyseSamRecord.

private void analyseSamRecord(final SAMRecord rec) {
    if (rec.getReadUnmappedFlag())
        return;
    if (rec.getReadFailsVendorQualityCheckFlag())
        return;
    if (rec.isSecondaryOrSupplementary())
        return;
    if (rec.getDuplicateReadFlag())
        return;
    final List<SAMRecord> others = SAMUtils.getOtherCanonicalAlignments(rec);
    if (others.isEmpty())
        return;
    String sample = this.defaultSampleName;
    final SAMReadGroupRecord g = rec.getReadGroup();
    if (g != null) {
        final String sa = g.getSample();
        if (sa != null)
            sample = sa;
    }
    IntervalTreeMap<Set<Arc>> database = this.sample2database.get(sample);
    if (database == null) {
        database = new IntervalTreeMap<Set<Arc>>();
        this.sample2database.put(sample, database);
    }
    for (final SAMRecord other : others) {
        analyseSamPair(database, rec, other);
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) SAMRecord(htsjdk.samtools.SAMRecord) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord)

Aggregations

SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)81 SAMFileHeader (htsjdk.samtools.SAMFileHeader)48 SAMRecord (htsjdk.samtools.SAMRecord)33 Test (org.testng.annotations.Test)31 SamReader (htsjdk.samtools.SamReader)29 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)26 File (java.io.File)23 ArrayList (java.util.ArrayList)22 SAMRecordIterator (htsjdk.samtools.SAMRecordIterator)20 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)20 HashMap (java.util.HashMap)18 CigarElement (htsjdk.samtools.CigarElement)17 Cigar (htsjdk.samtools.Cigar)16 HashSet (java.util.HashSet)16 SAMFileWriter (htsjdk.samtools.SAMFileWriter)15 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)15 CigarOperator (htsjdk.samtools.CigarOperator)14 IOException (java.io.IOException)14 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)13 List (java.util.List)12