GLF reader and writer check in.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1202 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
c8fcecbc6f
commit
8ee5c7de8e
|
|
@ -1,6 +1,5 @@
|
|||
package org.broadinstitute.sting.utils.genotype;
|
||||
|
||||
import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
||||
import edu.mit.broad.picard.genotype.geli.GeliFileWriter;
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
|
||||
|
|
@ -35,7 +34,7 @@ import java.io.File;
|
|||
/**
|
||||
* @author aaron
|
||||
* @version 1.0
|
||||
*
|
||||
* <p/>
|
||||
* Class GeliAdapter
|
||||
* Adapts the Geli file writer to the Genotype writer interface
|
||||
*/
|
||||
|
|
@ -47,6 +46,7 @@ public class GeliAdapter implements GenotypeWriter {
|
|||
|
||||
/**
|
||||
* wrap a GeliFileWriter in the Genotype writer interface
|
||||
*
|
||||
* @param writeTo where to write to
|
||||
* @param fileHeader the file header to write out
|
||||
*/
|
||||
|
|
@ -58,19 +58,29 @@ public class GeliAdapter implements GenotypeWriter {
|
|||
/**
|
||||
* add a single point genotype call to the
|
||||
*
|
||||
* @param contigName the name of the contig you're calling in
|
||||
* @param contigLength the contig length
|
||||
* @param position the position on the contig
|
||||
* @param referenceBase the reference base
|
||||
* @param readDepth the read depth at the specified position
|
||||
* @param likelihoods the likelihoods of each of the possible alleles
|
||||
*/
|
||||
@Override
|
||||
public void addGenotypeCall( int position, float rmsMapQuals, char referenceBase, int readDepth, LikelihoodObject likelihoods ) {
|
||||
public void addGenotypeCall(String contigName,
|
||||
int contigLength,
|
||||
int position,
|
||||
float rmsMapQuals,
|
||||
char referenceBase,
|
||||
int readDepth,
|
||||
LikelihoodObject likelihoods) {
|
||||
writer.addGenotypeLikelihoods(likelihoods.convert(writer.getFileHeader(), 1, position, (byte) referenceBase));
|
||||
}
|
||||
|
||||
/**
|
||||
* add a variable length call to the genotyper
|
||||
*
|
||||
* @param contigName the name of the contig you're calling in
|
||||
* @param contigLength the contig length
|
||||
* @param position the position on the genome
|
||||
* @param rmsMapQuals the root mean square of the mapping qualities
|
||||
* @param readDepth the read depth
|
||||
|
|
@ -80,7 +90,7 @@ public class GeliAdapter implements GenotypeWriter {
|
|||
* @param hetLikelihood the heterozygous likelihood
|
||||
*/
|
||||
@Override
|
||||
public void addVariableLengthCall( int position, float rmsMapQuals, int readDepth, char refBase, IndelLikelihood firstHomZyg, IndelLikelihood secondHomZyg, byte hetLikelihood ) {
|
||||
public void addVariableLengthCall(String contigName, int contigLength, int position, float rmsMapQuals, int readDepth, char refBase, IndelLikelihood firstHomZyg, IndelLikelihood secondHomZyg, byte hetLikelihood) {
|
||||
throw new UnsupportedOperationException("Geli format does not support variable length allele calls");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
package org.broadinstitute.sting.utils.genotype;
|
||||
|
||||
import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
||||
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 The Broad Institute
|
||||
*
|
||||
|
|
@ -29,22 +26,26 @@ import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
|||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aaron
|
||||
*
|
||||
* <p/>
|
||||
* Class Genotype
|
||||
*
|
||||
* <p/>
|
||||
* The interface for storing genotype calls.
|
||||
*/
|
||||
public interface GenotypeWriter {
|
||||
/**
|
||||
* add a single point genotype call to the
|
||||
*
|
||||
* @param contigName the name of the contig you're calling in
|
||||
* @param contigLength the contig length
|
||||
* @param position the position on the contig
|
||||
* @param referenceBase the reference base
|
||||
* @param readDepth the read depth at the specified position
|
||||
* @param likelihoods the likelihoods of each of the possible alleles
|
||||
*/
|
||||
public void addGenotypeCall(int position,
|
||||
public void addGenotypeCall(String contigName,
|
||||
int contigLength,
|
||||
int position,
|
||||
float rmsMapQuals,
|
||||
char referenceBase,
|
||||
int readDepth,
|
||||
|
|
@ -52,6 +53,9 @@ public interface GenotypeWriter {
|
|||
|
||||
/**
|
||||
* add a variable length call to the genotyper
|
||||
*
|
||||
* @param contigName the name of the contig you're calling in
|
||||
* @param contigLength the contig length
|
||||
* @param position the position on the genome
|
||||
* @param rmsMapQuals the root mean square of the mapping qualities
|
||||
* @param readDepth the read depth
|
||||
|
|
@ -60,7 +64,9 @@ public interface GenotypeWriter {
|
|||
* @param secondHomZyg the second homozygous indel (if present, null if not)
|
||||
* @param hetLikelihood the heterozygous likelihood
|
||||
*/
|
||||
public void addVariableLengthCall(int position,
|
||||
public void addVariableLengthCall(String contigName,
|
||||
int contigLength,
|
||||
int position,
|
||||
float rmsMapQuals,
|
||||
int readDepth,
|
||||
char refBase,
|
||||
|
|
@ -70,15 +76,14 @@ public interface GenotypeWriter {
|
|||
|
||||
/**
|
||||
* add a no call to the genotype file, if supported.
|
||||
*
|
||||
* @param position
|
||||
* @param readDepth
|
||||
*/
|
||||
public void addNoCall(int position,
|
||||
int readDepth);
|
||||
|
||||
/**
|
||||
* finish writing, closing any open files.
|
||||
*/
|
||||
/** finish writing, closing any open files. */
|
||||
public void close();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package org.broadinstitute.sting.utils.genotype.glf;
|
||||
|
||||
import net.sf.samtools.util.BinaryCodec;
|
||||
import net.sf.samtools.util.BlockCompressedOutputStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sf.samtools.util.BlockCompressedInputStream;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 The Broad Institute
|
||||
*
|
||||
|
|
@ -35,9 +35,7 @@ import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
|||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* an object for reading in GLF files
|
||||
*/
|
||||
/** an object for reading in GLF files */
|
||||
public class GLFReader implements Iterator<GLFRecord> {
|
||||
|
||||
// our next record
|
||||
|
|
@ -58,28 +56,43 @@ public class GLFReader implements Iterator<GLFRecord> {
|
|||
// reference length
|
||||
private int referenceLength;
|
||||
|
||||
/**
|
||||
* create a glf reader
|
||||
*
|
||||
* @param readFrom the file to read from
|
||||
*/
|
||||
GLFReader(File readFrom) {
|
||||
inputBinaryCodec = new BinaryCodec(new DataOutputStream(new BlockCompressedOutputStream(readFrom)));
|
||||
try {
|
||||
inputBinaryCodec = new BinaryCodec(new DataInputStream(new BlockCompressedInputStream(readFrom)));
|
||||
} catch (IOException e) {
|
||||
throw new StingException("Unable to open " + readFrom.getName(), e);
|
||||
}
|
||||
inputBinaryCodec.setInputFileName(readFrom.getName());
|
||||
|
||||
// first verify that it's a valid GLF
|
||||
for (short s : glfMagic) {
|
||||
if (inputBinaryCodec.readUByte() != s) throw new StingException("Verification of GLF format failed: magic string doesn't match)");
|
||||
if (inputBinaryCodec.readUByte() != s)
|
||||
throw new StingException("Verification of GLF format failed: magic string doesn't match)");
|
||||
}
|
||||
|
||||
// get the header string
|
||||
headerStr = inputBinaryCodec.readLengthAndString(false);
|
||||
|
||||
// get the reference name
|
||||
referenceName = inputBinaryCodec.readLengthAndString(true);
|
||||
|
||||
// get the reference length - this may be a problem storing an unsigned int into a signed int. but screw it.
|
||||
referenceLength = (int)inputBinaryCodec.readUInt();
|
||||
|
||||
// get the next record
|
||||
nextRecord = next();
|
||||
if (advanceContig()) {
|
||||
// setup the next record
|
||||
next();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* read in a single point call
|
||||
*
|
||||
* @param refBase the reference base
|
||||
* @param inputBinaryCodec the binary codec
|
||||
*
|
||||
* @return a single point call object
|
||||
*/
|
||||
private SinglePointCall generateSPC(char refBase, BinaryCodec inputBinaryCodec) {
|
||||
int offset = (int) inputBinaryCodec.readUInt();
|
||||
long depth = inputBinaryCodec.readUInt();
|
||||
|
|
@ -93,7 +106,14 @@ public class GLFReader implements Iterator<GLFRecord> {
|
|||
return new SinglePointCall(refBase, offset, readDepth, rmsMapping, lkValues);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* read in a variable length call, and generate a VLC object from the data
|
||||
*
|
||||
* @param refBase the reference base
|
||||
* @param inputBinaryCodec the input codex
|
||||
*
|
||||
* @return a VariableLengthCall object
|
||||
*/
|
||||
private VariableLengthCall generateVLC(char refBase, BinaryCodec inputBinaryCodec) {
|
||||
int offset = (int) inputBinaryCodec.readUInt();
|
||||
int depth = (int) inputBinaryCodec.readUInt();
|
||||
|
|
@ -105,15 +125,18 @@ public class GLFReader implements Iterator<GLFRecord> {
|
|||
short lkHet = inputBinaryCodec.readUByte();
|
||||
int indelLen1 = (int) inputBinaryCodec.readShort();
|
||||
int indelLen2 = (int) inputBinaryCodec.readShort();
|
||||
short[] indelSeq1 = new short[indelLen1];
|
||||
short[] indelSeq2 = new short[indelLen2];
|
||||
for (int x = 0; x < indelLen1; x++) {
|
||||
|
||||
int readCnt = Math.abs(indelLen1);
|
||||
short indelSeq1[] = new short[readCnt];
|
||||
for (int x = 0; x < readCnt; x++) {
|
||||
indelSeq1[x] = inputBinaryCodec.readUByte();
|
||||
}
|
||||
for (int x = 0; x < indelLen2; x++) {
|
||||
readCnt = Math.abs(indelLen2);
|
||||
short indelSeq2[] = new short[readCnt];
|
||||
for (int x = 0; x < readCnt; x++) {
|
||||
indelSeq2[x] = inputBinaryCodec.readUByte();
|
||||
}
|
||||
return new VariableLengthCall(refBase,offset,readDepth,rmsMapping,lkHom1,lkHom2,lkHet,indelSeq1,indelSeq2);
|
||||
return new VariableLengthCall(refBase, offset, readDepth, rmsMapping, lkHom1, lkHom2, lkHet, indelLen1, indelSeq1, indelLen2, indelSeq2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -124,24 +147,69 @@ public class GLFReader implements Iterator<GLFRecord> {
|
|||
@Override
|
||||
public GLFRecord next() {
|
||||
short firstBase = inputBinaryCodec.readUByte();
|
||||
byte recordType = (byte)(firstBase & 0x00f0 >> 4);
|
||||
byte recordType = (byte) ((firstBase & 0x0f0) >> 4);
|
||||
char refBase = (char) (firstBase & 0x000f);
|
||||
|
||||
GLFRecord ret = nextRecord;
|
||||
if (recordType == 1) {
|
||||
nextRecord = generateSPC(refBase, inputBinaryCodec);
|
||||
}
|
||||
else if (recordType == 2) {
|
||||
} else if (recordType == 2) {
|
||||
nextRecord = generateVLC(refBase, inputBinaryCodec);
|
||||
} else if (recordType == 0) {
|
||||
if (advanceContig()) {
|
||||
return next();
|
||||
}
|
||||
else if (recordType == 0){
|
||||
nextRecord = null;
|
||||
} else {
|
||||
throw new StingException("Unkonwn GLF record type (type = " + recordType + ")");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* advance to the next contig
|
||||
*
|
||||
* @return true if we could advance
|
||||
*/
|
||||
private boolean advanceContig() {
|
||||
// try to read the next sequence record
|
||||
try {
|
||||
// get the reference name
|
||||
referenceName = inputBinaryCodec.readLengthAndString(true);
|
||||
|
||||
// get the reference length - this may be a problem storing an unsigned int into a signed int. but screw it.
|
||||
referenceLength = (int) inputBinaryCodec.readUInt();
|
||||
//System.err.println(referenceName.length());
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
// we're out of file space, set the next to null
|
||||
nextRecord = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new StingException("I'm Sorry Dave, I can't let you do that (also GLFReader doesn't support remove()).");
|
||||
throw new StingException("GLFReader doesn't support remove()");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getter methods
|
||||
*/
|
||||
|
||||
public String getReferenceName() {
|
||||
return referenceName;
|
||||
}
|
||||
|
||||
public int getReferenceLength() {
|
||||
return referenceLength;
|
||||
}
|
||||
|
||||
public String getHeaderStr() {
|
||||
return headerStr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ abstract class GLFRecord {
|
|||
|
||||
/**
|
||||
* private constructor, used by the enum class to makes each enum value
|
||||
*
|
||||
* @param value the short values specified in the enum listing
|
||||
*/
|
||||
REF_BASE(short value) {
|
||||
|
|
@ -89,6 +90,10 @@ abstract class GLFRecord {
|
|||
* @throws IllegalArgumentException if the value passed can't be converted
|
||||
*/
|
||||
public static REF_BASE toBase(char value) {
|
||||
// for the case where they're passing in the enumated value
|
||||
if (value <= 0x0F && value >= 0) {
|
||||
return REF_BASE.values()[value];
|
||||
}
|
||||
String str = String.valueOf(value).toUpperCase();
|
||||
for (int x = 0; x < REF_BASE.values().length; x++) {
|
||||
if (REF_BASE.values()[x].toString().equals(str)) {
|
||||
|
|
@ -186,6 +191,7 @@ abstract class GLFRecord {
|
|||
* @param out the binary codec to write to
|
||||
*/
|
||||
void write(BinaryCodec out) {
|
||||
short bite = ((short) (this.getRecordType().getReadTypeValue() << 4 | (refBase.getBaseHexValue() & 0x0f)));
|
||||
out.writeUByte((short) (this.getRecordType().getReadTypeValue() << 4 | (refBase.getBaseHexValue() & 0x0f)));
|
||||
out.writeUInt(((Long) offset).intValue());
|
||||
out.writeUInt((new Long(readDepth).intValue()));
|
||||
|
|
@ -210,16 +216,20 @@ abstract class GLFRecord {
|
|||
|
||||
/**
|
||||
* convert a double to a byte, capping it at the maximum value of 255
|
||||
*
|
||||
* @param d a double value
|
||||
*
|
||||
* @return a byte, capped at
|
||||
*/
|
||||
protected static short toCappedShort(double d) {
|
||||
return (d > 255.0) ? (byte)255 : (byte)Math.round(d);
|
||||
return (d > 255.0) ? (short) 255 : (short) Math.round(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* find the minimum value in a set of doubles
|
||||
*
|
||||
* @param vals
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected static double findMin(double vals[]) {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,12 @@ package org.broadinstitute.sting.utils.genotype.glf;
|
|||
|
||||
import net.sf.samtools.util.BinaryCodec;
|
||||
import net.sf.samtools.util.BlockCompressedOutputStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import org.broadinstitute.sting.utils.genotype.GenotypeWriter;
|
||||
import org.broadinstitute.sting.utils.genotype.IndelLikelihood;
|
||||
import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
/*
|
||||
* Copyright (c) 2009 The Broad Institute
|
||||
*
|
||||
|
|
@ -51,19 +50,17 @@ public class GLFWriter implements GenotypeWriter {
|
|||
|
||||
// our header text, reference sequence name (i.e. chr1), and it's length
|
||||
private String headerText = "";
|
||||
private String referenceSequenceName = "";
|
||||
private String referenceSequenceName = null;
|
||||
private long referenceSequenceLength = 0;
|
||||
|
||||
/**
|
||||
* The public constructor for creating a GLF object
|
||||
*
|
||||
* @param headerText the header text (currently unclear what the contents are)
|
||||
* @param referenceSequenceName the reference sequence name, i.e. "chr1", "chr2", etc
|
||||
* @param writeTo the location to write to
|
||||
*/
|
||||
public GLFWriter( String headerText, String referenceSequenceName, int referenceSequenceLength, File writeTo ) {
|
||||
public GLFWriter(String headerText, File writeTo) {
|
||||
this.headerText = headerText;
|
||||
this.referenceSequenceName = referenceSequenceName;
|
||||
this.referenceSequenceLength = referenceSequenceLength;
|
||||
outputBinaryCodec = new BinaryCodec(new DataOutputStream(new BlockCompressedOutputStream(writeTo)));
|
||||
outputBinaryCodec.setOutputFileName(writeTo.toString());
|
||||
this.writeHeader();
|
||||
|
|
@ -72,6 +69,8 @@ public class GLFWriter implements GenotypeWriter {
|
|||
/**
|
||||
* add a point genotype to the GLF writer
|
||||
*
|
||||
* @param contigName the name of the contig you're calling in
|
||||
* @param contigLength the contig length
|
||||
* @param refBase the reference base, as a char
|
||||
* @param genomicLoc the location, as an offset from the previous glf record
|
||||
* @param readDepth the read depth at the specified postion
|
||||
|
|
@ -79,14 +78,19 @@ public class GLFWriter implements GenotypeWriter {
|
|||
* @param lhValues the GenotypeLikelihoods object, representing the genotype likelyhoods
|
||||
*/
|
||||
@Override
|
||||
public void addGenotypeCall( int genomicLoc,
|
||||
public void addGenotypeCall(String contigName,
|
||||
int contigLength,
|
||||
int genomicLoc,
|
||||
float rmsMapQ,
|
||||
char refBase,
|
||||
int readDepth,
|
||||
LikelihoodObject lhValues) {
|
||||
|
||||
// check if we've jumped to a new contig
|
||||
checkSequence(contigName, contigLength);
|
||||
|
||||
SinglePointCall call = new SinglePointCall(refBase, genomicLoc,
|
||||
SinglePointCall call = new SinglePointCall(refBase,
|
||||
genomicLoc,
|
||||
readDepth,
|
||||
(short) rmsMapQ,
|
||||
lhValues.toDoubleArray());
|
||||
|
|
@ -96,6 +100,8 @@ public class GLFWriter implements GenotypeWriter {
|
|||
/**
|
||||
* add a variable length (indel, deletion, etc) to the genotype writer
|
||||
*
|
||||
* @param contigName the name of the contig you're calling in
|
||||
* @param contigLength the contig length
|
||||
* @param refBase the reference base
|
||||
* @param genomicLoc the location, as an offset from the previous glf record
|
||||
* @param readDepth the read depth at the specified postion
|
||||
|
|
@ -105,7 +111,9 @@ public class GLFWriter implements GenotypeWriter {
|
|||
* @param hetLikelihood the negitive log likelihood of the heterozygote, from 0 to 255
|
||||
*/
|
||||
@Override
|
||||
public void addVariableLengthCall( int genomicLoc,
|
||||
public void addVariableLengthCall(String contigName,
|
||||
int contigLength,
|
||||
int genomicLoc,
|
||||
float rmsMapQ,
|
||||
int readDepth,
|
||||
char refBase,
|
||||
|
|
@ -113,15 +121,8 @@ public class GLFWriter implements GenotypeWriter {
|
|||
IndelLikelihood secondHomZyg,
|
||||
byte hetLikelihood) {
|
||||
|
||||
// in this context, the minumum likelihood is lowest of the three options
|
||||
double lowestLikelihood = Double.MAX_VALUE;
|
||||
if (firstHomZyg.getLikelihood() < lowestLikelihood) {
|
||||
lowestLikelihood = firstHomZyg.getLikelihood();
|
||||
} else if (secondHomZyg.getLikelihood() < lowestLikelihood) {
|
||||
lowestLikelihood = secondHomZyg.getLikelihood();
|
||||
} else if (hetLikelihood < lowestLikelihood) {
|
||||
lowestLikelihood = hetLikelihood;
|
||||
}
|
||||
// check if we've jumped to a new contig
|
||||
checkSequence(contigName, contigLength);
|
||||
|
||||
// normalize the two
|
||||
VariableLengthCall call = new VariableLengthCall(refBase,
|
||||
|
|
@ -131,11 +132,12 @@ public class GLFWriter implements GenotypeWriter {
|
|||
firstHomZyg.getLikelihood(),
|
||||
secondHomZyg.getLikelihood(),
|
||||
hetLikelihood,
|
||||
firstHomZyg.getLengthOfIndel(),
|
||||
firstHomZyg.getIndelSequence(),
|
||||
secondHomZyg.getLengthOfIndel(),
|
||||
secondHomZyg.getIndelSequence());
|
||||
|
||||
call.write(this.outputBinaryCodec);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -155,7 +157,8 @@ public class GLFWriter implements GenotypeWriter {
|
|||
*
|
||||
* @param rec the GLF record to write.
|
||||
*/
|
||||
public void addGLFRecord( GLFRecord rec ) {
|
||||
public void addGLFRecord(String contigName, int contigLength, GLFRecord rec) {
|
||||
checkSequence(contigName,contigLength);
|
||||
rec.write(this.outputBinaryCodec);
|
||||
}
|
||||
|
||||
|
|
@ -167,24 +170,52 @@ public class GLFWriter implements GenotypeWriter {
|
|||
*/
|
||||
private void writeHeader() {
|
||||
for (int x = 0; x < glfMagic.length; x++) {
|
||||
outputBinaryCodec.writeByte(glfMagic[x]);
|
||||
outputBinaryCodec.writeUByte(glfMagic[x]);
|
||||
}
|
||||
if (!(headerText.equals(""))) {
|
||||
outputBinaryCodec.writeString(headerText, true, true);
|
||||
} else {
|
||||
outputBinaryCodec.writeInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check to see if we've jumped to a new contig
|
||||
*
|
||||
* @param sequenceName
|
||||
* @param seqLength
|
||||
*/
|
||||
private void checkSequence(String sequenceName, int seqLength) {
|
||||
if ((referenceSequenceName == null) || (!referenceSequenceName.equals(sequenceName))) {
|
||||
if (this.referenceSequenceName != null) { // don't write the record the first time
|
||||
this.writeEndRecord();
|
||||
}
|
||||
referenceSequenceName = sequenceName;
|
||||
referenceSequenceLength = seqLength;
|
||||
addSequence();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** add a sequence definition to the glf */
|
||||
private void addSequence() {
|
||||
outputBinaryCodec.writeString(referenceSequenceName, true, true);
|
||||
outputBinaryCodec.writeUInt(referenceSequenceLength);
|
||||
}
|
||||
|
||||
/** write end record */
|
||||
private void writeEndRecord() {
|
||||
outputBinaryCodec.writeUByte((short) 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* close the file. You must close the file to ensure any remaining data gets
|
||||
* written out.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
outputBinaryCodec.writeByte((byte) 0);
|
||||
writeEndRecord();
|
||||
outputBinaryCodec.close();
|
||||
}
|
||||
|
||||
|
|
@ -210,6 +241,16 @@ public class GLFWriter implements GenotypeWriter {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the reference sequence
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getReferenceSequenceName() {
|
||||
return referenceSequenceName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ class SinglePointCall extends GLFRecord {
|
|||
*/
|
||||
SinglePointCall(char refBase, int offset, int readDepth, short rmsMapQ, double likelihoods[]) {
|
||||
super(refBase, offset, (short) GLFRecord.findMin(likelihoods), readDepth, rmsMapQ);
|
||||
|
||||
this.likelihoods = likelihoods;
|
||||
}
|
||||
|
||||
|
|
@ -63,9 +62,13 @@ class SinglePointCall extends GLFRecord {
|
|||
*/
|
||||
void write(BinaryCodec out) {
|
||||
super.write(out);
|
||||
try {
|
||||
for (double likelihood : likelihoods) {
|
||||
out.writeUByte(GLFRecord.toCappedShort(likelihood));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -70,14 +70,16 @@ class VariableLengthCall extends GLFRecord {
|
|||
double lkHom1,
|
||||
double lkHom2,
|
||||
double lkHet,
|
||||
int indelOneLength,
|
||||
final short indelSeq1[],
|
||||
int indelTwoLength,
|
||||
final short indelSeq2[]) {
|
||||
super(refBase, offset, GLFRecord.toCappedShort(findMin(new double[]{lkHom1, lkHom2, lkHet})), readDepth, rmsMapQ);
|
||||
this.lkHom1 = GLFRecord.toCappedShort(lkHom1);
|
||||
this.lkHom2 = GLFRecord.toCappedShort(lkHom2);
|
||||
this.lkHet = GLFRecord.toCappedShort(lkHet);
|
||||
this.indelLen1 = indelSeq1.length;
|
||||
this.indelLen2 = indelSeq2.length;
|
||||
this.indelLen1 = indelOneLength;
|
||||
this.indelLen2 = indelTwoLength;
|
||||
this.indelSeq1 = indelSeq1;
|
||||
this.indelSeq2 = indelSeq2;
|
||||
size = 16 + indelSeq1.length + indelSeq2.length;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
package org.broadinstitute.sting.utils.genotype;
|
||||
|
||||
import org.junit.Test;
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils;
|
||||
import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 The Broad Institute
|
||||
|
|
@ -58,7 +56,7 @@ public class GeliAdapterTest extends BaseTest {
|
|||
SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(2,1,10);
|
||||
adapter = new GeliAdapter(fl,header);
|
||||
LikelihoodObject obj = new LikelihoodObject(createFakeLikelihoods());
|
||||
adapter.addGenotypeCall(100,100,'A',100,obj);
|
||||
adapter.addGenotypeCall("chr1",10,100,100,'A',100,obj);
|
||||
adapter.close();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package org.broadinstitute.sting.utils.genotype.glf;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import org.broadinstitute.sting.BaseTest;
|
||||
import org.broadinstitute.sting.utils.genotype.glf.GLFWriter;
|
||||
import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
||||
import org.broadinstitute.sting.utils.genotype.GenotypeWriter;
|
||||
import org.broadinstitute.sting.utils.genotype.LikelihoodObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
|
@ -88,7 +87,7 @@ public class GLFWriterTest extends BaseTest {
|
|||
|
||||
@Test
|
||||
public void basicWrite() {
|
||||
rec = new GLFWriter(header, referenceSequenceName, refLength, writeTo);
|
||||
rec = new GLFWriter(header, writeTo);
|
||||
for (int x = 0; x < 100; x++) {
|
||||
addFakeSNP((int) Math.round(Math.random() * 9), 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue