Search in sources :

Example 1 with IntervalFilter

use of htsjdk.samtools.filter.IntervalFilter in project jvarkit by lindenb.

the class MultiBamLauncher method openSamIterator.

/**
 * create input SAMRecord iterator for one sample
 */
protected CloseableIterator<SAMRecord> openSamIterator(final SamReader sr) {
    if (this.regionFiles != null) {
        this.regionFiles.dictionary(SequenceDictionaryUtils.extractRequired(sr.getFileHeader()));
        if (!sr.hasIndex()) {
            final List<Interval> L = this.regionFiles.stream().map(x -> new Interval(x)).collect(Collectors.toList());
            final SAMRecordIterator st0 = sr.iterator();
            return new FilteringSamIterator(st0, new IntervalFilter(L, sr.getFileHeader()));
        } else {
            final QueryInterval[] optimized = this.regionFiles.optimizedQueryIntervals();
            return sr.query(optimized, false);
        }
    }
    return sr.iterator();
}
Also used : CloseableIterator(htsjdk.samtools.util.CloseableIterator) SequenceUtil(htsjdk.samtools.util.SequenceUtil) MergingSamRecordIterator(htsjdk.samtools.MergingSamRecordIterator) Parameter(com.beust.jcommander.Parameter) IOUtil(htsjdk.samtools.util.IOUtil) URL(java.net.URL) IntervalFilter(htsjdk.samtools.filter.IntervalFilter) HashMap(java.util.HashMap) IntervalListProvider(com.github.lindenb.jvarkit.samtools.util.IntervalListProvider) SAMFileHeader(htsjdk.samtools.SAMFileHeader) ValidationStringency(htsjdk.samtools.ValidationStringency) ArrayList(java.util.ArrayList) Interval(htsjdk.samtools.util.Interval) NoSplitter(com.github.lindenb.jvarkit.util.jcommander.NoSplitter) Map(java.util.Map) Launcher(com.github.lindenb.jvarkit.util.jcommander.Launcher) Path(java.nio.file.Path) CloserUtil(htsjdk.samtools.util.CloserUtil) SequenceDictionaryUtils(com.github.lindenb.jvarkit.util.bio.SequenceDictionaryUtils) FilteringSamIterator(htsjdk.samtools.filter.FilteringSamIterator) Files(java.nio.file.Files) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) Logger(com.github.lindenb.jvarkit.util.log.Logger) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Set(java.util.Set) IOException(java.io.IOException) SamReader(htsjdk.samtools.SamReader) Collectors(java.util.stream.Collectors) SAMRecord(htsjdk.samtools.SAMRecord) SamFileHeaderMerger(htsjdk.samtools.SamFileHeaderMerger) List(java.util.List) SamInputResource(htsjdk.samtools.SamInputResource) Paths(java.nio.file.Paths) StringUtils(com.github.lindenb.jvarkit.lang.StringUtils) QueryInterval(htsjdk.samtools.QueryInterval) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) IntervalFilter(htsjdk.samtools.filter.IntervalFilter) FilteringSamIterator(htsjdk.samtools.filter.FilteringSamIterator) QueryInterval(htsjdk.samtools.QueryInterval) Interval(htsjdk.samtools.util.Interval) QueryInterval(htsjdk.samtools.QueryInterval)

Example 2 with IntervalFilter

use of htsjdk.samtools.filter.IntervalFilter in project jvarkit by lindenb.

the class SamReadLengthDistribution method openSamIterator.

/**
 * create input SAMRecord iterator
 */
private CloseableIterator<SAMRecord> openSamIterator(final SamReader sr) {
    if (this.regionFiles != null) {
        this.regionFiles.dictionary(SequenceDictionaryUtils.extractRequired(sr.getFileHeader()));
        if (!sr.hasIndex()) {
            final List<Interval> L = this.regionFiles.stream().map(x -> new Interval(x)).collect(Collectors.toList());
            final SAMRecordIterator st0 = sr.iterator();
            return new FilteringSamIterator(st0, new IntervalFilter(L, sr.getFileHeader()));
        } else {
            return sr.query(this.regionFiles.optimizedQueryIntervals(), false);
        }
    }
    return sr.iterator();
}
Also used : Cigar(htsjdk.samtools.Cigar) CloseableIterator(htsjdk.samtools.util.CloseableIterator) Program(com.github.lindenb.jvarkit.util.jcommander.Program) Parameter(com.beust.jcommander.Parameter) IntervalFilter(htsjdk.samtools.filter.IntervalFilter) IntervalListProvider(com.github.lindenb.jvarkit.samtools.util.IntervalListProvider) SAMRecordPartition(com.github.lindenb.jvarkit.util.samtools.SAMRecordPartition) Interval(htsjdk.samtools.util.Interval) NoSplitter(com.github.lindenb.jvarkit.util.jcommander.NoSplitter) Map(java.util.Map) IOUtils(com.github.lindenb.jvarkit.io.IOUtils) Launcher(com.github.lindenb.jvarkit.util.jcommander.Launcher) DiscreteMedian(com.github.lindenb.jvarkit.math.DiscreteMedian) Path(java.nio.file.Path) PrintWriter(java.io.PrintWriter) SequenceDictionaryUtils(com.github.lindenb.jvarkit.util.bio.SequenceDictionaryUtils) FilteringSamIterator(htsjdk.samtools.filter.FilteringSamIterator) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) Logger(com.github.lindenb.jvarkit.util.log.Logger) IOException(java.io.IOException) SamReader(htsjdk.samtools.SamReader) Collectors(java.util.stream.Collectors) SAMRecord(htsjdk.samtools.SAMRecord) List(java.util.List) SamInputResource(htsjdk.samtools.SamInputResource) TreeMap(java.util.TreeMap) StringUtils(com.github.lindenb.jvarkit.lang.StringUtils) RangeOfIntegers(com.github.lindenb.jvarkit.math.RangeOfIntegers) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) IntervalFilter(htsjdk.samtools.filter.IntervalFilter) FilteringSamIterator(htsjdk.samtools.filter.FilteringSamIterator) Interval(htsjdk.samtools.util.Interval)

Aggregations

Parameter (com.beust.jcommander.Parameter)2 StringUtils (com.github.lindenb.jvarkit.lang.StringUtils)2 IntervalListProvider (com.github.lindenb.jvarkit.samtools.util.IntervalListProvider)2 SequenceDictionaryUtils (com.github.lindenb.jvarkit.util.bio.SequenceDictionaryUtils)2 Launcher (com.github.lindenb.jvarkit.util.jcommander.Launcher)2 NoSplitter (com.github.lindenb.jvarkit.util.jcommander.NoSplitter)2 Logger (com.github.lindenb.jvarkit.util.log.Logger)2 SAMRecord (htsjdk.samtools.SAMRecord)2 SAMRecordIterator (htsjdk.samtools.SAMRecordIterator)2 SamInputResource (htsjdk.samtools.SamInputResource)2 SamReader (htsjdk.samtools.SamReader)2 SamReaderFactory (htsjdk.samtools.SamReaderFactory)2 FilteringSamIterator (htsjdk.samtools.filter.FilteringSamIterator)2 IntervalFilter (htsjdk.samtools.filter.IntervalFilter)2 CloseableIterator (htsjdk.samtools.util.CloseableIterator)2 Interval (htsjdk.samtools.util.Interval)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 List (java.util.List)2 Map (java.util.Map)2