Skip to content
Snippets Groups Projects
Commit a9f3dd26 authored by tcarver's avatar tcarver
Browse files

speed up getFormatValues()

parent 08a70498
No related branches found
No related tags found
No related merge requests found
...@@ -46,13 +46,14 @@ public class VCFRecord ...@@ -46,13 +46,14 @@ public class VCFRecord
private String info; private String info;
private String infos[]; private String infos[];
private String format; private String format;
private String data[][]; private String genotypeData[][];
private short synFlag = -1; private short synFlag = -1;
private boolean markAsNewStop = false; private boolean markAsNewStop = false;
protected static Pattern MULTI_ALLELE_PATTERN = Pattern.compile("^[AGCTagct]+,[AGCTacgt,]+$"); protected static Pattern MULTI_ALLELE_PATTERN = Pattern.compile("^[AGCTagct]+,[AGCTacgt,]+$");
protected static Pattern COLON_PATTERN = Pattern.compile(":"); protected static Pattern COLON_PATTERN = Pattern.compile(":");
protected static Pattern SEMICOLON_PATTERN = Pattern.compile(";"); protected static Pattern SEMICOLON_PATTERN = Pattern.compile(";");
protected static Pattern TAB_PATTERN = Pattern.compile("\\t");
/** /**
* Return the string representation of the VCF record as a * Return the string representation of the VCF record as a
...@@ -99,11 +100,11 @@ public class VCFRecord ...@@ -99,11 +100,11 @@ public class VCFRecord
int nsamples = parts.length-9; int nsamples = parts.length-9;
int nfmt = rec.format.split(":").length; int nfmt = rec.format.split(":").length;
rec.data = new String[nsamples][nfmt]; rec.genotypeData = new String[nsamples][nfmt];
for(int i=0; i<nsamples; i++) for(int i=0; i<nsamples; i++)
{ {
String data[] = COLON_PATTERN.split(parts[9+i]); final String data[] = COLON_PATTERN.split(parts[9+i]);
rec.data[i] = data; rec.genotypeData[i] = data;
} }
} }
return rec; return rec;
...@@ -141,7 +142,7 @@ public class VCFRecord ...@@ -141,7 +142,7 @@ public class VCFRecord
protected String getFormatValueForSample(String key, int sampleIndex) protected String getFormatValueForSample(String key, int sampleIndex)
{ {
String fmtStr[] = getFormatValues(key); final String fmtStr[] = getFormatValues(key);
if(fmtStr == null) if(fmtStr == null)
return null; return null;
return fmtStr[sampleIndex]; return fmtStr[sampleIndex];
...@@ -157,17 +158,16 @@ public class VCFRecord ...@@ -157,17 +158,16 @@ public class VCFRecord
if(getFormat() == null) if(getFormat() == null)
return null; return null;
final String fmts[] = COLON_PATTERN.split(getFormat()); final String fmts[] = COLON_PATTERN.split(getFormat());
for(int i=0; i<fmts.length; i++) for(int i=0; i<fmts.length; i++)
{ {
if(fmts[i].equals(key)) if(fmts[i].equals(key))
{ {
String samplesData[] = getSampleDataString().split("\\t"); final String keyData[] = new String[genotypeData.length];
String keyData[] = new String[samplesData.length]; for(int j=0; j<genotypeData.length; j++)
for(int j=0; j<samplesData.length; j++)
{ {
String vals[] = COLON_PATTERN.split(samplesData[j]); if(genotypeData[j].length == fmts.length)
if(vals.length == fmts.length) keyData[j] = genotypeData[j][i];
keyData[j] = vals[i];
} }
return keyData; return keyData;
} }
...@@ -181,18 +181,18 @@ public class VCFRecord ...@@ -181,18 +181,18 @@ public class VCFRecord
*/ */
protected String getSampleDataString() protected String getSampleDataString()
{ {
if(data == null) if(genotypeData == null)
return ""; return "";
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
for(int i=0; i<data.length; i++) // loop over samples for(int i=0; i<genotypeData.length; i++) // loop over samples
{ {
for(int j=0; j<data[i].length; j++) // loop over values for(int j=0; j<genotypeData[i].length; j++) // loop over values
{ {
buff.append(data[i][j]); buff.append(genotypeData[i][j]);
if(j<data[i].length-1) if(j<genotypeData[i].length-1)
buff.append(":"); buff.append(":");
} }
if(i<data.length-1) if(i<genotypeData.length-1)
buff.append("\t"); buff.append("\t");
} }
return buff.toString(); return buff.toString();
...@@ -356,17 +356,17 @@ public class VCFRecord ...@@ -356,17 +356,17 @@ public class VCFRecord
/** /**
* @return the data * @return the data
*/ */
protected String[][] getData() protected String[][] getGenoTypeData()
{ {
return data; return genotypeData;
} }
/** /**
* @param data the data to set * @param data the data to set
*/ */
protected void setData(String[][] data) protected void setGenoTypeData(String[][] data)
{ {
this.data = data; this.genotypeData = data;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment