| 1 |
package var; |
| 2 |
|
| 3 |
import dna.Gene; |
| 4 |
|
| 5 |
|
| 6 |
public class VarLine extends Variation{ |
| 7 |
|
| 8 |
public static final long serialVersionUID = -4089933371294357462L; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
public VarLine(){} |
| 13 |
|
| 14 |
public VarLine(String s, float version){ |
| 15 |
String[] line=s.split("\t", -1); |
| 16 |
|
| 17 |
for(int i=0; i<line.length; i++){ |
| 18 |
line[i]=line[i].trim(); |
| 19 |
if(line[i].length()<1){ |
| 20 |
line[i]=null; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
Byte b=varTypeMap2.get(line.length>6 ? line[6] : "null"); |
| 28 |
assert(b!=null) : "Can't find "+line[6]+" in "+varTypeMap2.keySet()+"\n\nLine: "+s+"\n"; |
| 29 |
varType=b; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
b=(Byte)ploidyMap.get(line[1]); |
| 35 |
assert(b!=null) : "\n\n"+line[1]+"\n\n"+s+"\n\n"; |
| 36 |
ploidy=b; |
| 37 |
|
| 38 |
|
| 39 |
haplotype=(byte)find(line[2], haploMap); |
| 40 |
assert(haplotype>=0) : line[2]; |
| 41 |
|
| 42 |
chromosome=Gene.toChromosome(line[3]); |
| 43 |
assert(chromosome>0) : line[3]+" -> "+line[3].substring(3); |
| 44 |
|
| 45 |
beginLoc=Integer.parseInt(line[4]); |
| 46 |
int tempInt=Integer.parseInt(line[5])-1; |
| 47 |
tempInt=max(tempInt, beginLoc); |
| 48 |
endLoc=tempInt; |
| 49 |
|
| 50 |
String temp; |
| 51 |
|
| 52 |
temp=line.length>7 ? line[7] : null; |
| 53 |
if("?".equals(temp)){temp=null;} |
| 54 |
ref=temp; |
| 55 |
|
| 56 |
temp=line.length>8 ? line[8] : null; |
| 57 |
if("?".equals(temp)){temp=null;} |
| 58 |
call=temp; |
| 59 |
|
| 60 |
|
| 61 |
if(version<2){ |
| 62 |
|
| 63 |
totalScore=((line.length<=9 || line[9]==null || line[9].length()<1) ? -1 : Integer.parseInt(line[9])); |
| 64 |
hapLink=((line.length<=10 || line[10]==null || line[10].length()<1) ? -1 : Integer.parseInt(line[10])); |
| 65 |
|
| 66 |
assert(beginLoc<=endLoc) : s; |
| 67 |
|
| 68 |
|
| 69 |
}else{ |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
int varScoreVAF=((line.length<=9 || line[9]==null || line[9].length()<1) ? -1 : Integer.parseInt(line[9])); |
| 75 |
int varScoreEAF=((line.length<=10 || line[10]==null || line[10].length()<1) ? -1 : Integer.parseInt(line[10])); |
| 76 |
byte VQ=((line.length<=11 || line[11]==null || line[11].length()<1) ? (byte)0 : (byte)find(line[11], VQARRAY)); |
| 77 |
|
| 78 |
totalScore=varScoreVAF; |
| 79 |
hapLink=((line.length<=12 || line[12]==null || line[12].length()<1) ? -1 : Integer.parseInt(line[12])); |
| 80 |
|
| 81 |
assert(beginLoc<=endLoc) : s; |
| 82 |
|
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
assert(!((varType==Variation.INS || varType==Variation.DELINS || varType==Variation.SNP) |
| 87 |
&& call==null)) : "\nversion="+version+"\n"+s+"\n"+line+"\nline.ref="+ref+"\nline.call="+call+"\nref="+ref+"\ncall="+call; |
| 88 |
|
| 89 |
intern(); |
| 90 |
} |
| 91 |
|
| 92 |
@Override |
| 93 |
public VarLine clone(){ |
| 94 |
VarLine v=null; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
v=(VarLine) super.clone(); |
| 102 |
return v; |
| 103 |
} |
| 104 |
|
| 105 |
public VarLine[] splitLine(){ |
| 106 |
assert(haplotype==3) : this; |
| 107 |
VarLine[] r=new VarLine[2]; |
| 108 |
r[0]=this.clone(); |
| 109 |
r[1]=this.clone(); |
| 110 |
assert(this.equals(r[0]) && r[0].equals(this)); |
| 111 |
r[0].haplotype=1; |
| 112 |
r[1].haplotype=2; |
| 113 |
return r; |
| 114 |
} |
| 115 |
|
| 116 |
public VarLine spawnEqualPoint(){ |
| 117 |
assert(this.isPoint()); |
| 118 |
VarLine v=this.clone(); |
| 119 |
v.varType=REFPOINT; |
| 120 |
v.call=v.ref=null; |
| 121 |
return v; |
| 122 |
} |
| 123 |
|
| 124 |
public static VarLine makeEqualPoint(byte chrom, int loc, byte hap){ |
| 125 |
VarLine v=new VarLine(); |
| 126 |
v.chromosome=chrom; |
| 127 |
v.beginLoc=loc; |
| 128 |
v.endLoc=loc; |
| 129 |
v.haplotype=hap; |
| 130 |
v.varType=REFPOINT; |
| 131 |
return v; |
| 132 |
} |
| 133 |
|
| 134 |
@Override |
| 135 |
public String toSuperString(){return super.toString();} |
| 136 |
|
| 137 |
|
| 138 |
@Override |
| 139 |
public String toString(){ |
| 140 |
StringBuilder sb=new StringBuilder(256); |
| 141 |
|
| 142 |
|
| 143 |
sb.append(ploidyMap.get(ploidy)+"\t"); |
| 144 |
sb.append(haploMap[haplotype]+"\t"); |
| 145 |
sb.append("chr"+Gene.chromCodes[chromosome]+"\t"); |
| 146 |
sb.append(beginLoc+"\t"); |
| 147 |
sb.append(endLoc+"\t"); |
| 148 |
|
| 149 |
sb.append(varTypeMap[varType]+"\t"); |
| 150 |
sb.append((ref==null ? "" : ref)+"\t"); |
| 151 |
sb.append((call==null ? "" : call)+"\t"); |
| 152 |
sb.append((totalScore==-1 ? "" : totalScore)+"\t"); |
| 153 |
sb.append((hapLink==-1 ? "" : hapLink)+"\t"); |
| 154 |
|
| 155 |
return sb.toString(); |
| 156 |
} |
| 157 |
|
| 158 |
public static String sourceHeader(){ |
| 159 |
return "#locus\tploidy\tallele\tchromosome\tbegin\tend\tvarType\treference\talleleSeq\ttotalScore\thapLink\txRef"; |
| 160 |
|
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
@Override |
| 166 |
public String toSourceString(){ |
| 167 |
StringBuilder sb=new StringBuilder(256); |
| 168 |
|
| 169 |
sb.append(0+"\t"); |
| 170 |
sb.append(ploidyMap.get(ploidy)+"\t"); |
| 171 |
sb.append(haploMap[haplotype]+"\t"); |
| 172 |
sb.append("chr"+Gene.chromCodes[chromosome]+"\t"); |
| 173 |
sb.append(beginLoc+"\t"); |
| 174 |
|
| 175 |
if(varType==INS){ |
| 176 |
sb.append(beginLoc+"\t"); |
| 177 |
}else{ |
| 178 |
sb.append((endLoc+1)+"\t"); |
| 179 |
} |
| 180 |
|
| 181 |
sb.append(varTypeMap[varType]+"\t"); |
| 182 |
sb.append((ref==null ? "" : ref)+"\t"); |
| 183 |
sb.append((call==null ? "" : call)+"\t"); |
| 184 |
sb.append((totalScore==-1 ? "" : totalScore)+"\t"); |
| 185 |
sb.append((hapLink==-1 ? "" : hapLink)+"\t"); |
| 186 |
|
| 187 |
return sb.toString(); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
@Override |
| 192 |
public String toShortString(){ |
| 193 |
StringBuilder sb=new StringBuilder(256); |
| 194 |
|
| 195 |
sb.append(haploMap[haplotype]); |
| 196 |
while(sb.length()<3){sb.append(' ');} |
| 197 |
sb.append('\t'); |
| 198 |
sb.append(locationString()+"\t"); |
| 199 |
|
| 200 |
sb.append(varTypeMap[varType]+"\t"); |
| 201 |
sb.append((ref==null ? "" : ref)+"\t"); |
| 202 |
sb.append((call==null ? "" : call)+"\t"); |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
return sb.toString(); |
| 207 |
} |
| 208 |
|
| 209 |
@SuppressWarnings("unused") |
| 210 |
private static final int min(int x, int y){return x<y ? x : y;} |
| 211 |
private static final int max(int x, int y){return x>y ? x : y;} |
| 212 |
|
| 213 |
|
| 214 |
@Override |
| 215 |
public int compareTo(Variation other) { |
| 216 |
if(other.getClass()==VarLine.class){ |
| 217 |
return compareTo((VarLine)other); |
| 218 |
} |
| 219 |
return super.compareTo(other); |
| 220 |
} |
| 221 |
|
| 222 |
public int compareTo(VarLine other) { |
| 223 |
int x=super.compareTo((Variation)other); |
| 224 |
if(x!=0){return x;} |
| 225 |
return haplotype-other.haplotype; |
| 226 |
} |
| 227 |
|
| 228 |
@Override |
| 229 |
public boolean equals(Object other){ |
| 230 |
if(other.getClass()==VarLine.class){ |
| 231 |
return equals((VarLine)other); |
| 232 |
} |
| 233 |
return super.equals(other); |
| 234 |
} |
| 235 |
|
| 236 |
public boolean equals(VarLine other){ |
| 237 |
return compareTo(other)==0; |
| 238 |
} |
| 239 |
|
| 240 |
@Override |
| 241 |
public boolean equals(Variation other){ |
| 242 |
return super.equals(other); |
| 243 |
} |
| 244 |
|
| 245 |
public byte ploidy; |
| 246 |
|
| 247 |
|
| 248 |
public byte haplotype; |
| 249 |
public int totalScore; |
| 250 |
public int hapLink; |
| 251 |
|
| 252 |
public static final String[] VQARRAY=new String[] {"?", "VQLOW", "VQHIGH"}; |
| 253 |
|
| 254 |
} |