| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.analysis; |
| 22 |
|
|
| 23 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 24 |
|
import jalview.datamodel.AlignmentI; |
| 25 |
|
import jalview.datamodel.SequenceI; |
| 26 |
|
|
| 27 |
|
import com.stevesoft.pat.Regex; |
| 28 |
|
|
| |
|
| 94.1% |
Uncovered Elements: 4 (68) |
Complexity: 16 |
Complexity Density: 0.35 |
|
| 29 |
|
public class ParseProperties |
| 30 |
|
{ |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
private AlignmentI al = null; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
@param |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
3 |
public ParseProperties(AlignmentI al)... |
| 53 |
|
{ |
| 54 |
3 |
this.al = al; |
| 55 |
|
} |
| 56 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 57 |
3 |
public int getScoresFromDescription(String ScoreName,... |
| 58 |
|
String ScoreDescriptions, String regex, boolean repeat) |
| 59 |
|
{ |
| 60 |
3 |
return getScoresFromDescription(new String[] { ScoreName }, |
| 61 |
|
new String[] |
| 62 |
|
{ ScoreDescriptions }, regex, repeat); |
| 63 |
|
} |
| 64 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
3 |
public int getScoresFromDescription(String[] ScoreNames,... |
| 66 |
|
String[] ScoreDescriptions, String regex, boolean repeat) |
| 67 |
|
{ |
| 68 |
3 |
return getScoresFromDescription(al.getSequencesArray(), ScoreNames, |
| 69 |
|
ScoreDescriptions, regex, repeat); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
@param |
| 76 |
|
|
| 77 |
|
@param |
| 78 |
|
|
| 79 |
|
@param |
| 80 |
|
|
| 81 |
|
@param |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
@param |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@return |
| 88 |
|
|
| |
|
| 93.4% |
Uncovered Elements: 4 (61) |
Complexity: 13 |
Complexity Density: 0.3 |
|
| 89 |
3 |
public int getScoresFromDescription(SequenceI[] seqs, String[] ScoreNames,... |
| 90 |
|
String[] ScoreDescriptions, String regex, boolean repeat) |
| 91 |
|
{ |
| 92 |
3 |
int count = 0; |
| 93 |
3 |
Regex pattern = new Regex(regex); |
| 94 |
3 |
if (pattern.numSubs() > ScoreNames.length) |
| 95 |
|
{ |
| 96 |
|
|
| 97 |
|
|
| 98 |
1 |
int onamelen = ScoreNames.length; |
| 99 |
1 |
String[] tnames = new String[pattern.numSubs() + 1]; |
| 100 |
1 |
System.arraycopy(ScoreNames, 0, tnames, 0, ScoreNames.length); |
| 101 |
1 |
String base = tnames[ScoreNames.length - 1]; |
| 102 |
1 |
ScoreNames = tnames; |
| 103 |
1 |
String descrbase = ScoreDescriptions[onamelen - 1]; |
| 104 |
1 |
if (descrbase == null) |
| 105 |
|
{ |
| 106 |
0 |
descrbase = "Score parsed from (" + regex + ")"; |
| 107 |
|
} |
| 108 |
1 |
tnames = new String[pattern.numSubs() + 1]; |
| 109 |
1 |
System.arraycopy(ScoreDescriptions, 0, tnames, 0, |
| 110 |
|
ScoreDescriptions.length); |
| 111 |
1 |
ScoreDescriptions = tnames; |
| 112 |
3 |
for (int i = onamelen; i < ScoreNames.length; i++) |
| 113 |
|
{ |
| 114 |
2 |
ScoreNames[i] = base + "_" + i; |
| 115 |
2 |
ScoreDescriptions[i] = descrbase + " (column " + i + ")"; |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
15 |
for (int i = 0; i < seqs.length; i++) |
| 119 |
|
{ |
| 120 |
12 |
String descr = seqs[i].getDescription(); |
| 121 |
12 |
if (descr == null) |
| 122 |
|
{ |
| 123 |
0 |
continue; |
| 124 |
|
} |
| 125 |
12 |
int pos = 0; |
| 126 |
12 |
boolean added = false; |
| 127 |
12 |
int reps = 0; |
| 128 |
31 |
while ((repeat || pos == 0) && pattern.searchFrom(descr, pos)) |
| 129 |
|
{ |
| 130 |
19 |
pos = pattern.matchedTo(); |
| 131 |
41 |
for (int cols = 0; cols < pattern.numSubs(); cols++) |
| 132 |
|
{ |
| 133 |
22 |
String sstring = pattern.stringMatched(cols + 1); |
| 134 |
22 |
double score = Double.NaN; |
| 135 |
22 |
try |
| 136 |
|
{ |
| 137 |
22 |
score = Double.valueOf(sstring).doubleValue(); |
| 138 |
|
} catch (Exception e) |
| 139 |
|
{ |
| 140 |
|
|
| 141 |
5 |
continue; |
| 142 |
|
} |
| 143 |
|
|
| 144 |
17 |
AlignmentAnnotation an = new AlignmentAnnotation( |
| 145 |
17 |
ScoreNames[cols] + ((reps > 0) ? "_" + reps : ""), |
| 146 |
|
ScoreDescriptions[cols], null); |
| 147 |
17 |
an.setScore(score); |
| 148 |
17 |
jalview.bin.Console.outPrintln(seqs[i].getName() + " score: '" |
| 149 |
|
+ ScoreNames[cols] + "' = " + score); |
| 150 |
17 |
an.setSequenceRef(seqs[i]); |
| 151 |
17 |
seqs[i].addAlignmentAnnotation(an); |
| 152 |
17 |
al.addAnnotation(an); |
| 153 |
17 |
added = true; |
| 154 |
|
} |
| 155 |
19 |
reps++; |
| 156 |
|
} |
| 157 |
12 |
if (added) |
| 158 |
|
{ |
| 159 |
10 |
count++; |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
3 |
return count; |
| 163 |
|
} |
| 164 |
|
} |