Better accessors for dealing with second base prob pileups

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@785 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
depristo 2009-05-21 22:25:16 +00:00
parent d261459c48
commit dc17a5661d
4 changed files with 45 additions and 14 deletions

View File

@ -8,7 +8,12 @@ package org.broadinstitute.sting.utils;
public class BaseUtils { public class BaseUtils {
/** Private constructor. No instantiating this class! */ /** Private constructor. No instantiating this class! */
private BaseUtils() {} private BaseUtils() {}
static public boolean basesAreEqual(byte base1, byte base2) {
return simpleBaseToBaseIndex((char)base1) == simpleBaseToBaseIndex((char)base2);
}
/** /**
* Converts a simple base to a base index * Converts a simple base to a base index
* *

View File

@ -68,15 +68,23 @@ abstract public class BasicPileup implements Pileup {
return quals; return quals;
} }
public static String qualPileupAsString( List<SAMRecord> reads, List<Integer> offsets ) { public static String mappingQualPileupAsString( List<SAMRecord> reads) {
StringBuilder quals = new StringBuilder(); return quals2String(mappingQualPileup(reads));
for ( int qual : qualPileup(reads, offsets)) { }
public static String quals2String( List<Byte> quals ) {
StringBuilder qualStr = new StringBuilder();
for ( int qual : quals ) {
qual = Math.min(qual, 63); // todo: fixme, this isn't a good idea qual = Math.min(qual, 63); // todo: fixme, this isn't a good idea
char qualChar = (char) (33 + qual); // todo: warning, this is illegal for qual > 63 char qualChar = (char) (33 + qual); // todo: warning, this is illegal for qual > 63
quals.append(qualChar); qualStr.append(qualChar);
} }
return quals.toString(); return qualStr.toString();
}
public static String qualPileupAsString( List<SAMRecord> reads, List<Integer> offsets ) {
return quals2String(qualPileup(reads, offsets));
} }
public static ArrayList<Byte> secondaryBasePileup( List<SAMRecord> reads, List<Integer> offsets ) { public static ArrayList<Byte> secondaryBasePileup( List<SAMRecord> reads, List<Integer> offsets ) {
@ -153,17 +161,18 @@ abstract public class BasicPileup implements Pileup {
return (hasAtLeastOneSQField ? quals2 : null); return (hasAtLeastOneSQField ? quals2 : null);
} }
public static String secondaryQualPileupAsString( List<SAMRecord> reads, List<Integer> offsets ) { public static String secondaryQualPileupAsString( List<SAMRecord> reads, List<Integer> offsets) {
StringBuilder quals2 = new StringBuilder(); StringBuilder quals2 = new StringBuilder();
ArrayList<Byte> sqquals = secondaryQualPileup(reads, offsets); ArrayList<Byte> sqquals = secondaryQualPileup(reads, offsets);
if (sqquals == null) { return null; } if (sqquals == null) {
return null;
for (byte qual2 : secondaryQualPileup(reads, offsets)) { } else {
quals2.append(qual2); for (byte qual2 : secondaryQualPileup(reads, offsets)) {
quals2.append(qual2);
}
return quals2.toString();
} }
return quals2.toString();
} }
public static double[][] probDistPileup( List<SAMRecord> reads, List<Integer> offsets ) { public static double[][] probDistPileup( List<SAMRecord> reads, List<Integer> offsets ) {

View File

@ -23,6 +23,10 @@ public class QualityUtils {
return 1.0 - qualToErrorProb(qual); return 1.0 - qualToErrorProb(qual);
} }
static public double qualToProb(int qual) {
return 1.0 - Math.pow(10.0, ((double) qual)/-10.0);
}
/** /**
* Convert a quality score to a probability of error. This is the Phred-style * Convert a quality score to a probability of error. This is the Phred-style
* conversion, *not* the Illumina-style conversion (though asymptotically, they're the same). * conversion, *not* the Illumina-style conversion (though asymptotically, they're the same).

View File

@ -62,6 +62,10 @@ public class ReadBackedPileup extends BasicPileup {
return Utils.join(",", mappingQualPileup(reads)); return Utils.join(",", mappingQualPileup(reads));
} }
public String getMappingQuals() {
return mappingQualPileupAsString(reads);
}
public String getSecondaryBasePileup() { public String getSecondaryBasePileup() {
return secondaryBasePileupAsString(reads, offsets); return secondaryBasePileupAsString(reads, offsets);
} }
@ -76,6 +80,15 @@ public class ReadBackedPileup extends BasicPileup {
public String getPileupString() public String getPileupString()
{ {
return String.format("%s: %s %s %s", getLocation(), getRef(), getBases(), getQuals()); // In the pileup format, each line represents a genomic position, consisting of chromosome name,
// coordinate, reference base, read bases, read qualities and alignment mapping qualities.
//return String.format("%s %s %s %s", getLocation(), getRef(), getBases(), getQuals());
return String.format("%s %s %s %s %s %s",
getLocation().getContig(), getLocation().getStart(), // chromosome name and coordinate
getRef(), // reference base
getBases(),
getQuals(),
getMappingQuals());
} }
} }