-Fixed VCF header line bug

-Added useful trim() method for Strings for characters other than whitespace


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2538 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2010-01-07 17:51:41 +00:00
parent b643a513bb
commit 9a658e6b18
5 changed files with 30 additions and 8 deletions

View File

@ -429,6 +429,22 @@ public class Utils {
return count;
}
// trim a string for the given character (i.e. not just whitespace)
public static String trim(String str, char ch) {
char[] array = str.toCharArray();
int start = 0;
while ( start < array.length && array[start] == ch )
start++;
int end = array.length - 1;
while ( end > start && array[end] == ch )
end--;
return str.substring(start, end+1);
}
public static byte listMaxByte(List<Byte> quals) {
if (quals.size() == 0) return 0;
byte m = quals.get(0);

View File

@ -1,5 +1,7 @@
package org.broadinstitute.sting.utils.genotype.vcf;
import org.broadinstitute.sting.utils.Utils;
/**
* @author ebanks
@ -38,10 +40,10 @@ public class VCFFilterHeaderLine extends VCFHeaderLine {
throw new IllegalArgumentException("There are too few values in the VCF FILTER header line: " + line);
mName = pieces[0];
mDescription = pieces[1];
mDescription = Utils.trim(pieces[1], '"');
// just in case there were some commas in the description
for (int i = 1; i < pieces.length; i++)
mDescription += "," + pieces[i];
mDescription += "," + Utils.trim(pieces[i], '"');
}
protected String makeStringRep() {

View File

@ -1,5 +1,7 @@
package org.broadinstitute.sting.utils.genotype.vcf;
import org.broadinstitute.sting.utils.Utils;
/**
* @author ebanks
@ -51,10 +53,10 @@ public class VCFFormatHeaderLine extends VCFHeaderLine {
mName = pieces[0];
mCount = Integer.valueOf(pieces[1]);
mType = INFO_TYPE.valueOf(pieces[2]);
mDescription = pieces[3];
mDescription = Utils.trim(pieces[3], '"');
// just in case there were some commas in the description
for (int i = 4; i < pieces.length; i++)
mDescription += "," + pieces[i];
mDescription += "," + Utils.trim(pieces[i], '"');
}
protected String makeStringRep() {

View File

@ -1,5 +1,7 @@
package org.broadinstitute.sting.utils.genotype.vcf;
import org.broadinstitute.sting.utils.Utils;
/**
* @author ebanks
@ -51,10 +53,10 @@ public class VCFInfoHeaderLine extends VCFHeaderLine {
mName = pieces[0];
mCount = Integer.valueOf(pieces[1]);
mType = INFO_TYPE.valueOf(pieces[2]);
mDescription = pieces[3];
mDescription = Utils.trim(pieces[3], '"');
// just in case there were some commas in the description
for (int i = 4; i < pieces.length; i++)
mDescription += "," + pieces[i];
mDescription += "," + Utils.trim(pieces[i], '"');
}
protected String makeStringRep() {

View File

@ -172,9 +172,9 @@ public class VCFReader implements Iterator<VCFRecord>, Iterable<VCFRecord> {
if ( str.startsWith("##INFO=") )
metaData.add(new VCFInfoHeaderLine(str.substring(7)));
else if ( str.startsWith("##FILTER=") )
metaData.add(new VCFFilterHeaderLine(str.substring(7)));
metaData.add(new VCFFilterHeaderLine(str.substring(9)));
else if ( str.startsWith("##FORMAT=") )
metaData.add(new VCFFormatHeaderLine(str.substring(7)));
metaData.add(new VCFFormatHeaderLine(str.substring(9)));
else {
int equals = str.indexOf("=");
if ( equals != -1 )