Skip to content

Commit

Permalink
Handling of new input files.
Browse files Browse the repository at this point in the history
Fixed null pointer issues with complex inversions in the initial input.
  • Loading branch information
jibsch committed Mar 23, 2017
1 parent cbf92b3 commit 4d0093b
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>au.edu.wehi</groupId>
<artifactId>clove</artifactId>
<packaging>jar</packaging>
<version>0.13</version>
<version>0.14</version>
<name>clove</name>
<url>http://github.com/PapenfussLab/clove</url>
<properties>
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/au/edu/wehi/clove/Clove.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private static void compareToGoldStandard(String goldFileName, Hashtable<String,
//redundant HTP?
System.out.println("Redundant HTP!");
} else {
statsByType.get(e.getType())[3]++;
statsByType.get(typeConversion.get(type))[3]++;
}

}
Expand All @@ -389,11 +389,11 @@ private static void compareToGoldStandard(String goldFileName, Hashtable<String,
e = events.next();

int tps=0, fps=0, fns=0, htps=0;
System.out.println("Stats:\tTP\tHalf TP\tFP\tFN\tSen\tSpe");
System.out.println("Stats:\tTP\tHalf-TP\tFP\tFN\tSen\tSpe");
for(EVENT_TYPE t: EVENT_TYPE.values()){
int[] stats = statsByType.get(t);
double sen = (stats[0]+stats[2]==0? 0: (double)stats[0]/(stats[0]+stats[2]));
double spe = (stats[0]+stats[1]==0? 0: (double)stats[0]/(stats[0]+stats[1]));
double sen = (stats[0]+stats[2]+stats[3]==0? 0: (double)(stats[0]+stats[3])/(stats[0]+stats[2]+stats[3]));
double spe = (stats[0]+stats[1]+stats[3]==0? 0: (double)(stats[0]+stats[3])/(stats[0]+stats[1]+stats[3]));
System.out.println(t+"\t"+stats[0]+"\t"+stats[3]+"\t"+stats[1]+"\t"+stats[2]+"\t"+sen+"\t"+spe);
tps+=stats[0]; fps+=stats[1]; fns+=stats[2]; htps +=stats[3];
}
Expand Down Expand Up @@ -528,7 +528,7 @@ public static void createVCFHeader(PrintWriter output) throws IOException{
output.write("#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\n");
}

enum SV_ALGORITHM {SOCRATES, DELLY, CREST, GUSTAF, BEDPE};
enum SV_ALGORITHM {SOCRATES, DELLY, DELLY2, CREST, GUSTAF, BEDPE, METASV};


static ArrayList<String> oldFns = new ArrayList<String>();
Expand All @@ -542,7 +542,7 @@ public static void main(String[] args) throws IOException {

if(args.length < 8){
System.err.println("Options (all mandatory -- input can be specified more than once):" +
"\n\t-i <list of breakpoints> <algorithm (Socrates/Delly/Crest/Gustaf/BEDPE)>" +
"\n\t-i <list of breakpoints> <algorithm (Socrates/Delly/Delly2/Crest/Gustaf/BEDPE)>" +
"\n\t-b <BAM file> \n\t-c <mean coverage> <coverage>" +
"\n\t-o <output filename> [default: CLOVE.vcf]");
System.exit(0);
Expand Down Expand Up @@ -619,9 +619,11 @@ public static void main(String[] args) throws IOException {
switch(algorithm){
case SOCRATES: e = Event.createNewEventFromSocratesOutputLatest(line, count++); break;
case DELLY: e = Event.createNewEventFromDellyOutputLatest(line);break;
case DELLY2: e = Event.createNewEventFromDelly2Output(line);break;
case CREST: e = Event.createNewEventFromCrestOutputLatest(line, count++); break;
case GUSTAF: e = Event.createNewEventFromGustafOutput(line); if(e.size()<50) continue; break;
case GUSTAF: e = Event.createNewEventFromGustafOutput(line); if(e.size()<50) continue; break;
case BEDPE: e = Event.createNewEventFromBEDPE(line); break;
case METASV: e = Event.createNewEventFromMetaSVOutput(line); break;
default: e = null;
}
allEvents.add(e);
Expand Down
136 changes: 132 additions & 4 deletions src/main/java/au/edu/wehi/clove/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,138 @@ public static Event createNewEventFromDellyOutputLatest(String output){
return new Event(c1, c2, type, id, ref, alt, qual, filter, info, new HashSet<Clove.SV_ALGORITHM>() {{add(Clove.SV_ALGORITHM.DELLY);}}, 1);
//return new Event(c1, c2, type);

}
public static Event createNewEventFromDelly2Output(String output){
String[] bits = output.split("\t");
String chr1 = bits[0];
int p1 = Integer.parseInt(bits[1]);
String[] moreBits = bits[7].split(";");
String chr2 = moreBits[3].replace("CHR2=", "");
int p2 = Integer.parseInt(moreBits[4].replace("END=", ""));
String o = moreBits[7].replace("CT=", "");
String o1 = (Integer.parseInt(o.split("to")[0]) == 3? "+" : "-");
String o2 = (Integer.parseInt(o.split("to")[1]) == 3? "+" : "-");

String id=bits[2];
String ref=bits[3];
String alt=bits[4];
String qual=bits[5];
String filter=bits[6];
String info=bits[7];

GenomicCoordinate c1 = new GenomicCoordinate(chr1, p1);
GenomicCoordinate c2 = new GenomicCoordinate(chr2, p2);
EVENT_TYPE type = classifySocratesBreakpoint(c1, o1, c2, o2);

//System.out.println(chr1 +"\t"+ p1 +"\t"+ p2 +"\t" + type +"\t"+ typeT);

return new Event(c1, c2, type, id, ref, alt, qual, filter, info, new HashSet<Clove.SV_ALGORITHM>() {{add(Clove.SV_ALGORITHM.DELLY);}}, 1);
//return new Event(c1, c2, type);

}
/*
* Function to classify a line of Delly output into a genomic event type.
* Function to classify a line of BedPE into a genomic event type.
* The distinctions between INV1/2 etc are arbitrary, and have to be consistent across all the inputs.
* c1 and c2 are always the same chromosome
*/
private static EVENT_TYPE classifyDellyBreakpointLatest(GenomicCoordinate c1, GenomicCoordinate c2){
return null;
}

/*
* Static function to handle the particularities of MetaSV output, and convert it into a general
* purpose Event.
*/
public static Event createNewEventFromMetaSVOutput(String output){
String[] bits = output.split("\t");
String chr1 = bits[0];
int p1 = Integer.parseInt(bits[1]);
String[] moreBits = bits[7].split(";");
String chr2 = chr1;
int p2 = 0;
String o1 = null;
String o2 = null;
for(String s: moreBits){
if(s.startsWith("CHR2"))
chr2 = s.replace("CHR2=", "");
else if(s.startsWith("END="))
p2 = Integer.parseInt(s.replace("END=", ""));
else if(s.startsWith("SVLEN="))
p2 = p1 + Integer.parseInt(s.replace("SVLEN=", ""));
else if(s.startsWith("BD_ORI1")){
String o = s.replace("BD_ORI1=", "");
int fwd = Integer.parseInt(o.split("[+-]")[0]);
int rev = Integer.parseInt(o.split("[+-]")[1]);
o1 = (fwd>rev ? "+" : "-");}

else if(s.startsWith("BD_ORI2")){
String o = s.replace("BD_ORI2=", "");
int fwd = Integer.parseInt(o.split("[+-]")[0]);
int rev = Integer.parseInt(o.split("[+-]")[1]);
o2 = (fwd>rev ? "+" : "-");
}
}
String id=bits[2];
String ref=bits[3];
String alt=bits[4];
String qual=bits[5];
String filter=bits[6];
String info=bits[7];

GenomicCoordinate c1 = new GenomicCoordinate(chr1, p1);
GenomicCoordinate c2 = new GenomicCoordinate(chr2, p2);
EVENT_TYPE type = classifyMetaSVBreakpoint(alt, chr1, chr2, o1, o2);

if(type == EVENT_TYPE.COMPLEX_INVERSION){
Event e = new ComplexEvent(c1, c2, type, new Event[] {}, null);
e.setAlt("<CIV>");
e.setCoord(c1);
return e;
}

//System.out.println(chr1 +"\t"+ p1 +"\t"+ p2 +"\t" + type +"\t"+ typeT);

return new Event(c1, c2, type, id, ref, alt, qual, filter, info, new HashSet<Clove.SV_ALGORITHM>() {{add(Clove.SV_ALGORITHM.METASV);}}, 1);
//return new Event(c1, c2, type);

}

private static EVENT_TYPE classifyMetaSVBreakpoint(String t, String c1, String c2, String o1, String o2){
if(t.equals("<DEL>")){
return EVENT_TYPE.DEL;
} else if (t.equals("<INS>")){
return EVENT_TYPE.INS;
} else if (t.equals("<INV>")){
return EVENT_TYPE.COMPLEX_INVERSION;
} else if(t.equals("<ITX>")){
if(o1.equals("+"))
if(o2.equals("+"))
return EVENT_TYPE.INV1;
else
return EVENT_TYPE.DEL;
else if(o2.equals("+"))
return EVENT_TYPE.TAN;
else
return EVENT_TYPE.INV2;
} else if (t.equals("<CTX>")) {
if(o1.equals(o2)) {
if(o1.equals("+"))
return EVENT_TYPE.INVTX1;
else
return EVENT_TYPE.INVTX2;
} else if(o1.equals("+") && c1.compareTo(c2) < 0 || o1.equals("-") && c1.compareTo(c2) >= 0){
return EVENT_TYPE.ITX1;
} else {
return EVENT_TYPE.ITX2;
}
} else if(t.equals("<DUP>")){
return EVENT_TYPE.TAN;
}
else {
return EVENT_TYPE.XXX;
}
}

public static Event createNewEventFromBEDPE (String output){
String[] bits = output.split("\t");
String chr1 = bits[0];
Expand Down Expand Up @@ -297,7 +419,10 @@ public static Event createNewEventFromCrestOutput(String output) {
EVENT_TYPE type = classifyCrestBreakpoint(t.nextToken(), chr1, chr2, o1, o2);

if(type == EVENT_TYPE.COMPLEX_INVERSION){
return new ComplexEvent(c1, c2, type, null, null);
Event e = new ComplexEvent(c1, c2, type, new Event[] {}, null);
e.setAlt("<CIV>");
e.setCoord(c1);
return e;
}
return new Event(c1, c2, type);
}
Expand Down Expand Up @@ -325,7 +450,10 @@ public static Event createNewEventFromCrestOutputLatest(String output, int count
EVENT_TYPE type = classifyCrestBreakpoint(t.nextToken(), chr1, chr2, o1, o2);

if(type == EVENT_TYPE.COMPLEX_INVERSION){
return new ComplexEvent(c1, c2, type, null, null);
Event e = new ComplexEvent(c1, c2, type, new Event[] {}, null);
e.setAlt("<CIV>");
e.setCoord(c1);
return e;
}

String alt=altVCF(type);
Expand Down Expand Up @@ -523,7 +651,7 @@ public void setAlt(String alt) {
}

public String getFilter() {
return filter;
return (filter==null? ".":filter);
}

public void setFilter(String filter) {
Expand Down

0 comments on commit 4d0093b

Please sign in to comment.