diff --git a/uk/ac/sanger/artemis/components/variant/BCFReader.java b/uk/ac/sanger/artemis/components/variant/BCFReader.java index 5a770b76720f40e7ea3646e7290e4706866664a4..2f5f2e3ed6605e8659fa13a141c0939f3ebc514c 100644 --- a/uk/ac/sanger/artemis/components/variant/BCFReader.java +++ b/uk/ac/sanger/artemis/components/variant/BCFReader.java @@ -26,6 +26,7 @@ package uk.ac.sanger.artemis.components.variant; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.Writer; import java.util.List; import java.util.Vector; import java.util.regex.Pattern; @@ -66,21 +67,21 @@ class BCFReader extends AbstractVCFReader is.seek(off); } - protected VCFRecord next(int bid, int beg, int end) throws IOException + protected VCFRecord next(int beg, int end) throws IOException { try { VCFRecord bcfRecord = readVCFRecord(); - if(bcfRecord.pos >= beg && bcfRecord.pos <= end) + if(bcfRecord.getPos() >= beg && bcfRecord.getPos() <= end) return bcfRecord; - else if(bcfRecord.pos < beg) + else if(bcfRecord.getPos() < beg) { - while( (bcfRecord = readVCFRecord()).pos <= beg ) + while( (bcfRecord = readVCFRecord()).getPos() <= beg ) { - if(bcfRecord.pos >= beg && bcfRecord.pos <= end) + if(bcfRecord.getPos() >= beg && bcfRecord.getPos() <= end) return bcfRecord; } - if(bcfRecord.pos >= beg && bcfRecord.pos <= end) + if(bcfRecord.getPos() >= beg && bcfRecord.getPos() <= end) return bcfRecord; } } @@ -173,9 +174,9 @@ class BCFReader extends AbstractVCFReader private VCFRecord readVCFRecord() throws IOException { VCFRecord bcfRecord = new VCFRecord(); - bcfRecord.chrom = seqNames[readInt(is)]; - bcfRecord.pos = readInt(is)+1; - bcfRecord.quality = readFloat(is); + bcfRecord.setChrom( seqNames[readInt(is)] ); + bcfRecord.setPos ( readInt(is)+1 ); + bcfRecord.setQuality( readFloat(is) ); int slen = readInt(is); byte[] str = new byte[slen]; @@ -183,16 +184,16 @@ class BCFReader extends AbstractVCFReader getParts(str, bcfRecord); - if(formatPattern.matcher(bcfRecord.format).matches()) + if(formatPattern.matcher(bcfRecord.getFormat()).matches()) { int n_alleles = bcfRecord.getNumAlleles(); int nc = (int) (n_alleles * ((float)(((float)n_alleles+1.f)/2.f))); - if(bcfRecord.alt.equals(".")) + if(bcfRecord.getAlt().equals(".")) nc = 1; - String fmts[] = bcfRecord.format.split(":"); - bcfRecord.data = new String[nsamples][fmts.length]; + String fmts[] = bcfRecord.getFormat().split(":"); + bcfRecord.setData( new String[nsamples][fmts.length] ); for(int j=0; j<nsamples; j++) { @@ -212,7 +213,7 @@ class BCFReader extends AbstractVCFReader else value = ""; - bcfRecord.data[j][k] = value; + bcfRecord.getData()[j][k] = value; } } @@ -255,12 +256,12 @@ class BCFReader extends AbstractVCFReader String parts[] = buff.toString().replace(" ", " ").split(" "); - bcfRecord.ID = parts[0]; - bcfRecord.ref = parts[1]; - bcfRecord.alt = parts[2]; - bcfRecord.filter = parts[3]; - bcfRecord.info = parts[4]; - bcfRecord.format = parts[5]; + bcfRecord.setID( parts[0] ); + bcfRecord.setRef( parts[1] ); + bcfRecord.setAlt( parts[2] ); + bcfRecord.setFilter( parts[3] ); + bcfRecord.setInfo( parts[4] ); + bcfRecord.setFormat( parts[5] ); } /** @@ -325,6 +326,20 @@ class BCFReader extends AbstractVCFReader return (int)(b & 0xFF); } + protected static void writeVCF(Writer writer, String vcfFileName) throws IOException + { + BCFReader reader = new BCFReader(new File(vcfFileName)); + writer.write( reader.headerToString()+"\n" ); + + int sbeg = 0; + int send = Integer.MAX_VALUE; + VCFRecord record; + + while( (record = reader.next(sbeg, send)) != null) + writer.write(record.toString()+"\n"); + writer.close(); + } + protected List<BCFIndex> loadIndex() throws IOException { BlockCompressedInputStream is = new BlockCompressedInputStream(indexFileStream); @@ -402,7 +417,7 @@ class BCFReader extends AbstractVCFReader System.out.println(reader.headerToString()); VCFRecord bcfRecord; - while( (bcfRecord = reader.next(bid, sbeg, send)) != null ) + while( (bcfRecord = reader.next(sbeg, send)) != null ) System.out.println(bcfRecord.toString()); reader.close(); diff --git a/uk/ac/sanger/artemis/components/variant/VCFview.java b/uk/ac/sanger/artemis/components/variant/VCFview.java index a9970bf9aa46dcefd55a4445d4a42b8d8be711cd..78ea19e7f437e3776dc38e45de03f7519e946582 100644 --- a/uk/ac/sanger/artemis/components/variant/VCFview.java +++ b/uk/ac/sanger/artemis/components/variant/VCFview.java @@ -533,7 +533,7 @@ public class VCFview extends JPanel { VCFview.this.setCursor(new Cursor(Cursor.WAIT_CURSOR)); IOUtils.export(entryGroup, vcfFiles, VCFview.this); - VCFview.this.setCursor(new Cursor(Cursor.WAIT_CURSOR)); + VCFview.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }); popup.add(exportVCF); @@ -776,8 +776,11 @@ public class VCFview extends JPanel bcfReader.seek(off); VCFRecord bcfRecord; - while( (bcfRecord = bcfReader.next(bid, sbeg, send)) != null ) - drawVariantCall(g, bcfRecord, start, i, pixPerBase, features); + while( (bcfRecord = bcfReader.next(sbeg, send)) != null ) + { + if(bcfRecord.getChrom().equals(chr)) + drawVariantCall(g, bcfRecord, start, i, pixPerBase, features); + } } catch (IOException e) { @@ -991,30 +994,30 @@ public class VCFview extends JPanel //String parts[] = line.split("\\t"); //String parts[] = tabPattern.split(line, 0); - int basePosition = record.pos + getSequenceOffset(record.chrom); + int basePosition = record.getPos() + getSequenceOffset(record.getChrom()); - if( !showVariant(record.ref, record.alt, features, basePosition, record.quality) ) + if( !showVariant(record.getRef(), record.getAlt(), features, basePosition, record.getQuality()) ) return; int pos[] = getScreenPosition(basePosition, pixPerBase, start, index); - if(isDeletion(record.ref, record.alt)) + if(isDeletion(record.getRef(), record.getAlt())) g.setColor(Color.gray); - else if(isInsertion(record.ref, record.alt)) + else if(isInsertion(record.getRef(), record.getAlt())) g.setColor(Color.yellow); - else if(record.alt.equals("C") && record.ref.length() == 1) + else if(record.getAlt().equals("C") && record.getRef().length() == 1) g.setColor(Color.red); - else if(record.alt.equals("A") && record.ref.length() == 1) + else if(record.getAlt().equals("A") && record.getRef().length() == 1) g.setColor(Color.green); - else if(record.alt.equals("G") && record.ref.length() == 1) + else if(record.getAlt().equals("G") && record.getRef().length() == 1) g.setColor(Color.blue); - else if(record.alt.equals("T") && record.ref.length() == 1) + else if(record.getAlt().equals("T") && record.getRef().length() == 1) g.setColor(Color.black); - else if(record.alt.equals(".") && record.ref.length() == 1) + else if(record.getAlt().equals(".") && record.getRef().length() == 1) g.setColor(Color.magenta); else { - Matcher m = multiAllelePattern.matcher(record.alt); + Matcher m = multiAllelePattern.matcher(record.getAlt()); if(m.matches()) { g.setColor(Color.orange); @@ -1191,8 +1194,11 @@ public class VCFview extends JPanel { bcfReader.seek(off); VCFRecord bcfRecord; - while( (bcfRecord = bcfReader.next(bid, sbeg, send)) != null ) - isMouseOver(mousePoint, bcfRecord, features, i, start, pixPerBase); + while( (bcfRecord = bcfReader.next(sbeg, send)) != null ) + { + if(bcfRecord.getChrom().equals(chr)) + isMouseOver(mousePoint, bcfRecord, features, i, start, pixPerBase); + } } catch (IOException e) { @@ -1228,9 +1234,9 @@ public class VCFview extends JPanel int i, int start, float pixPerBase) { - int basePosition = record.pos + getSequenceOffset(record.chrom); + int basePosition = record.getPos() + getSequenceOffset(record.getChrom()); - if( !showVariant(record.ref, record.alt, features, basePosition, record.quality) ) + if( !showVariant(record.getRef(), record.getAlt(), features, basePosition, record.getQuality()) ) return; int pos[] = getScreenPosition(basePosition, pixPerBase, start, i);