Java Code Examples for htsjdk.samtools.SAMRecord#getBaseQualityString()
The following examples show how to use
htsjdk.samtools.SAMRecord#getBaseQualityString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SAMRecords.java From hmftools with GNU General Public License v3.0 | 5 votes |
public static int getAvgBaseQuality(@NotNull final SAMRecord record, int readPosition, int length) { assert (readPosition > 0); int score = 0; final String baseQualities = record.getBaseQualityString(); for (int index = readPosition - 1; index < Math.min(readPosition - 1 + length, baseQualities.length()); index++) { int baseScore = getBaseQuality(baseQualities.charAt(index)); score += baseScore; } return score / length; }
Example 2
Source File: SAMRecords.java From hmftools with GNU General Public License v3.0 | 5 votes |
public static int getMinBaseQuality(@NotNull final SAMRecord record, int readPosition, int length) { assert (readPosition > 0); int score = Integer.MAX_VALUE; final String baseQualities = record.getBaseQualityString(); for (int index = readPosition - 1; index < Math.min(readPosition - 1 + length, baseQualities.length()); index++) { int baseScore = getBaseQuality(baseQualities.charAt(index)); score = Math.min(baseScore, score); } return score == Integer.MAX_VALUE ? 0 : score; }
Example 3
Source File: SamRecordComparision.java From cramtools with Apache License 2.0 | 5 votes |
public static Object getValue(SAMRecord record, FIELD_TYPE field, String tagId) { if (field == null) throw new IllegalArgumentException("Record field is null."); switch (field) { case QNAME: return record.getReadName(); case FLAG: return Integer.toString(record.getFlags()); case RNAME: return record.getReferenceName(); case POS: return Integer.toString(record.getAlignmentStart()); case MAPQ: return Integer.toString(record.getMappingQuality()); case CIGAR: return record.getCigarString(); case RNEXT: return record.getMateReferenceName(); case PNEXT: return Integer.toString(record.getMateAlignmentStart()); case TLEN: return Integer.toString(record.getInferredInsertSize()); case SEQ: return record.getReadString(); case QUAL: return record.getBaseQualityString(); case TAG: if (tagId == null) throw new IllegalArgumentException("Tag mismatch reqiues tag id. "); return record.getAttribute(tagId); default: throw new IllegalArgumentException("Unknown record field: " + field.name()); } }
Example 4
Source File: SAMRecordField.java From cramtools with Apache License 2.0 | 5 votes |
public Object getValue(SAMRecord record) { switch (type) { case QNAME: return record.getReadName(); case FLAG: return Integer.toString(record.getFlags()); case RNAME: return record.getReferenceName(); case POS: return Integer.toString(record.getAlignmentStart()); case MAPQ: return Integer.toString(record.getMappingQuality()); case CIGAR: return record.getCigarString(); case RNEXT: return record.getMateReferenceName(); case PNEXT: return Integer.toString(record.getMateAlignmentStart()); case TLEN: return Integer.toString(record.getInferredInsertSize()); case SEQ: return record.getReadString(); case QUAL: return record.getBaseQualityString(); case TAG: if (tagId == null) throw new IllegalArgumentException("Tag mismatch reqiues tag id. "); return record.getAttribute(tagId); default: throw new IllegalArgumentException("Unknown record field: " + type.name()); } }
Example 5
Source File: SamToFastq.java From picard with MIT License | 4 votes |
private void writeRecord(final SAMRecord read, final Integer mateNumber, final FastqWriter writer, final int basesToTrim, final Integer maxBasesToWrite) { final String seqHeader = mateNumber == null ? read.getReadName() : read.getReadName() + "/" + mateNumber; String readString = read.getReadString(); String baseQualities = read.getBaseQualityString(); // If we're clipping, do the right thing to the bases or qualities if (CLIPPING_ATTRIBUTE != null) { Integer clipPoint = (Integer) read.getAttribute(CLIPPING_ATTRIBUTE); if (clipPoint != null && clipPoint < CLIPPING_MIN_LENGTH) { clipPoint = Math.min(readString.length(), CLIPPING_MIN_LENGTH); } if (clipPoint != null) { if (CLIPPING_ACTION.equalsIgnoreCase(CLIP_TRIM)) { readString = clip(readString, clipPoint, null, !read.getReadNegativeStrandFlag()); baseQualities = clip(baseQualities, clipPoint, null, !read.getReadNegativeStrandFlag()); } else if (CLIPPING_ACTION.equalsIgnoreCase(CLIP_TO_N)) { readString = clip(readString, clipPoint, CLIP_TO_N.charAt(0), !read.getReadNegativeStrandFlag()); } else { final char newQual = SAMUtils.phredToFastq(new byte[]{(byte) Integer.parseInt(CLIPPING_ACTION)}).charAt(0); baseQualities = clip(baseQualities, clipPoint, newQual, !read.getReadNegativeStrandFlag()); } } } if (RE_REVERSE && read.getReadNegativeStrandFlag()) { readString = SequenceUtil.reverseComplement(readString); baseQualities = StringUtil.reverseString(baseQualities); } if (basesToTrim > 0) { readString = readString.substring(basesToTrim); baseQualities = baseQualities.substring(basesToTrim); } // Perform quality trimming if desired, making sure to leave at least one base! if (QUALITY != null) { final byte[] quals = SAMUtils.fastqToPhred(baseQualities); final int qualityTrimIndex = Math.max(1, TrimmingUtil.findQualityTrimPoint(quals, QUALITY)); if (qualityTrimIndex < quals.length) { readString = readString.substring(0, qualityTrimIndex); baseQualities = baseQualities.substring(0, qualityTrimIndex); } } if (maxBasesToWrite != null && maxBasesToWrite < readString.length()) { readString = readString.substring(0, maxBasesToWrite); baseQualities = baseQualities.substring(0, maxBasesToWrite); } writer.write(new FastqRecord(seqHeader, readString, "", baseQualities)); }