private synchronized String getHashString() { if (hashString == null) { hashString = read1 != null ? read1.getSAMString() : "null" + read2 != null ? read2.getSAMString() : "null"; } return hashString; }
@Override public String toString() { return record.getSAMString(); }
@Override public String toString() { return record.getSAMString().trim(); // remove trailing newline } }
@Override public String toString() { return record.getSAMString().trim(); // remove trailing newline } }
@Override public String toString() { return record.getSAMString().trim(); // remove trailing newline } }
/** * Low-level helper function that returns the new reference index for oldIndex according to the * ordering map newOrder. Read is provided in case an error occurs, so that an informative message * can be made. */ private int newOrderIndex(SAMRecord read, int oldIndex, Map<Integer, Integer> newOrder) { if (oldIndex == -1) return -1; // unmapped read else { final Integer n = newOrder.get(oldIndex); if (n == null) throw new PicardException("BUG: no mapping found for read " + read.getSAMString()); else return n; } }
/** * Low-level helper function that returns the new reference index for oldIndex according to the * ordering map newOrder. Read is provided in case an error occurs, so that an informative message * can be made. */ private int newOrderIndex(SAMRecord read, int oldIndex, Map<Integer, Integer> newOrder) { if (oldIndex == -1) return -1; // unmapped read else { final Integer n = newOrder.get(oldIndex); if (n == null) throw new PicardException("BUG: no mapping found for read " + read.getSAMString()); else return n; } }
@Override public SAMRecord next() { final SAMRecord result = wrappedIterator.next(); if (checker != null) { final SAMRecord previous = checker.getPreviousRecord(); if (!checker.isSorted(result)) { throw new IllegalStateException(String.format( "Record %s should come after %s when sorting with %s ordering.", previous.getSAMString().trim(), result.getSAMString().trim(), checker.getSortOrder())); } } return result; }
@Override public SAMRecord next() { final SAMRecord result = wrappedIterator.next(); if (checker != null) { final SAMRecord previous = checker.getPreviousRecord(); if (!checker.isSorted(result)) { throw new IllegalStateException(String.format( "Record %s should come after %s when sorting with %s ordering.", previous.getSAMString().trim(), result.getSAMString().trim(), checker.getSortOrder())); } } return result; }
@Override protected List<String> getRecordsAsStrings() { List<String> featureList= new ArrayList<String>(); for(List<SamSequenceFragment> x : this.readStack){ for(SamSequenceFragment frag : x){ featureList.add(frag.getLeftRead().getSamRecord().getSAMString()); if(frag.getRightRead() != null){ featureList.add(frag.getRightRead().getSamRecord().getSAMString()); } } } return featureList; }
@Override public SAMRecord next() throws PicardException { final SAMRecord toReturn = nextRecord; // save for return // This should always return an element // NB: it should be the case that nextRecord != null if (null == toReturn) { throw new NoSuchElementException(); } // Get the next record, if possible // NB: it should be the case that (nextRecord != null), due to the (null == toReturn) above if (hasNext()) { nextRecord = markDuplicatesAndGetTheNextAvailable(); // get one more, if possible } else { nextRecord = null; } // Check for sorted order if (null != nextRecord && 0 < sortComparator.fileOrderCompare(toReturn, nextRecord)) { System.err.print("Previous record: " + toReturn.getSAMString()); System.err.print("Current record:" + nextRecord.getSAMString()); throw new PicardException("Records were not found coordinate sort order"); } return toReturn; }
/** * Return the sort key used for the given sort order. Useful in error messages. * This should only be used in error messages and program correctness should not rely on this. */ public String getSortKey(final SAMRecord rec) { switch (sortOrder) { case coordinate: return rec.getReferenceName() + ":" + rec.getAlignmentStart(); case queryname: return rec.getReadName(); default: return rec.getSAMString().trim(); } } }
/** * Return the sort key used for the given sort order. Useful in error messages. * This should only be used in error messages and program correctness should not rely on this. */ public String getSortKey(final SAMRecord rec) { switch (sortOrder) { case coordinate: return rec.getReferenceName() + ":" + rec.getAlignmentStart(); case queryname: return rec.getReadName(); default: return rec.getSAMString().trim(); } } }
private void sort() { if (!records.isEmpty()) { if (1 < records.size()) { Collections.sort(records, this.comparator); } if (setDuplicateFlag) { // reset duplicate flags for (final SAMRecord record : records) { if (!record.getReadUnmappedFlag() && !record.isSecondaryOrSupplementary() && !record.getReadName().equals(representative.getReadName())) { record.setDuplicateReadFlag(true); } } records.get(0).setDuplicateReadFlag(false); } if (!records.get(0).equals(this.representative)) { throw new SAMException("BUG: the representative was not the first record after sorting." + "\nFIRST: " + records.get(0).getSAMString() + "\nSECOND: " + this.representative.getSAMString()); } } needsSorting = false; // this could be in the if above if you think hard about it }
private void checkPassesFilter(final boolean expected, final SAMRecord record, final String sequence, final int startPos, final int endPos, final boolean contained) { final boolean passes = passesFilter(record, sequence, startPos, endPos, contained); if (passes != expected) { System.out.println("Error: Record erroneously " + (passes ? "passed" : "failed") + " filter."); System.out.println(" Record: " + record.getSAMString()); System.out.println(" Filter: " + sequence + ":" + startPos + "-" + endPos + " (" + (contained ? "contained" : "overlapping") + ")"); assertEquals(passes, expected); } }
private void checkPassesFilter(final boolean expected, final SAMRecord record, final String sequence, final int startPos, final int endPos, final boolean contained) { final boolean passes = passesFilter(record, sequence, startPos, endPos, contained); if (passes != expected) { System.out.println("Error: Record erroneously " + (passes ? "passed" : "failed") + " filter."); System.out.println(" Record: " + record.getSAMString()); System.out.println(" Filter: " + sequence + ":" + startPos + "-" + endPos + " (" + (contained ? "contained" : "overlapping") + ")"); assertEquals(passes, expected); } }
@Test public void testEmptyArrayAttributeHasNoCommaWhenWrittenToSAM(){ final SAMFileHeader header = new SAMFileHeader(); final SAMRecord record = new SAMRecord(header); record.setAttribute("xa", new int[0]); Assert.assertTrue(record.getSAMString().endsWith("xa:B:i\n")); } }
/** * A wrapper method to provide better diagnostics for ArrayIndexOutOfBoundsException. * * @param cramRecord CRAM record * @param samRecord SAM record * @return a list of read features created for the given {@link htsjdk.samtools.SAMRecord} */ private List<ReadFeature> checkedCreateVariations(final CramCompressionRecord cramRecord, final SAMRecord samRecord) { try { return createVariations(cramRecord, samRecord); } catch (final ArrayIndexOutOfBoundsException e) { log.error("Reference bases array length=" + refBases.length); log.error("Offensive CRAM record: " + cramRecord.toString()); log.error("Offensive SAM record: " + samRecord.getSAMString()); throw e; } }
/** * A wrapper method to provide better diagnostics for ArrayIndexOutOfBoundsException. * * @param cramRecord CRAM record * @param samRecord SAM record * @return a list of read features created for the given {@link htsjdk.samtools.SAMRecord} */ private List<ReadFeature> checkedCreateVariations(final CramCompressionRecord cramRecord, final SAMRecord samRecord) { try { return createVariations(cramRecord, samRecord); } catch (final ArrayIndexOutOfBoundsException e) { log.error("Reference bases array length=" + refBases.length); log.error("Offensive CRAM record: " + cramRecord.toString()); log.error("Offensive SAM record: " + samRecord.getSAMString()); throw e; } }
@Test public void canShadeBaseQuality() throws InvalidGenomicCoordsException, IOException, InvalidColourException { GenomicCoords gc= new GenomicCoords("chr7:1-80", 80, null, null); SAMRecord rec= new SAMRecord(null); rec.setAlignmentStart(1); rec.setCigarString("2M3D8M"); rec.setMappingQuality(30); rec.setReadBases("AAAAATTTTT".getBytes()); rec.setBaseQualities("!!!!!IIIII".getBytes()); System.err.println(rec.getSAMString()); TextRead tr= new TextRead(rec, gc, false); System.err.println(Splitter.on("m").omitEmptyStrings().splitToList(tr.getPrintableTextRead(false, false, false))); }