Permalink
Browse files

optimise readVCFRecord()

  • Loading branch information...
1 parent fbfc668 commit dc555fd8ee3c6f6147740a45985288058843e226 tcarver committed Jan 6, 2012
Showing with 13 additions and 5 deletions.
  1. +13 −5 uk/ac/sanger/artemis/components/variant/BCFReader.java
@@ -241,15 +241,21 @@ private VCFRecord readVCFRecord() throws IOException
if(formatPattern.matcher(bcfRecord.getFormat()).matches())
{
- int n_alleles = bcfRecord.getAlt().getNumAlleles();
+ int n_alleles;
if(bcfRecord.getAlt().toString().equals(":")) // non-variant
{
n_alleles = 1;
bcfRecord.setAlt(".");
}
+ else
+ n_alleles = bcfRecord.getAlt().getNumAlleles();
int nc = (int) (n_alleles * ((float)(((float)n_alleles+1.f)/2.f)));
- String fmts[] = VCFRecord.COLON_PATTERN.split( bcfRecord.getFormat() );
+ //String fmts[] = VCFRecord.COLON_PATTERN.split( bcfRecord.getFormat() );
+
+ final int nfmt = VCFRecord.countOccurrences(bcfRecord.getFormat(), ':')+1;
+ final String fmts[] = VCFRecord.split(bcfRecord.getFormat() , ":", nfmt);
+
bcfRecord.setGenoTypeData( new String[nsamples][fmts.length] );
for(int i=0; i<fmts.length; i++)
@@ -291,9 +297,9 @@ else if(fmts[i].equals("DP")||fmts[i].equals("SP")||fmts[i].equals("GQ"))
* @param b
* @return
*/
- private void getParts(byte[] b, VCFRecord bcfRecord)
+ private void getParts(final byte[] b, final VCFRecord bcfRecord)
{
- StringBuffer buff = new StringBuffer();
+ final StringBuilder buff = new StringBuilder();
for(int i=0; i<b.length; i++)
{
if(i == 0 && b[i] == 0)
@@ -309,6 +315,8 @@ else if(b[i] == 0)
int ind = 0;
int lastInd = 0;
int i = 0;
+ final int len = buff.length();
+
while((ind = buff.indexOf(" ", ind)) > -1)
{
switch( i )
@@ -323,7 +331,7 @@ else if(b[i] == 0)
}
ind++;
- if(ind < buff.length() && buff.charAt(ind) == ' ')
+ if(ind < len && buff.charAt(ind) == ' ')
ind++;
lastInd = ind;
i++;

0 comments on commit dc555fd

Please sign in to comment.