| 1 |
package pp2.prediction.knn; |
| 2 |
|
| 3 |
|
| 4 |
/** |
| 5 |
* Stores a BLAST hit with associated information such as E-value etc. |
| 6 |
* @author Thomas Hopf |
| 7 |
* |
| 8 |
*/ |
| 9 |
public class BlastHit implements Comparable<BlastHit>{ |
| 10 |
|
| 11 |
// FASTA identifier of the hit |
| 12 |
private String hitID; |
| 13 |
|
| 14 |
// list of all associated go terms |
| 15 |
private String[] goTerms; |
| 16 |
|
| 17 |
// all measures of the hit |
| 18 |
private double eValue; |
| 19 |
private double bitScore; |
| 20 |
private int length; |
| 21 |
|
| 22 |
private int sequenceIdentity; |
| 23 |
private int sequenceIdentityLength; |
| 24 |
private int gaps; |
| 25 |
private int gapsLength; |
| 26 |
|
| 27 |
// PSI-Blast iteration in which the hit was found |
| 28 |
private int iteration; |
| 29 |
|
| 30 |
// holds which ontologies are supported by this hit (important for calculating normalization values) |
| 31 |
private boolean[] supports; |
| 32 |
// private boolean supportsMolecularFunction = false; |
| 33 |
// private boolean supportsBiologicalProcess = false; |
| 34 |
// private boolean supportsCellularComponent = false; |
| 35 |
|
| 36 |
public BlastHit(String hitLine) |
| 37 |
{ |
| 38 |
try { |
| 39 |
String[] split = hitLine.split("\t"); |
| 40 |
//System.out.println(Arrays.toString(split)); |
| 41 |
|
| 42 |
// extract all information from the hitLine |
| 43 |
hitID = split[0]; |
| 44 |
goTerms = split[1].split(","); |
| 45 |
|
| 46 |
// if eValue has format e-117, we need to add a "1" as prefix to avoid a NumberFormatException |
| 47 |
eValue = Double.parseDouble(split[2].startsWith("e") ? ("1"+split[2]): split[2]); |
| 48 |
|
| 49 |
bitScore = Double.parseDouble(split[3]); |
| 50 |
length = Integer.parseInt(split[4]); |
| 51 |
sequenceIdentity = Integer.parseInt(split[5].split("/")[0]); |
| 52 |
sequenceIdentityLength = Integer.parseInt(split[5].split("/")[1]); |
| 53 |
if(split[6].equals("0")) |
| 54 |
{ |
| 55 |
gaps = 0; |
| 56 |
gapsLength = length; |
| 57 |
} |
| 58 |
else |
| 59 |
{ |
| 60 |
gaps = Integer.parseInt(split[6].split("/")[0]); |
| 61 |
gapsLength = Integer.parseInt(split[6].split("/")[1]); |
| 62 |
} |
| 63 |
iteration = Integer.parseInt(split[7]); |
| 64 |
|
| 65 |
supports = new boolean[PredictionTarget.NUM_ONTOLOGIES]; |
| 66 |
} catch(Exception e) { |
| 67 |
System.err.println("an error occurred while parsing a blast hit line:"); |
| 68 |
System.err.println(hitLine); |
| 69 |
e.printStackTrace(); |
| 70 |
//System.err.println(e); |
| 71 |
} |
| 72 |
//System.out.println(hitID + "->" + goTerms + ", " + eValue); |
| 73 |
} |
| 74 |
|
| 75 |
// deprecated |
| 76 |
public BlastHit(String goTerms, double eValue) |
| 77 |
{ |
| 78 |
this.goTerms = goTerms.split(","); |
| 79 |
this.eValue = eValue; |
| 80 |
} |
| 81 |
|
| 82 |
public double getEValue() |
| 83 |
{ |
| 84 |
return eValue; |
| 85 |
} |
| 86 |
|
| 87 |
public String[] getGoTerms() |
| 88 |
{ |
| 89 |
return goTerms; |
| 90 |
} |
| 91 |
|
| 92 |
public double getBitScore() |
| 93 |
{ |
| 94 |
return bitScore; |
| 95 |
} |
| 96 |
|
| 97 |
public String getHitID() |
| 98 |
{ |
| 99 |
return hitID; |
| 100 |
} |
| 101 |
|
| 102 |
public boolean supports(int ontologyType) { |
| 103 |
return supports[ontologyType]; |
| 104 |
} |
| 105 |
|
| 106 |
public void activateOntologySupport(String ontology) |
| 107 |
{ |
| 108 |
if(ontology.equals("molecular_function")) |
| 109 |
supports[PredictionTarget.MOLECULAR_FUNCTION] = true; |
| 110 |
else { |
| 111 |
if(ontology.equals("biological_process")) |
| 112 |
supports[PredictionTarget.BIOLOGICAL_PROCESS] = true; |
| 113 |
else |
| 114 |
supports[PredictionTarget.CELLULAR_COMPONENT] = true; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public int compareTo(BlastHit o) { |
| 120 |
|
| 121 |
if(this.eValue < o.eValue) |
| 122 |
return -1; |
| 123 |
else { |
| 124 |
if (this.eValue > o.eValue) |
| 125 |
return 1; |
| 126 |
else |
| 127 |
return 0; |
| 128 |
} |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
} |