Removing unused methods in QualityUtils; ReferenceContext now converting all bases to upper case, but can be disabled with static boolean

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3399 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
depristo 2010-05-20 12:38:06 +00:00
parent 5abac5c057
commit 6ce3835622
6 changed files with 16 additions and 79 deletions

View File

@ -28,6 +28,7 @@ package org.broadinstitute.sting.gatk.contexts;
import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.utils.BaseUtils;
import net.sf.samtools.util.StringUtil;
/**
* The section of the reference that overlaps with the given
@ -38,6 +39,8 @@ import org.broadinstitute.sting.utils.BaseUtils;
*/
public class ReferenceContext {
final public static boolean UPPERCASE_REFERENCE = true;
/**
* The locus.
*/
@ -64,7 +67,7 @@ public class ReferenceContext {
* @param base reference base at that locus.
*/
public ReferenceContext( GenomeLoc locus, byte base ) {
this( locus, locus, new byte[] { base } );
this( locus, locus, new byte[] { UPPERCASE_REFERENCE ? StringUtil.toUpperCase(base) : base } );
}
// todo -- this really should take the referenceview as an option and only grab the bases if necessary
@ -75,6 +78,8 @@ public class ReferenceContext {
this.locus = locus;
this.window = window;
this.bases = bases;
if (UPPERCASE_REFERENCE) StringUtil.toUpperCase(bases);
}
/**

View File

@ -34,6 +34,7 @@ import java.util.*;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.SAMReadGroupRecord;
import net.sf.samtools.SAMUtils;
/**
* Created by IntelliJ IDEA.
@ -428,7 +429,9 @@ public class RecalDataManager {
if( attr != null ) {
byte[] colorSpaceQuals;
if( attr instanceof String ) {
colorSpaceQuals = QualityUtils.fastqToPhred((String)attr);
String x = (String)attr;
colorSpaceQuals = x.getBytes();
SAMUtils.fastqToPhred(colorSpaceQuals);
} else {
throw new StingException(String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_QUAL_ATTRIBUTE_TAG, read.getReadName()));
}

View File

@ -34,11 +34,7 @@ import java.util.Random;
import java.util.ResourceBundle;
import java.util.regex.Pattern;
import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMFileWriter;
import net.sf.samtools.SAMProgramRecord;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.SAMTag;
import net.sf.samtools.*;
import net.sf.samtools.util.SequenceUtil;
import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrderedDataSource;
@ -57,6 +53,7 @@ import org.broadinstitute.sting.utils.QualityUtils;
import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.utils.text.TextFormattingUtils;
import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.utils.BaseUtils;
import org.broadinstitute.sting.utils.text.XReadLines;
import org.broadinstitute.sting.commandline.Argument;
import org.broadinstitute.sting.commandline.ArgumentCollection;
@ -359,7 +356,7 @@ public class TableRecalibrationWalker extends ReadWalker<SAMRecord, SAMFileWrite
read.setBaseQualities( recalQuals ); // Overwrite old qualities with new recalibrated qualities
if ( read.getAttribute(RecalDataManager.ORIGINAL_QUAL_ATTRIBUTE_TAG) == null ) { // Save the old qualities if the tag isn't already taken in the read
read.setAttribute(RecalDataManager.ORIGINAL_QUAL_ATTRIBUTE_TAG, QualityUtils.phredToFastq(originalQuals));
read.setAttribute(RecalDataManager.ORIGINAL_QUAL_ATTRIBUTE_TAG, SAMUtils.phredToFastq(originalQuals));
}
if (read.getAttribute(SAMTag.UQ.name()) != null) {

View File

@ -64,7 +64,7 @@ public class BaseUtils {
return t;
}
public static boolean isTransition( byte base1, byte base2 ) {
public static boolean isTransition( byte base1, byte base2 ) {
int b1 = simpleBaseToBaseIndex(base1);
int b2 = simpleBaseToBaseIndex(base2);
return b1 == 0 && b2 == 2 || b1 == 2 && b2 == 0 ||
@ -144,6 +144,7 @@ public class BaseUtils {
}
return bases;
}
/**
* Converts a simple base to a base index
*

View File

@ -217,73 +217,4 @@ public class QualityUtils {
static public byte[] reverseQualityArray( byte[] quals ) {
return BaseUtils.reverse(quals); // no sense in duplicating functionality
}
// TODO --
// TODO --
// TODO -- stolen from SAMUtils in picard -- remove when public access is granted
// TODO --
// TODO --
/**
* Convert an array of bytes, in which each byte is a binary phred quality score, to
* printable ASCII representation of the quality scores, ala FASTQ format.
* @param buffer Array of bytes in which each byte is a binar phred score.
* @param offset Where in buffer to start conversion.
* @param length How many bytes of buffer to convert.
* @return String with ASCII representation of those quality scores.
*/
public static String phredToFastq(final byte[] buffer, final int offset, final int length) {
final char[] chars = new char[length];
for (int i = 0; i < length; i++) {
chars[i] = phredToFastq(buffer[offset+i] & 0xFF);
}
return new String(chars);
}
/** convenience -- should be pushed back into Picard */
public static String phredToFastq(final byte[] buffer) {
return phredToFastq(buffer, 0, buffer.length);
}
/**
* Convert a single binary phred score to printable ASCII representation, ala FASTQ format.
* @param phredScore binary phred score.
* @return Printable ASCII representation of phred score.
*/
public static char phredToFastq(final int phredScore) {
if (phredScore < 0 || phredScore > MAX_QUAL_SCORE) {
throw new IllegalArgumentException("Cannot encode phred score: " + phredScore);
}
return (char) (33 + phredScore);
}
/**
* Convert a string with phred scores in printable ASCII FASTQ format to an array
* of binary phred scores.
* @param fastq Phred scores in FASTQ printable ASCII format.
* @return byte array of binary phred scores in which each byte corresponds to a character in the input string.
*/
public static byte[] fastqToPhred(final String fastq) {
if (fastq == null) {
return null;
}
final int length = fastq.length();
final byte[] scores = new byte[length];
for (int i = 0; i < length; i++) {
scores[i] = (byte) fastqToPhred(fastq.charAt(i));
}
return scores;
}
/**
* Convert a single printable ASCII FASTQ format phred score to binary phred score.
* @param ch Printable ASCII FASTQ format phred score.
* @return Binary phred score.
*/
public static int fastqToPhred(final char ch) {
if (ch < 33 || ch > 126) {
throw new IllegalArgumentException("Invalid fastq character: " + ch);
}
return (ch - 33);
}
}

View File

@ -104,7 +104,7 @@ public class LocusReferenceViewUnitTest extends ReferenceViewTemplate {
GenomeLoc locus = shardIterator.next();
ReferenceSequence expectedAsSeq = sequenceFile.getSubsequenceAt(locus.getContig(), locus.getStart(), locus.getStop());
char expected = StringUtil.bytesToString(expectedAsSeq.getBases()).charAt(0);
char expected = Character.toUpperCase(StringUtil.bytesToString(expectedAsSeq.getBases()).charAt(0));
char actual = view.getReferenceContext(locus).getBaseAsChar();
Assert.assertEquals(String.format("Value of base at position %s in shard %s does not match expected", locus.toString(), shard.getGenomeLocs()),