/** * Derived class may override this method in order to return a different set of genes for * picking transcripts for computing coverage, or to cache the value returned by geneOverlapDetector.getAll(), * because it can be expensive to compute repeatedly. */ protected Set<Gene> getGenesForPickTranscripts() { return geneOverlapDetector.getAll(); }
/** * Derived class may override this method in order to return a different set of genes for * picking transcripts for computing coverage, or to cache the value returned by geneOverlapDetector.getAll(), * because it can be expensive to compute repeatedly. */ protected Set<Gene> getGenesForPickTranscripts() { return geneOverlapDetector.getAll(); }
/** * Load UCSC chain file in order to lift over Intervals. */ public LiftOver(File chainFile) { IOUtil.assertFileIsReadable(chainFile); chains = Chain.loadChains(chainFile); for (final Chain chain : this.chains.getAll()) { final String from = chain.fromSequenceName; final String to = chain.toSequenceName; final Set<String> names; if (contigMap.containsKey(from)) { names = contigMap.get(from); } else { names = new HashSet<>(); contigMap.put(from, names); } names.add(to); } }
/** * Load UCSC chain file in order to lift over Intervals. */ public LiftOver(File chainFile) { IOUtil.assertFileIsReadable(chainFile); chains = Chain.loadChains(chainFile); for (final Chain chain : this.chains.getAll()) { final String from = chain.fromSequenceName; final String to = chain.toSequenceName; final Set<String> names; if (contigMap.containsKey(from)) { names = contigMap.get(from); } else { names = new HashSet<>(); contigMap.put(from, names); } names.add(to); } }
/** * Throw an exception if all the "to" sequence names in the chains are not found in the given sequence dictionary. */ public void validateToSequences(final SAMSequenceDictionary sequenceDictionary) { for (final Chain chain : chains.getAll()) { if (sequenceDictionary.getSequence(chain.toSequenceName) == null) { throw new SAMException("Sequence " + chain.toSequenceName + " from chain file is not found in sequence dictionary."); } } }
/** * Throw an exception if all the "to" sequence names in the chains are not found in the given sequence dictionary. */ public void validateToSequences(final SAMSequenceDictionary sequenceDictionary) { for (final Chain chain : chains.getAll()) { if (sequenceDictionary.getSequence(chain.toSequenceName) == null) { throw new SAMException("Sequence " + chain.toSequenceName + " from chain file is not found in sequence dictionary."); } } }
/** * Throw an exception if all the "to" sequence names in the chains are not found in the given sequence dictionary. */ public void validateToSequences(final SAMSequenceDictionary sequenceDictionary) { for (final Chain chain : chains.getAll()) { if (sequenceDictionary.getSequence(chain.toSequenceName) == null) { throw new SAMException("Sequence " + chain.toSequenceName + " from chain file is not found in sequence dictionary."); } } }
@Test(dataProvider = "intervalsSameContig") public void testOverlap(final List<Locatable> input, final Interval query, final List<Locatable> expected) throws Exception { final OverlapDetector<Locatable> targetDetector = OverlapDetector.create(input); final Set<Locatable> actual = targetDetector.getOverlaps(query); Assert.assertEquals(actual, new HashSet<>(expected)); Assert.assertEquals(targetDetector.overlapsAny(query), !expected.isEmpty()); Assert.assertEquals(new HashSet<>(targetDetector.getAll()), new HashSet<>(input)); }
@Test public void testWriteChain() throws Exception { final OverlapDetector<Chain> chains = Chain.loadChains(CHAIN_FILE); File outFile = File.createTempFile("test.", ".chain"); outFile.deleteOnExit(); PrintWriter pw = new PrintWriter(outFile); final Map<Integer, Chain> originalChainMap = new TreeMap<Integer, Chain>(); for (final Chain chain : chains.getAll()) { chain.write(pw); originalChainMap.put(chain.id, chain); } pw.close(); final OverlapDetector<Chain> newChains = Chain.loadChains(outFile); final Map<Integer, Chain> newChainMap = new TreeMap<Integer, Chain>(); for (final Chain chain : newChains.getAll()) { newChainMap.put(chain.id, chain); } Assert.assertEquals(newChainMap, originalChainMap); }
@Override protected void setup(final SAMFileHeader header, final File samFile) { if (CHART_OUTPUT != null) IOUtil.assertFileIsWritable(CHART_OUTPUT); final OverlapDetector<Gene> geneOverlapDetector = GeneAnnotationReader.loadRefFlat(REF_FLAT, header.getSequenceDictionary()); LOG.info("Loaded " + geneOverlapDetector.getAll().size() + " genes."); final Long ribosomalBasesInitialValue = RIBOSOMAL_INTERVALS != null ? 0L : null; final OverlapDetector<Interval> ribosomalSequenceOverlapDetector = RnaSeqMetricsCollector.makeOverlapDetector(samFile, header, RIBOSOMAL_INTERVALS, LOG); final HashSet<Integer> ignoredSequenceIndices = RnaSeqMetricsCollector.makeIgnoredSequenceIndicesSet(header, IGNORE_SEQUENCE); collector = new RnaSeqMetricsCollector(METRIC_ACCUMULATION_LEVEL, header.getReadGroups(), ribosomalBasesInitialValue, geneOverlapDetector, ribosomalSequenceOverlapDetector, ignoredSequenceIndices, MINIMUM_LENGTH, STRAND_SPECIFICITY, RRNA_FRAGMENT_PERCENTAGE, true); // If we're working with a single library, assign that library's name as a suffix to the plot title final List<SAMReadGroupRecord> readGroups = header.getReadGroups(); if (readGroups.size() == 1) { this.plotSubtitle = readGroups.get(0).getLibrary(); if (null == this.plotSubtitle) this.plotSubtitle = ""; } }
@Override protected void setup(final SAMFileHeader header, final File samFile) { if (CHART_OUTPUT != null) IOUtil.assertFileIsWritable(CHART_OUTPUT); final OverlapDetector<Gene> geneOverlapDetector = GeneAnnotationReader.loadRefFlat(REF_FLAT, header.getSequenceDictionary()); LOG.info("Loaded " + geneOverlapDetector.getAll().size() + " genes."); final Long ribosomalBasesInitialValue = RIBOSOMAL_INTERVALS != null ? 0L : null; final OverlapDetector<Interval> ribosomalSequenceOverlapDetector = RnaSeqMetricsCollector.makeOverlapDetector(samFile, header, RIBOSOMAL_INTERVALS, LOG); final HashSet<Integer> ignoredSequenceIndices = RnaSeqMetricsCollector.makeIgnoredSequenceIndicesSet(header, IGNORE_SEQUENCE); collector = new RnaSeqMetricsCollector(METRIC_ACCUMULATION_LEVEL, header.getReadGroups(), ribosomalBasesInitialValue, geneOverlapDetector, ribosomalSequenceOverlapDetector, ignoredSequenceIndices, MINIMUM_LENGTH, STRAND_SPECIFICITY, RRNA_FRAGMENT_PERCENTAGE, true); // If we're working with a single library, assign that library's name as a suffix to the plot title final List<SAMReadGroupRecord> readGroups = header.getReadGroups(); if (readGroups.size() == 1) { this.plotSubtitle = readGroups.get(0).getLibrary(); if (null == this.plotSubtitle) this.plotSubtitle = ""; } }