当前位置: 首页>>代码示例>>Java>>正文


Java IntervalTreeMap类代码示例

本文整理汇总了Java中htsjdk.samtools.util.IntervalTreeMap的典型用法代码示例。如果您正苦于以下问题:Java IntervalTreeMap类的具体用法?Java IntervalTreeMap怎么用?Java IntervalTreeMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IntervalTreeMap类属于htsjdk.samtools.util包,在下文中一共展示了IntervalTreeMap类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: groupMrnaStuff

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
protected void groupMrnaStuff(List<Gene> mRnaStuff, IntervalTreeMap<Gene> stuffIntervalMap) {
    for (Gene s : mRnaStuff) {
        Interval interval = new Interval(s.getFeature(), s.getStartIndex(), s.getEndIndex());
        if (stuffIntervalMap.containsKey(interval)) {
            Gene merged = s;
            List<Interval> toRemove = new ArrayList<>();
            for (Gene g : stuffIntervalMap.getOverlapping(interval)) {
                merged.setStartIndex(Math.min(merged.getStartIndex(), g.getStartIndex()));
                merged.setEndIndex(Math.max(merged.getEndIndex(), g.getEndIndex()));
                merged.setGroupId(null);
                merged.setAttributes(Collections.emptyMap());
                toRemove.add(new Interval(s.getFeature(), g.getStartIndex(), g.getEndIndex()));
            }
            merged.setFeature(FeatureType.CDS.name());
            toRemove.forEach(stuffIntervalMap::remove);
            stuffIntervalMap.put(new Interval(s.getFeature(), merged.getStartIndex(), merged.getEndIndex()),
                    merged);
        } else {
            s.setFeature(FeatureType.CDS.name());
            stuffIntervalMap.put(interval, s);
        }
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:24,代码来源:AbstractGeneReader.java

示例2: parseBedAsBooleanIntervalTreeMap

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
public IntervalTreeMap<Boolean> parseBedAsBooleanIntervalTreeMap(final String bedUri) throws IOException
	{
	if(bedUri==null || bedUri.isEmpty()) throw new IllegalArgumentException("bad bed uri");
	BufferedReader r=null;
	final IntervalTreeMap<Boolean> treeMap = new IntervalTreeMap<>();
	try
		{
		r = IOUtils.openURIForBufferedReading(bedUri);
		final BedLineCodec codec=new BedLineCodec();
		r.lines().forEach(L->{
			final BedLine bedline = codec.decode(L);
			if(bedline==null) {
				LOG.warn("Ignoring line in BED (doesn't look like a BED line):"+L);
				return;
			}
			treeMap.put(bedline.toInterval(),Boolean.TRUE);
			});
		
		return treeMap;
		}
	finally
		{
		CloserUtil.close(r);
		}
	
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:27,代码来源:KnimeVariantHelper.java

示例3: readBedFile

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
private void readBedFile(final File bedFile)
{
if(this.intervals==null)
	{
	intervals=new IntervalTreeMap<Boolean>();
	}
try
	{
	LOG.info("Reading "+bedFile);
	final BedLineCodec bedLineCodec = new BedLineCodec();
	BufferedReader r=IOUtils.openFileForBufferedReading(bedFile);
	String line;
	while((line=r.readLine())!=null)
		{
		final BedLine bedLine = bedLineCodec.decode(line);
		if(bedLine==null) continue;
		this.intervals.put(bedLine.toInterval(),true);
		}
	CloserUtil.close(r);
	}
catch(final IOException err)
	{
	LOG.error(err);
	throw new RuntimeException(err);	
	}
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:27,代码来源:BamCmpCoverage.java

示例4: analyseSamRecord

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
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);
	}
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:27,代码来源:SamScanSplitReads.java

示例5: readBedFileAsBooleanIntervalTreeMap

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
/** reads a Bed file and convert it to a IntervalTreeMap<Boolean> */
protected IntervalTreeMap<Boolean> readBedFileAsBooleanIntervalTreeMap(final java.io.File file) throws java.io.IOException
	{
	java.io.BufferedReader r=null;
	try
		{
		final  IntervalTreeMap<Boolean> intervals = new IntervalTreeMap<Boolean>();
		r=com.github.lindenb.jvarkit.io.IOUtils.openFileForBufferedReading(file);
		final BedLineCodec bedCodec=new BedLineCodec();
		r.lines().
			filter(line->!(line.startsWith("#") ||  com.github.lindenb.jvarkit.util.bio.bed.BedLine.isBedHeader(line) ||  line.isEmpty())).
			map(line->bedCodec.decode(line)).
			filter(B->B!=null).
			map(B->B.toInterval()).
			filter(L->L.getStart()<L.getEnd()).
			forEach(L->{intervals.put(L,true); }
			);	
		return intervals;
		}
	finally
		{
		htsjdk.samtools.util.CloserUtil.close(r);
		}
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:25,代码来源:Launcher.java

示例6: collapseFeatures

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
@Override
protected void collapseFeatures(final ConcurrentMap<String, ConcurrentMap<String, List<Gene>>> mRnaStuffMap,
                                Gene gene, final ConcurrentMap<String, ConcurrentMap<String, Gene>> mRnaMap,
                                Double scaleFactor, List<Gene> passedGenes) {
    ConcurrentMap<String, Gene> mrnas = mRnaMap.remove(gene.getGffId());

    if (mrnas != null && scaleFactor > LARGE_SCALE_FACTOR_LIMIT) {
        IntervalTreeMap<Gene> stuffIntervalMap = new IntervalTreeMap<>();
        Gene canonicalTranscript = createCanonicalTranscript(gene);

        for (Map.Entry<String, Gene> mrnaEntry : mrnas.entrySet()) {
            Gene transcript = mrnaEntry.getValue();
            setCanonicalTranscriptIndexes(canonicalTranscript, transcript);

            if (mRnaStuffMap.containsKey(transcript.getGffId()) &&
                    mRnaStuffMap.get(transcript.getGffId()).containsKey(transcript.getGffId())) {

                List<Gene> mRnaStuff = mRnaStuffMap.get(transcript.getGffId()).remove(transcript.getGffId());
                removeIfEmpty(mRnaStuffMap, transcript.getGffId());

                groupMrnaStuff(mRnaStuff, stuffIntervalMap);
            }
        }

        canonicalTranscript.setItems(new ArrayList<>(stuffIntervalMap.values()));
        gene.setItems(Collections.singletonList(canonicalTranscript));

        if (gene.getExonsCount() == null) {
            calculateExonsCountAndLength(gene, canonicalTranscript.getItems());
        }
    }

    if (passesScaleFactor(gene, scaleFactor)) {
        passedGenes.add(gene);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:37,代码来源:GffReader.java

示例7: collapseFeatures

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
@Override
protected void collapseFeatures(final ConcurrentMap<String, ConcurrentMap<String, List<Gene>>> mRnaStuffMap,
                                Gene gene, final ConcurrentMap<String, ConcurrentMap<String, Gene>> mRnaMap,
                                Double scaleFactor, List<Gene> passedGenes) {
    final ConcurrentMap<String, Gene> mrnas = mRnaMap.remove(gene.getGroupId());

    if (mrnas != null && scaleFactor > LARGE_SCALE_FACTOR_LIMIT) {
        IntervalTreeMap<Gene> stuffIntervalMap = new IntervalTreeMap<>();
        Gene canonicalTranscript = createCanonicalTranscript(gene);

        for (Map.Entry<String, Gene> mrnaEntry : mrnas.entrySet()) {
            setCanonicalTranscriptIndexes(canonicalTranscript, mrnaEntry.getValue());

            if (mRnaStuffMap.containsKey(gene.getGroupId())
                    && mRnaStuffMap.get(gene.getGroupId()).containsKey(mrnaEntry.getKey())) {
                List<Gene> mRnaStuff = mRnaStuffMap.get(gene.getGroupId()).remove(mrnaEntry.getKey());
                removeIfEmpty(mRnaStuffMap, gene.getGroupId());

                groupMrnaStuff(mRnaStuff, stuffIntervalMap);
            }
        }

        canonicalTranscript.setItems(new ArrayList<>(stuffIntervalMap.values()));
        gene.setItems(Collections.singletonList(canonicalTranscript));

        if (gene.getExonsCount() == null) {
            calculateExonsCountAndLength(gene, canonicalTranscript.getItems());
        }
    }

    if (passesScaleFactor(gene, scaleFactor)) {
        passedGenes.add(gene);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:35,代码来源:GtfReader.java

示例8:

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
/** reads a Bed file and convert it to a IntervalTreeMap<Bedline> */
private htsjdk.samtools.util.IntervalTreeMap<Set<com.github.lindenb.jvarkit.util.bio.bed.BedLine>> 
	readBedFileAsIntervalTreeMap(final java.io.File file) throws java.io.IOException
	{
	java.io.BufferedReader r=null;
	try
		{
		final  htsjdk.samtools.util.IntervalTreeMap<Set<com.github.lindenb.jvarkit.util.bio.bed.BedLine>> intervals = new
				 htsjdk.samtools.util.IntervalTreeMap<>();
		r=com.github.lindenb.jvarkit.io.IOUtils.openFileForBufferedReading(file);
		String line;
		final com.github.lindenb.jvarkit.util.bio.bed.BedLineCodec codec = new com.github.lindenb.jvarkit.util.bio.bed.BedLineCodec();
		while((line=r.readLine())!=null) 
			{
			if(line.startsWith("#") ||  com.github.lindenb.jvarkit.util.bio.bed.BedLine.isBedHeader(line) ||  line.isEmpty()) continue; 
			final com.github.lindenb.jvarkit.util.bio.bed.BedLine bl = codec.decode(line);
			if(bl==null || bl.getStart()>bl.getEnd()) continue;
			final htsjdk.samtools.util.Interval interval= bl.toInterval();
			Set<BedLine> set = intervals.get(interval);
			if(set==null )
				{
				set = new HashSet<>();
				intervals.put(interval,set); 
				}
			set.add(bl);
			}
		return intervals;
		}
	finally
		{
		htsjdk.samtools.util.CloserUtil.close(r);
		}
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:34,代码来源:VCFBed.java

示例9: loadUriAsIntervalTreeMap

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
/** load knownGene file/uri as an IntervalTreeMap. Intervals in the IntervalTreeMap are *1-based* (interval.start= kg.txStart+1)*/
public static IntervalTreeMap<List<KnownGene>> loadUriAsIntervalTreeMap(
		final String uri,
		final Predicate<KnownGene> filterOrNull
		) throws IOException
	{
	final IntervalTreeMap<List<KnownGene>> treeMap = new IntervalTreeMap<>();
	BufferedReader in=null;
	try {
		in = IOUtils.openURIForBufferedReading(uri);
		String line;
		final Pattern tab = Pattern.compile("[\t]");
		while ((line = in.readLine()) != null) {
			if (line.isEmpty())
				continue;
			final String tokens[] = tab.split(line);
			final KnownGene g = new KnownGene(tokens);
			if(filterOrNull!=null && !filterOrNull.test(g)) continue;
			final Interval interval = new Interval(g.getContig(),g.getTxStart()+1,g.getTxEnd(),g.isNegativeStrand(),g.getName());
			List<KnownGene> L=  treeMap.get(interval);
			if(L==null) {
				L=new ArrayList<>(2);
				treeMap.put(interval, L);
				}
			
			L.add(g);
		}
		in.close();
		in = null;
		return treeMap;
		}
	finally {
		CloserUtil.close(in);
		}
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:36,代码来源:KnownGene.java

示例10: overlapBed

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
private static Predicate<SAMRecord> overlapBed(final String fname) {
    final File bedFile = new File(fname);
    final BedLineCodec codec = new BedLineCodec();
    final IntervalTreeMap<Boolean> intervals = new IntervalTreeMap<Boolean>();
    BufferedReader r = null;
    try {
        r = IOUtils.openFileForBufferedReading(bedFile);
        String line;
        while((line=r.readLine())!=null) {
                final BedLine bedline = codec.decode(line);
                if(bedline==null)  continue;
                intervals.put(new Interval(
                        bedline.getContig(),
                        bedline.getStart()+1,
                        bedline.getEnd()),
                        Boolean.TRUE
                        );
        }
        CloserUtil.close(r);
            return new Predicate<SAMRecord>() {
                                @Override
                                public boolean test(final SAMRecord t) {
                                        return !t.getReadUnmappedFlag() &&
                                                        intervals.containsContained(new Interval(t.getContig(), t.getStart(), t.getEnd()))
                                                        ;
                                }
                        };
    } catch(final IOException err) {
        LOG.error(err);
        throw new RuntimeIOException(err);
    }
    finally {
        CloserUtil.close(r);
    }
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:36,代码来源:SamFilterParser.java

示例11: NggbIntervalTreeMap

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
public NggbIntervalTreeMap() {
    super();
    this.treeMap = new IntervalTreeMap<>();
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:5,代码来源:NggbIntervalTreeMap.java

示例12: getTreeMap

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
public IntervalTreeMap<T> getTreeMap() {
    return treeMap;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:4,代码来源:NggbIntervalTreeMap.java

示例13: loadKnownGenesFromUri

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
private void loadKnownGenesFromUri() throws IOException
{
BufferedReader in=null;
try {
	if (this.referenceGenome.getDictionary() == null) {
		throw new JvarkitException.FastaDictionaryMissing(this.referenceGenomeSource);
	}
	int n_ignored=0;
	int n_genes = 0;
	this.knownGenes = new IntervalTreeMap<>();
	LOG.info("loading genes");

	final ContigNameConverter contigNameConverter = ContigNameConverter.fromOneDictionary(this.referenceGenome.getDictionary());
	contigNameConverter.setOnNotFound(OnNotFound.SKIP);
	
	in = IOUtils.openURIForBufferedReading(this.kgURI);
	String line;
	final Pattern tab = Pattern.compile("[\t]");
	while ((line = in.readLine()) != null) {
		if (StringUtil.isBlank(line))
			continue;
		final String tokens[] = tab.split(line);
		final KnownGene g = new KnownGene(tokens);
		final String normalizedContig = contigNameConverter.apply(g.getContig());
		if(StringUtil.isBlank(normalizedContig)) {
			++n_ignored;
			continue;
		}
		
		if (this.referenceGenome.getDictionary().getSequence(normalizedContig) == null) {
			++n_ignored;
			continue;
		}
		final int extend_gene_search = 5000; // because we want to set
												// SO:5KB_upstream_variant

		final Interval interval = new Interval(
				normalizedContig,
				Math.max(1, g.getTxStart() + 1 - extend_gene_search),
				g.getTxEnd() + extend_gene_search
				);
		List<KnownGene> L= this.knownGenes.get(interval);
		if(L==null) {
			L=new ArrayList<>(2);
			this.knownGenes.put(interval, L);
		}
		++n_genes;
		L.add(g);
	}
	in.close();
	in = null;
	LOG.info("genes:" + n_genes+" (ignored: "+n_ignored+")");
	}
finally {
	CloserUtil.close(in);
	}
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:58,代码来源:VCFPredictions.java

示例14: loadEntrezGenes

import htsjdk.samtools.util.IntervalTreeMap; //导入依赖的package包/类
protected void loadEntrezGenes(SAMSequenceDictionary dict) throws IOException
{
this.ncbiGeneMap=new IntervalTreeMap<Integer>();
BiomartQuery q=new BiomartQuery();
q.setDataSetName("hsapiens_gene_ensembl");
q.setAttributes(
		"chromosome_name",
		"start_position",
		"end_position",
		"entrezgene"
		);
q.setUniqRows(true);
LOG.info("sending "+q);


LOG.info("invoking biomart "+q);
LineReader r=q.execute();
@SuppressWarnings("resource")
LineIterator lr=new LineIteratorImpl(r);
Pattern pattern=Pattern.compile("[\t]");
while(lr.hasNext())
	{
	String line=lr.next();
	String param[]=pattern.split(line);
	if(param.length<4 || param[3].isEmpty()) continue;
	SAMSequenceRecord rec=null;
	if((rec=dict.getSequence(param[0]))==null) continue;
	try
		{
		int start=Integer.parseInt(param[0]);
		int end=Integer.parseInt(param[1]);
		int ncbiGene=Integer.parseInt(param[3]);
		if(!gene2doid.containsKey(ncbiGene)) continue;
		ncbiGeneMap.put(new Interval(rec.getSequenceName(),start,end),ncbiGene);
		}
	catch (Exception e)
		{
		LOG.warning(e);
		continue;
		}
	
	
	}
r.close();
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:46,代码来源:AbstractVCFDiseaseOntology.java


注:本文中的htsjdk.samtools.util.IntervalTreeMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。