public void setHeader(final SAMFileHeader header) { this.header = header.clone(); }
public void setHeader(final SAMFileHeader header) { this.header = header.clone(); }
/** * creates a independent copy of the given IntervalList */ public static IntervalList copyOf(final IntervalList list) { final IntervalList clone = new IntervalList(list.header.clone()); clone.intervals.addAll(list.intervals); return clone; }
/** creates a independent copy of the given IntervalList * * @param list * @return */ public static IntervalList copyOf(final IntervalList list){ final IntervalList clone = new IntervalList(list.header.clone()); clone.intervals.addAll(list.intervals); return clone; }
/** * creates a independent copy of the given IntervalList */ public static IntervalList copyOf(final IntervalList list) { final IntervalList clone = new IntervalList(list.header.clone()); clone.intervals.addAll(list.intervals); return clone; }
/** * Copy the CRAM header into a new {@link CramHeader} object. * @return a complete copy of the header */ @SuppressWarnings("CloneDoesntCallSuperClone") @Override public CramHeader clone() { final CramHeader clone = new CramHeader(); clone.version = version; System.arraycopy(id, 0, clone.id, 0, id.length); clone.samFileHeader = getSamFileHeader().clone(); return clone; }
/** * Copy the CRAM header into a new {@link CramHeader} object. * @return a complete copy of the header */ @SuppressWarnings("CloneDoesntCallSuperClone") @Override public CramHeader clone() { final CramHeader clone = new CramHeader(); clone.version = version; System.arraycopy(id, 0, clone.id, 0, id.length); clone.samFileHeader = getSamFileHeader().clone(); return clone; }
/** * Returned an independent IntervalList that is sorted and uniquified. * @param concatenateNames If false, interval names are not concatenated when merging intervals to save space. */ public IntervalList uniqued(final boolean concatenateNames) { final List<Interval> tmp = getUniqueIntervals(sorted(), concatenateNames); final IntervalList value = new IntervalList(this.header.clone()); value.intervals.addAll(tmp); return value; }
/** * Returned an independent IntervalList that is sorted and uniquified. * * @param concatenateNames If false, interval names are not concatenated when merging intervals to save space. */ public IntervalList uniqued(final boolean concatenateNames) { final List<Interval> tmp = getUniqueIntervals(sorted(), concatenateNames); final IntervalList value = new IntervalList(this.header.clone()); value.intervals.addAll(tmp); return value; }
/** * Returned an independent IntervalList that is sorted and uniquified. * * @param concatenateNames If false, interval names are not concatenated when merging intervals to save space. */ public IntervalList uniqued(final boolean concatenateNames) { final List<Interval> tmp = getUniqueIntervals(sorted(), concatenateNames); final IntervalList value = new IntervalList(this.header.clone()); value.intervals.addAll(tmp); return value; }
/** * Creates a program record for the program, adds it to the list of program records (@PG tags) in the bam file and sets * up the writer with the header and presorted status. * * @param originalHeader original header * @param programRecord the program record for this program */ public static SAMFileHeader setupWriter(final SAMFileHeader originalHeader, final SAMProgramRecord programRecord) { final SAMFileHeader header = originalHeader.clone(); final List<SAMProgramRecord> oldRecords = header.getProgramRecords(); final List<SAMProgramRecord> newRecords = new ArrayList<SAMProgramRecord>(oldRecords.size()+1); for ( SAMProgramRecord record : oldRecords ) if ( (programRecord != null && !record.getId().startsWith(programRecord.getId()))) newRecords.add(record); if (programRecord != null) { newRecords.add(programRecord); header.setProgramRecords(newRecords); } return header; }
/** * A utility function for merging a list of IntervalLists, checks for equal dictionaries. * Merging does not look for overlapping intervals nor uniquify * * @param lists a list of IntervalList * @return the union of all the IntervalLists in lists. */ public static IntervalList concatenate(final Collection<IntervalList> lists) { if (lists.isEmpty()) { throw new SAMException("Cannot concatenate an empty list of IntervalLists."); } // Ensure that all the sequence dictionaries agree and merge the lists final SAMFileHeader header = lists.iterator().next().getHeader().clone(); header.setSortOrder(SAMFileHeader.SortOrder.unsorted); final IntervalList merged = new IntervalList(header); for (final IntervalList in : lists) { SequenceUtil.assertSequenceDictionariesEqual(merged.getHeader().getSequenceDictionary(), in.getHeader().getSequenceDictionary()); merged.addall(in.intervals); } return merged; }
/** * Returns a new IntervalList where each interval is padded by the specified amount of bases. */ public IntervalList padded(final int before, final int after) { if (before < 0 || after < 0) { throw new IllegalArgumentException("Padding values must be >= 0."); } final IntervalList padded = new IntervalList(this.getHeader().clone()); final SAMSequenceDictionary dict = padded.getHeader().getSequenceDictionary(); for (final Interval i : this) { final SAMSequenceRecord seq = dict.getSequence(i.getContig()); final int start = Math.max(1, i.getStart() - before); final int end = Math.min(seq.getSequenceLength(), i.getEnd() + after); padded.add(new Interval(i.getContig(), start, end, i.isNegativeStrand(), i.getName())); } return padded; }
protected void kickedFromCache(FastqRead read) { if (writer == null) { log.info("Creating overflow BAM file."); headerForOverflowWriter = header.clone(); headerForOverflowWriter.setSortOrder(SAMFileHeader.SortOrder.queryname); writer = new SAMFileWriterFactory().makeBAMWriter(headerForOverflowWriter, false, cacheOverFlowStream); } SAMRecord r = read.toSAMRecord(writer.getFileHeader()); writer.addAlignment(r); }
/** * Returns a new IntervalList where each interval is padded by the specified amount of bases. */ public IntervalList padded(final int before, final int after) { if (before < 0 || after < 0) { throw new IllegalArgumentException("Padding values must be >= 0."); } final IntervalList padded = new IntervalList(this.getHeader().clone()); final SAMSequenceDictionary dict = padded.getHeader().getSequenceDictionary(); for (final Interval i : this) { final SAMSequenceRecord seq = dict.getSequence(i.getContig()); final int start = Math.max(1, i.getStart() - before); final int end = Math.min(seq.getSequenceLength(), i.getEnd() + after); padded.add(new Interval(i.getContig(), start, end, i.isNegativeStrand(), i.getName())); } return padded; }
@Test public void testCRAMQuerySort() throws IOException { final File input = new File("src/test/resources/htsjdk/samtools/cram_query_sorted.cram"); final File reference = new File("src/test/resources/htsjdk/samtools/cram_query_sorted.fasta"); final File outputFile = File.createTempFile("tmp.", ".cram"); try (final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(reference).open(input); final SAMFileWriter writer = new SAMFileWriterFactory().makeWriter(reader.getFileHeader().clone(), false, outputFile, reference)) { for (SAMRecord rec : reader) { writer.addAlignment(rec); } } try (final SamReader outReader = SamReaderFactory.makeDefault().referenceSequence(reference).open(outputFile)) { String prevName = null; for (final SAMRecord rec : outReader) { if (prevName == null) { prevName = rec.getReadName(); continue; } // test if the read names are sorted alphabetically: Assert.assertTrue(rec.getReadName().compareTo(prevName) >= 0); } } }
@Override public void initialize() { // All for the no_pg_tag. Should this be in the engine and not in the walker? final GenomeAnalysisEngine toolkit = getToolkit(); final SAMFileHeader outputHeader = toolkit.getSAMFileHeader().clone(); final String PROGRAM_RECORD_NAME = "GATK PrintReads"; final boolean preSorted = true; if (toolkit.getArguments().BQSR_RECAL_FILE != null && !NO_PG_TAG ) { NWaySAMFileWriter.setupWriter(out, toolkit, outputHeader, preSorted, this, PROGRAM_RECORD_NAME); } else { out.writeHeader(outputHeader); out.setPresorted(preSorted); } }
/** * A utility function for generating the intersection of two IntervalLists, checks for equal dictionaries. * * @param list1 the first IntervalList * @param list2 the second IntervalList * @return the intersection of list1 and list2. */ public static IntervalList intersection(final IntervalList list1, final IntervalList list2) { final IntervalList result; // Ensure that all the sequence dictionaries agree and merge the lists SequenceUtil.assertSequenceDictionariesEqual(list1.getHeader().getSequenceDictionary(), list2.getHeader().getSequenceDictionary()); result = new IntervalList(list1.getHeader().clone()); final OverlapDetector<Interval> detector = new OverlapDetector<>(0, 0); detector.addAll(list1.getIntervals(), list1.getIntervals()); for (final Interval i : list2.getIntervals()) { final Collection<Interval> as = detector.getOverlaps(i); for (final Interval j : as) { final Interval tmp = i.intersect(j); result.add(tmp); } } return result.uniqued(); }
/** * A utility function for generating the intersection of two IntervalLists, checks for equal dictionaries. * * @param list1 the first IntervalList * @param list2 the second IntervalList * @return the intersection of list1 and list2. */ public static IntervalList intersection(final IntervalList list1, final IntervalList list2) { final IntervalList result; // Ensure that all the sequence dictionaries agree and merge the lists SequenceUtil.assertSequenceDictionariesEqual(list1.getHeader().getSequenceDictionary(), list2.getHeader().getSequenceDictionary()); result = new IntervalList(list1.getHeader().clone()); final OverlapDetector<Interval> detector = new OverlapDetector<>(0, 0); detector.addAll(list1.getIntervals(), list1.getIntervals()); for (final Interval i : list2.getIntervals()) { final Collection<Interval> as = detector.getOverlaps(i); for (final Interval j : as) { final Interval tmp = i.intersect(j); result.add(tmp); } } return result.uniqued(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void changeHeader() { SAMFileHeader clonedHeader = fileHeader.clone(); clonedHeader.addSequence(new SAMSequenceRecord("4", 1000)); IntervalList usingClone1 = new IntervalList(clonedHeader); usingClone1.add(new Interval("4", 1, 100)); IntervalList usingClone2 = new IntervalList(clonedHeader); usingClone2.add(new Interval("4", 10, 20)); IntervalList expected = new IntervalList(clonedHeader); expected.add(new Interval("4", 1, 9)); expected.add(new Interval("4", 21, 100)); //pull rug from underneath (one call will change all the headers, since there's actually only one) usingClone1.getHeader().setSequenceDictionary(fileHeader.getSequenceDictionary()); //now interval lists are in "illegal state" since they contain contigs that are not in the header. //this next step should fail IntervalList.subtract(usingClone1, usingClone2); Assert.assertTrue(false); }