Search in sources :

Example 6 with CoverageFactory

use of com.github.lindenb.jvarkit.samtools.CoverageFactory in project jvarkit by lindenb.

the class BamXtremDepth method runLoop.

private void runLoop(final List<Path> bamPaths, final SamReaderFactory srf, final SAMSequenceRecord ssr, final SAMSequenceDictionary refDict, BitSet lowList, BitSet highList) throws IOException {
    final CoverageFactory coverageFactory = new CoverageFactory().setMappingQuality(mapq);
    for (final Path bamPath : bamPaths) {
        try (SamReader samReader = srf.open(bamPath)) {
            // check indexed
            if (!samReader.hasIndex()) {
                throw new JvarkitException.BamHasIndex(bamPath.toString());
            }
            final SAMFileHeader header = samReader.getFileHeader();
            // check dictionary
            final SAMSequenceDictionary dict = SequenceDictionaryUtils.extractRequired(header);
            SequenceUtil.assertSequenceDictionariesEqual(dict, refDict);
            // get the coverage in the low and high region.
            final CoverageFactory.SimpleCoverage coverage;
            if (this.alternative_algorithm) {
                LOG.info(ssr.getContig() + " " + bamPath);
                coverage = coverageFactory.getSimpleCoverage(samReader, ssr, null);
            } else {
                final List<Locatable> regions = bitSetToLocatables(ssr, lowList);
                regions.addAll(bitSetToLocatables(ssr, highList));
                if (regions.isEmpty())
                    break;
                LOG.info(ssr.getContig() + " " + bamPath + " n-intervals:" + regions.size() + " size:" + regions.stream().mapToInt(R -> R.getLengthOnReference()).sum());
                coverage = coverageFactory.getSimpleCoverage(samReader, regions, null);
            }
            // compute the new low and hight coverage
            reduce(lowList, coverage, I -> I <= this.min_coverage);
            reduce(highList, coverage, I -> I >= this.max_coverage);
        }
        System.gc();
    }
}
Also used : Path(java.nio.file.Path) SequenceUtil(htsjdk.samtools.util.SequenceUtil) Program(com.github.lindenb.jvarkit.util.jcommander.Program) Parameter(com.beust.jcommander.Parameter) IntPredicate(java.util.function.IntPredicate) SAMFileHeader(htsjdk.samtools.SAMFileHeader) ValidationStringency(htsjdk.samtools.ValidationStringency) SAMTextHeaderCodec(htsjdk.samtools.SAMTextHeaderCodec) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ContigDictComparator(com.github.lindenb.jvarkit.util.samtools.ContigDictComparator) Interval(htsjdk.samtools.util.Interval) CoverageFactory(com.github.lindenb.jvarkit.samtools.CoverageFactory) IOUtils(com.github.lindenb.jvarkit.io.IOUtils) Launcher(com.github.lindenb.jvarkit.util.jcommander.Launcher) Path(java.nio.file.Path) PrintWriter(java.io.PrintWriter) SimpleInterval(com.github.lindenb.jvarkit.samtools.util.SimpleInterval) SequenceDictionaryUtils(com.github.lindenb.jvarkit.util.bio.SequenceDictionaryUtils) Locatable(htsjdk.samtools.util.Locatable) Logger(com.github.lindenb.jvarkit.util.log.Logger) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Set(java.util.Set) IOException(java.io.IOException) JVarkitVersion(com.github.lindenb.jvarkit.util.JVarkitVersion) SamReader(htsjdk.samtools.SamReader) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) List(java.util.List) FileExtensions(htsjdk.samtools.util.FileExtensions) BitSet(java.util.BitSet) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SamReader(htsjdk.samtools.SamReader) CoverageFactory(com.github.lindenb.jvarkit.samtools.CoverageFactory) SAMFileHeader(htsjdk.samtools.SAMFileHeader) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Locatable(htsjdk.samtools.util.Locatable)

Aggregations

CoverageFactory (com.github.lindenb.jvarkit.samtools.CoverageFactory)6 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)6 ArrayList (java.util.ArrayList)6 Parameter (com.beust.jcommander.Parameter)5 IOUtils (com.github.lindenb.jvarkit.io.IOUtils)5 SimpleInterval (com.github.lindenb.jvarkit.samtools.util.SimpleInterval)5 SequenceDictionaryUtils (com.github.lindenb.jvarkit.util.bio.SequenceDictionaryUtils)5 ContigNameConverter (com.github.lindenb.jvarkit.util.bio.fasta.ContigNameConverter)5 Launcher (com.github.lindenb.jvarkit.util.jcommander.Launcher)5 Program (com.github.lindenb.jvarkit.util.jcommander.Program)5 Logger (com.github.lindenb.jvarkit.util.log.Logger)5 SAMFileHeader (htsjdk.samtools.SAMFileHeader)5 SamReader (htsjdk.samtools.SamReader)5 Locatable (htsjdk.samtools.util.Locatable)5 SequenceUtil (htsjdk.samtools.util.SequenceUtil)5 Path (java.nio.file.Path)5 List (java.util.List)5 StringUtils (com.github.lindenb.jvarkit.lang.StringUtils)4 NoSplitter (com.github.lindenb.jvarkit.util.jcommander.NoSplitter)4 IOException (java.io.IOException)4