| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.io; |
| 22 |
|
|
| 23 |
|
import static org.testng.Assert.assertTrue; |
| 24 |
|
import static org.testng.AssertJUnit.assertEquals; |
| 25 |
|
import static org.testng.AssertJUnit.assertNotNull; |
| 26 |
|
import static org.testng.AssertJUnit.assertTrue; |
| 27 |
|
import static org.testng.AssertJUnit.fail; |
| 28 |
|
|
| 29 |
|
import java.io.File; |
| 30 |
|
import java.util.Arrays; |
| 31 |
|
import java.util.BitSet; |
| 32 |
|
import java.util.HashMap; |
| 33 |
|
import java.util.List; |
| 34 |
|
import java.util.Map; |
| 35 |
|
import java.util.regex.Matcher; |
| 36 |
|
import java.util.regex.Pattern; |
| 37 |
|
|
| 38 |
|
import org.testng.Assert; |
| 39 |
|
import org.testng.annotations.BeforeClass; |
| 40 |
|
import org.testng.annotations.Test; |
| 41 |
|
|
| 42 |
|
import jalview.datamodel.Alignment; |
| 43 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 44 |
|
import jalview.datamodel.AlignmentI; |
| 45 |
|
import jalview.datamodel.Annotation; |
| 46 |
|
import jalview.datamodel.DBRefEntry; |
| 47 |
|
import jalview.datamodel.Sequence; |
| 48 |
|
import jalview.datamodel.SequenceFeature; |
| 49 |
|
import jalview.datamodel.SequenceI; |
| 50 |
|
import jalview.gui.JvOptionPane; |
| 51 |
|
import jalview.util.DBRefUtils; |
| 52 |
|
|
| |
|
| 93.4% |
Uncovered Elements: 24 (366) |
Complexity: 94 |
Complexity Density: 0.37 |
|
| 53 |
|
public class StockholmFileTest |
| 54 |
|
{ |
| 55 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 56 |
1 |
@BeforeClass(alwaysRun = true)... |
| 57 |
|
public void setUpJvOptionPane() |
| 58 |
|
{ |
| 59 |
1 |
JvOptionPane.setInteractiveMode(false); |
| 60 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
static String PfamFile = "examples/PF00111_seed.stk", |
| 64 |
|
RfamFile = "examples/RF00031_folded.stk", |
| 65 |
|
RnaSSTestFile = "examples/rna_ss_test.stk"; |
| 66 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 67 |
1 |
@Test(groups = { "Functional" })... |
| 68 |
|
public void pfamFileIO() throws Exception |
| 69 |
|
{ |
| 70 |
1 |
testFileIOwithFormat(new File(PfamFile), FileFormat.Stockholm, -1, 0, |
| 71 |
|
false, false, false); |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 74 |
1 |
@Test(groups = { "Functional" })... |
| 75 |
|
public void pfamFileDataExtraction() throws Exception |
| 76 |
|
{ |
| 77 |
1 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
| 78 |
1 |
AlignmentI al = af.readFile(PfamFile, DataSourceType.FILE, |
| 79 |
|
new IdentifyFile().identify(PfamFile, DataSourceType.FILE)); |
| 80 |
1 |
int numpdb = 0; |
| 81 |
1 |
for (SequenceI sq : al.getSequences()) |
| 82 |
|
{ |
| 83 |
206 |
if (sq.getAllPDBEntries() != null) |
| 84 |
|
{ |
| 85 |
206 |
numpdb += sq.getAllPDBEntries().size(); |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
1 |
assertTrue( |
| 89 |
|
"PF00111 seed alignment has at least 1 PDB file, but the reader found none.", |
| 90 |
|
numpdb > 0); |
| 91 |
|
} |
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 93 |
1 |
@Test(groups = { "Functional" })... |
| 94 |
|
public void rfamFileIO() throws Exception |
| 95 |
|
{ |
| 96 |
1 |
testFileIOwithFormat(new File(RfamFile), FileFormat.Stockholm, 2, 1, |
| 97 |
|
false, false, false); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 104 |
1 |
@Test(groups = { "Functional" })... |
| 105 |
|
public void dbrefOutput() throws Exception |
| 106 |
|
{ |
| 107 |
|
|
| 108 |
|
|
| 109 |
1 |
SequenceI sq = new Sequence("FER2_SPIOL", "AASSDDDFFF"); |
| 110 |
1 |
sq.addDBRef(new DBRefEntry("UNIPROT", "1", "P00224")); |
| 111 |
1 |
sq.addDBRef(new DBRefEntry("PFAM", "1", "P00224.1")); |
| 112 |
1 |
sq.addDBRef(new DBRefEntry("PFAM", "1", "PF00111")); |
| 113 |
1 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
| 114 |
1 |
String toStockholm = af.formatSequences(FileFormat.Stockholm, |
| 115 |
|
new Alignment(new SequenceI[] |
| 116 |
|
{ sq }), false); |
| 117 |
1 |
System.out.println(toStockholm); |
| 118 |
|
|
| 119 |
1 |
assertTrue( |
| 120 |
|
Pattern.compile( |
| 121 |
|
"^#=GS\\s+FER2_SPIOL(/\\d+-\\d+)?\\s+AC\\s+P00224$", |
| 122 |
|
Pattern.MULTILINE).matcher(toStockholm).find(), |
| 123 |
|
"Couldn't locate UNIPROT Accession in generated Stockholm file."); |
| 124 |
1 |
AlignmentI fromStockholm = af.readFile(toStockholm, |
| 125 |
|
DataSourceType.PASTE, FileFormat.Stockholm); |
| 126 |
1 |
SequenceI importedSeq = fromStockholm.getSequenceAt(0); |
| 127 |
1 |
assertTrue(importedSeq.getDBRefs().size() == 1, |
| 128 |
|
"Expected just one database reference to be added to sequence."); |
| 129 |
1 |
assertTrue( |
| 130 |
|
importedSeq.getDBRefs().get(0).getAccessionId() |
| 131 |
|
.indexOf(" ") == -1, |
| 132 |
|
"Spaces were found in accession ID."); |
| 133 |
1 |
List<DBRefEntry> dbrefs = DBRefUtils.searchRefs(importedSeq.getDBRefs(), |
| 134 |
|
"P00224"); |
| 135 |
1 |
assertTrue(dbrefs.size() == 1, |
| 136 |
|
"Couldn't find Uniprot DBRef on re-imported sequence."); |
| 137 |
|
|
| 138 |
|
} |
| 139 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 140 |
1 |
@Test(groups = { "Functional" })... |
| 141 |
|
public void descriptionLineOutput() throws Exception |
| 142 |
|
{ |
| 143 |
|
|
| 144 |
|
|
| 145 |
1 |
SequenceI sq = new Sequence("FER2_SPIOL", "AASSDDDFFF"); |
| 146 |
1 |
String expected_descr = "This is a description !@&^%@£@"; |
| 147 |
1 |
sq.setDescription(expected_descr); |
| 148 |
1 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
| 149 |
1 |
String toStockholm = af.formatSequences(FileFormat.Stockholm, |
| 150 |
|
new Alignment(new SequenceI[] |
| 151 |
|
{ sq }), false); |
| 152 |
1 |
System.out.println(toStockholm); |
| 153 |
|
|
| 154 |
|
|
| 155 |
1 |
assertTrue(toStockholm.contains(expected_descr), |
| 156 |
|
"Couldn't locate expected description srting in generated Stockholm file."); |
| 157 |
|
|
| 158 |
1 |
AlignmentI fromStockholm = af.readFile(toStockholm, |
| 159 |
|
DataSourceType.PASTE, FileFormat.Stockholm); |
| 160 |
1 |
SequenceI importedSeq = fromStockholm.getSequenceAt(0); |
| 161 |
1 |
assertEquals("Description did not get reimported.", expected_descr, |
| 162 |
|
importedSeq.getDescription()); |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
@param |
| 170 |
|
|
| 171 |
|
@param |
| 172 |
|
|
| 173 |
|
|
| 174 |
|
@param |
| 175 |
|
@param |
| 176 |
|
@param |
| 177 |
|
|
| 178 |
|
|
| |
|
| 93.8% |
Uncovered Elements: 2 (32) |
Complexity: 5 |
Complexity Density: 0.19 |
|
| 179 |
3 |
public static void testFileIOwithFormat(File f, FileFormatI ioformat,... |
| 180 |
|
int naliannot, int nminseqann, boolean ignoreFeatures, |
| 181 |
|
boolean ignoreRowVisibility, boolean allowNullAnnotations) |
| 182 |
|
{ |
| 183 |
3 |
System.out.println("Reading file: " + f); |
| 184 |
3 |
String ff = f.getPath(); |
| 185 |
3 |
try |
| 186 |
|
{ |
| 187 |
3 |
AppletFormatAdapter rf = new AppletFormatAdapter(); |
| 188 |
|
|
| 189 |
3 |
AlignmentI al = rf.readFile(ff, DataSourceType.FILE, |
| 190 |
|
new IdentifyFile().identify(ff, DataSourceType.FILE)); |
| 191 |
|
|
| 192 |
3 |
assertNotNull("Couldn't read supplied alignment data.", al); |
| 193 |
|
|
| 194 |
|
|
| 195 |
272 |
for (int i = 0; i < al.getSequencesArray().length; ++i) |
| 196 |
|
{ |
| 197 |
269 |
al.getSequenceAt(i).createDatasetSequence(); |
| 198 |
|
} |
| 199 |
3 |
String outputfile = rf.formatSequences(ioformat, al, true); |
| 200 |
3 |
System.out.println("Output file in '" + ioformat + "':\n" + outputfile |
| 201 |
|
+ "\n<<EOF\n"); |
| 202 |
|
|
| 203 |
3 |
AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile, |
| 204 |
|
DataSourceType.PASTE, ioformat); |
| 205 |
3 |
assertNotNull("Couldn't parse reimported alignment data.", al_input); |
| 206 |
|
|
| 207 |
3 |
FileFormatI identifyoutput = new IdentifyFile().identify(outputfile, |
| 208 |
|
DataSourceType.PASTE); |
| 209 |
3 |
assertNotNull("Identify routine failed for outputformat " + ioformat, |
| 210 |
|
identifyoutput); |
| 211 |
3 |
assertTrue( |
| 212 |
|
"Identify routine could not recognise output generated by '" |
| 213 |
|
+ ioformat + "' writer", |
| 214 |
|
ioformat.equals(identifyoutput)); |
| 215 |
3 |
testAlignmentEquivalence(al, al_input, ignoreFeatures, |
| 216 |
|
ignoreRowVisibility, allowNullAnnotations); |
| 217 |
3 |
int numaliannot = 0, numsqswithali = 0; |
| 218 |
3 |
for (AlignmentAnnotation ala : al_input.getAlignmentAnnotation()) |
| 219 |
|
{ |
| 220 |
80 |
if (ala.sequenceRef == null) |
| 221 |
|
{ |
| 222 |
4 |
numaliannot++; |
| 223 |
|
} |
| 224 |
|
else |
| 225 |
|
{ |
| 226 |
76 |
numsqswithali++; |
| 227 |
|
} |
| 228 |
|
} |
| 229 |
3 |
if (naliannot > -1) |
| 230 |
|
{ |
| 231 |
1 |
assertEquals("Number of alignment annotations", naliannot, |
| 232 |
|
numaliannot); |
| 233 |
|
} |
| 234 |
|
|
| 235 |
3 |
assertTrue( |
| 236 |
|
"Number of sequence associated annotations wasn't at least " |
| 237 |
|
+ nminseqann, |
| 238 |
|
numsqswithali >= nminseqann); |
| 239 |
|
|
| 240 |
|
} catch (Exception e) |
| 241 |
|
{ |
| 242 |
0 |
e.printStackTrace(); |
| 243 |
0 |
assertTrue("Couln't format the alignment for output file.", false); |
| 244 |
|
} |
| 245 |
|
} |
| 246 |
|
|
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
@param |
| 251 |
|
|
| 252 |
|
@param |
| 253 |
|
|
| 254 |
|
|
| 255 |
|
@param |
| 256 |
|
|
| 257 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 258 |
0 |
public static void testAlignmentEquivalence(AlignmentI al,... |
| 259 |
|
AlignmentI al_input, boolean ignoreFeatures) |
| 260 |
|
{ |
| 261 |
0 |
testAlignmentEquivalence(al, al_input, ignoreFeatures, false, false); |
| 262 |
|
} |
| 263 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
|
| 267 |
|
|
| 268 |
|
@param |
| 269 |
|
|
| 270 |
|
@param |
| 271 |
|
|
| 272 |
|
|
| 273 |
|
@param |
| 274 |
|
|
| 275 |
|
|
| 276 |
|
@param |
| 277 |
|
|
| 278 |
|
|
| 279 |
|
@param |
| 280 |
|
|
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
| 284 |
|
|
| |
|
| 90.4% |
Uncovered Elements: 11 (114) |
Complexity: 32 |
Complexity Density: 0.46 |
|
| 285 |
15 |
public static void testAlignmentEquivalence(AlignmentI al,... |
| 286 |
|
AlignmentI al_input, boolean ignoreFeatures, |
| 287 |
|
boolean ignoreRowVisibility, boolean allowNullAnnotation) |
| 288 |
|
{ |
| 289 |
15 |
assertNotNull("Original alignment was null", al); |
| 290 |
15 |
assertNotNull("Generated alignment was null", al_input); |
| 291 |
|
|
| 292 |
15 |
assertTrue( |
| 293 |
|
"Alignment dimension mismatch: original: " + al.getHeight() |
| 294 |
|
+ "x" + al.getWidth() + ", generated: " |
| 295 |
|
+ al_input.getHeight() + "x" + al_input.getWidth(), |
| 296 |
|
al.getHeight() == al_input.getHeight() |
| 297 |
|
&& al.getWidth() == al_input.getWidth()); |
| 298 |
|
|
| 299 |
|
|
| 300 |
15 |
AlignmentAnnotation[] aa_new = al_input.getAlignmentAnnotation(); |
| 301 |
15 |
AlignmentAnnotation[] aa_original = al.getAlignmentAnnotation(); |
| 302 |
15 |
boolean expectProteinSS = !al.isNucleotide(); |
| 303 |
15 |
assertTrue( |
| 304 |
|
"Alignments not both " |
| 305 |
15 |
+ (al.isNucleotide() ? "nucleotide" : "protein"), |
| 306 |
|
al_input.isNucleotide() == al.isNucleotide()); |
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
|
| 311 |
15 |
int aa_new_size = (aa_new == null ? 0 : aa_new.length); |
| 312 |
15 |
int aa_original_size = (aa_original == null ? 0 : aa_original.length); |
| 313 |
15 |
Map<Integer, BitSet> orig_groups = new HashMap<>(); |
| 314 |
15 |
Map<Integer, BitSet> new_groups = new HashMap<>(); |
| 315 |
|
|
| 316 |
15 |
if (aa_new != null && aa_original != null) |
| 317 |
|
{ |
| 318 |
187 |
for (int i = 0; i < aa_original.length; i++) |
| 319 |
|
{ |
| 320 |
175 |
if (aa_new.length > i) |
| 321 |
|
{ |
| 322 |
175 |
assertEqualSecondaryStructure( |
| 323 |
|
"Different alignment annotation at position " + i, |
| 324 |
|
aa_original[i], aa_new[i], allowNullAnnotation); |
| 325 |
175 |
if (aa_original[i].hasIcons) |
| 326 |
|
{ |
| 327 |
85 |
assertTrue( |
| 328 |
|
"Secondary structure expected to be " |
| 329 |
85 |
+ (expectProteinSS ? "protein" : "nucleotide"), |
| 330 |
|
expectProteinSS == !aa_original[i].isRNA()); |
| 331 |
|
} |
| 332 |
|
|
| 333 |
175 |
assertEquals("Graph type not identical.", aa_original[i].graph, |
| 334 |
|
aa_new[i].graph); |
| 335 |
175 |
if (!ignoreRowVisibility) |
| 336 |
|
{ |
| 337 |
170 |
assertEquals("Visibility not identical.", |
| 338 |
|
aa_original[i].visible, aa_new[i].visible); |
| 339 |
|
} |
| 340 |
175 |
assertEquals("Threshold line not identical.", |
| 341 |
|
aa_original[i].threshold, aa_new[i].threshold); |
| 342 |
|
|
| 343 |
175 |
Integer o_ggrp = Integer.valueOf(aa_original[i].graphGroup + 2); |
| 344 |
175 |
Integer n_ggrp = Integer.valueOf(aa_new[i].graphGroup + 2); |
| 345 |
175 |
BitSet orig_g = orig_groups.get(o_ggrp); |
| 346 |
175 |
BitSet new_g = new_groups.get(n_ggrp); |
| 347 |
175 |
if (orig_g == null) |
| 348 |
|
{ |
| 349 |
47 |
orig_groups.put(o_ggrp, orig_g = new BitSet()); |
| 350 |
|
} |
| 351 |
175 |
if (new_g == null) |
| 352 |
|
{ |
| 353 |
47 |
new_groups.put(n_ggrp, new_g = new BitSet()); |
| 354 |
|
} |
| 355 |
175 |
assertEquals("Graph Group pattern differs at annotation " + i, |
| 356 |
|
orig_g, new_g); |
| 357 |
175 |
orig_g.set(i); |
| 358 |
175 |
new_g.set(i); |
| 359 |
|
} |
| 360 |
|
else |
| 361 |
|
{ |
| 362 |
0 |
System.err.println("No matching annotation row for " |
| 363 |
|
+ aa_original[i].toString()); |
| 364 |
|
} |
| 365 |
|
} |
| 366 |
|
} |
| 367 |
15 |
assertEquals( |
| 368 |
|
"Generated and imported alignment have different annotation sets", |
| 369 |
|
aa_original_size, aa_new_size); |
| 370 |
|
|
| 371 |
|
|
| 372 |
15 |
SequenceI[] seq_original = new SequenceI[al.getSequencesArray().length]; |
| 373 |
15 |
seq_original = al.getSequencesArray(); |
| 374 |
15 |
SequenceI[] seq_new = new SequenceI[al_input |
| 375 |
|
.getSequencesArray().length]; |
| 376 |
15 |
seq_new = al_input.getSequencesArray(); |
| 377 |
15 |
List<SequenceFeature> sequenceFeatures_original; |
| 378 |
15 |
List<SequenceFeature> sequenceFeatures_new; |
| 379 |
15 |
AlignmentAnnotation annot_original, annot_new; |
| 380 |
|
|
| 381 |
412 |
for (int i = 0; i < al.getSequencesArray().length; i++) |
| 382 |
|
{ |
| 383 |
397 |
String name = seq_original[i].getName(); |
| 384 |
397 |
int start = seq_original[i].getStart(); |
| 385 |
397 |
int end = seq_original[i].getEnd(); |
| 386 |
397 |
System.out |
| 387 |
|
.println("Check sequence: " + name + "/" + start + "-" + end); |
| 388 |
|
|
| 389 |
|
|
| 390 |
24168 |
for (int in = 0; in < al_input.getSequencesArray().length; in++) |
| 391 |
|
{ |
| 392 |
24168 |
if (name.equals(seq_new[in].getName()) |
| 393 |
|
&& start == seq_new[in].getStart() |
| 394 |
|
&& end == seq_new[in].getEnd()) |
| 395 |
|
{ |
| 396 |
397 |
String ss_original = seq_original[i].getSequenceAsString(); |
| 397 |
397 |
String ss_new = seq_new[in].getSequenceAsString(); |
| 398 |
397 |
assertEquals("The sequences " + name + "/" + start + "-" + end |
| 399 |
|
+ " are not equal", ss_original, ss_new); |
| 400 |
|
|
| 401 |
397 |
assertTrue( |
| 402 |
|
"Sequence Features were not equivalent" |
| 403 |
397 |
+ (ignoreFeatures ? " ignoring." : ""), |
| 404 |
|
ignoreFeatures |
| 405 |
|
|| (seq_original[i].getSequenceFeatures() == null |
| 406 |
|
&& seq_new[in] |
| 407 |
|
.getSequenceFeatures() == null) |
| 408 |
|
|| (seq_original[i].getSequenceFeatures() != null |
| 409 |
|
&& seq_new[in] |
| 410 |
|
.getSequenceFeatures() != null)); |
| 411 |
|
|
| 412 |
397 |
if (!ignoreFeatures |
| 413 |
|
&& seq_original[i].getSequenceFeatures() != null |
| 414 |
|
&& seq_new[in].getSequenceFeatures() != null) |
| 415 |
|
{ |
| 416 |
392 |
System.out.println("Checking feature equivalence."); |
| 417 |
392 |
sequenceFeatures_original = seq_original[i] |
| 418 |
|
.getSequenceFeatures(); |
| 419 |
392 |
sequenceFeatures_new = seq_new[in].getSequenceFeatures(); |
| 420 |
|
|
| 421 |
392 |
assertEquals("different number of features", |
| 422 |
|
seq_original[i].getSequenceFeatures().size(), |
| 423 |
|
seq_new[in].getSequenceFeatures().size()); |
| 424 |
|
|
| 425 |
392 |
for (int feat = 0; feat < seq_original[i].getSequenceFeatures() |
| 426 |
|
.size(); feat++) |
| 427 |
|
{ |
| 428 |
0 |
assertEquals("Different features", |
| 429 |
|
sequenceFeatures_original.get(feat), |
| 430 |
|
sequenceFeatures_new.get(feat)); |
| 431 |
|
} |
| 432 |
|
} |
| 433 |
|
|
| 434 |
397 |
if (al.getSequenceAt(i).getAnnotation() != null |
| 435 |
|
&& al_input.getSequenceAt(in).getAnnotation() != null) |
| 436 |
|
{ |
| 437 |
278 |
for (int j = 0; j < al.getSequenceAt(i) |
| 438 |
|
.getAnnotation().length; j++) |
| 439 |
|
{ |
| 440 |
165 |
if (al.getSequenceAt(i).getAnnotation()[j] != null && al_input |
| 441 |
|
.getSequenceAt(in).getAnnotation()[j] != null) |
| 442 |
|
{ |
| 443 |
165 |
annot_original = al.getSequenceAt(i).getAnnotation()[j]; |
| 444 |
165 |
annot_new = al_input.getSequenceAt(in).getAnnotation()[j]; |
| 445 |
165 |
assertEqualSecondaryStructure( |
| 446 |
|
"Different annotation elements", annot_original, |
| 447 |
|
annot_new, allowNullAnnotation); |
| 448 |
|
} |
| 449 |
|
} |
| 450 |
|
} |
| 451 |
284 |
else if (al.getSequenceAt(i).getAnnotation() == null |
| 452 |
|
&& al_input.getSequenceAt(in).getAnnotation() == null) |
| 453 |
|
{ |
| 454 |
284 |
System.out.println("No annotations"); |
| 455 |
|
} |
| 456 |
0 |
else if (al.getSequenceAt(i).getAnnotation() != null |
| 457 |
|
&& al_input.getSequenceAt(in).getAnnotation() == null) |
| 458 |
|
{ |
| 459 |
0 |
fail("Annotations differed between sequences (" |
| 460 |
|
+ al.getSequenceAt(i).getName() + ") and (" |
| 461 |
|
+ al_input.getSequenceAt(i).getName() + ")"); |
| 462 |
|
} |
| 463 |
397 |
break; |
| 464 |
|
} |
| 465 |
|
} |
| 466 |
|
} |
| 467 |
|
} |
| 468 |
|
|
| 469 |
|
|
| 470 |
|
|
| 471 |
|
|
| 472 |
|
|
| 473 |
|
|
| 474 |
|
|
| 475 |
|
@param |
| 476 |
|
|
| 477 |
|
@param |
| 478 |
|
|
| 479 |
|
@param |
| 480 |
|
|
| 481 |
|
@param |
| 482 |
|
|
| 483 |
|
|
| 484 |
|
|
| 485 |
|
|
| |
|
| 87.5% |
Uncovered Elements: 6 (48) |
Complexity: 31 |
Complexity Density: 1.41 |
|
| 486 |
390 |
private static void assertEqualSecondaryStructure(String message,... |
| 487 |
|
AlignmentAnnotation annot_or, AlignmentAnnotation annot_new, |
| 488 |
|
boolean allowNullEqivalence) |
| 489 |
|
{ |
| 490 |
|
|
| 491 |
|
|
| 492 |
390 |
if (annot_or.annotations.length != annot_new.annotations.length) |
| 493 |
|
{ |
| 494 |
0 |
fail("Different lengths for annotation row elements: " |
| 495 |
|
+ annot_or.annotations.length + "!=" |
| 496 |
|
+ annot_new.annotations.length); |
| 497 |
|
} |
| 498 |
390 |
assertTrue("Expected identical 'Number of Sequences Included'", |
| 499 |
|
annot_or.getNoOfSequencesIncluded() == annot_new |
| 500 |
|
.getNoOfSequencesIncluded()); |
| 501 |
390 |
assertTrue("Expected identical 'Number of Tracks Included'", annot_or |
| 502 |
|
.getNoOfTracksIncluded() == annot_new.getNoOfTracksIncluded()); |
| 503 |
390 |
boolean isRna = annot_or.isRNA(); |
| 504 |
390 |
assertTrue( |
| 505 |
390 |
"Expected " + (isRna ? " valid RNA " : " no RNA ") |
| 506 |
|
+ " secondary structure in the row.", |
| 507 |
|
isRna == annot_new.isRNA()); |
| 508 |
44588 |
for (int i = 0; i < annot_or.annotations.length; i++) |
| 509 |
|
{ |
| 510 |
44226 |
Annotation an_or = annot_or.annotations[i], |
| 511 |
|
an_new = annot_new.annotations[i]; |
| 512 |
44226 |
if (an_or != null && an_new != null) |
| 513 |
|
{ |
| 514 |
|
|
| 515 |
29028 |
if (isRna) |
| 516 |
|
{ |
| 517 |
9141 |
if (an_or.secondaryStructure != an_new.secondaryStructure |
| 518 |
|
|| ((Float.isNaN(an_or.value) != Float |
| 519 |
|
.isNaN(an_new.value)) |
| 520 |
|
|| an_or.value != an_new.value)) |
| 521 |
|
{ |
| 522 |
0 |
fail("Different RNA secondary structure at column " + i |
| 523 |
|
+ " expected: [" + annot_or.annotations[i].toString() |
| 524 |
|
+ "] but got: [" + annot_new.annotations[i].toString() |
| 525 |
|
+ "]"); |
| 526 |
|
} |
| 527 |
|
} |
| 528 |
|
else |
| 529 |
|
{ |
| 530 |
|
|
| 531 |
19887 |
if ((an_or.isWhitespace() != an_new.isWhitespace()) |
| 532 |
|
|| !an_or.displayCharacter.trim() |
| 533 |
|
.equals(an_new.displayCharacter.trim()) |
| 534 |
|
|| !("" + an_or.secondaryStructure).trim() |
| 535 |
|
.equals(("" + an_new.secondaryStructure).trim()) |
| 536 |
|
|| (an_or.description != an_new.description |
| 537 |
|
&& !((an_or.description == null |
| 538 |
|
&& an_new.description.trim() |
| 539 |
|
.length() == 0) |
| 540 |
|
|| (an_new.description == null |
| 541 |
|
&& an_or.description.trim() |
| 542 |
|
.length() == 0) |
| 543 |
|
|| an_or.description.trim().equals( |
| 544 |
|
an_new.description.trim()))) |
| 545 |
|
|| !((Float.isNaN(an_or.value) |
| 546 |
|
&& Float.isNaN(an_new.value)) |
| 547 |
|
|| an_or.value == an_new.value)) |
| 548 |
|
{ |
| 549 |
12 |
fail("Annotation Element Mismatch\nElement " + i |
| 550 |
|
+ " in original: " + annot_or.annotations[i].toString() |
| 551 |
|
+ "\nElement " + i + " in new: " |
| 552 |
|
+ annot_new.annotations[i].toString()); |
| 553 |
|
} |
| 554 |
|
} |
| 555 |
|
} |
| 556 |
15198 |
else if (annot_or.annotations[i] == null |
| 557 |
|
&& annot_new.annotations[i] == null) |
| 558 |
|
{ |
| 559 |
15130 |
continue; |
| 560 |
|
} |
| 561 |
|
else |
| 562 |
|
{ |
| 563 |
68 |
if (allowNullEqivalence) |
| 564 |
|
{ |
| 565 |
65 |
if (an_or != null && an_or.isWhitespace()) |
| 566 |
|
|
| 567 |
|
{ |
| 568 |
0 |
continue; |
| 569 |
|
} |
| 570 |
65 |
if (an_new != null && an_new.isWhitespace()) |
| 571 |
|
{ |
| 572 |
62 |
continue; |
| 573 |
|
} |
| 574 |
|
} |
| 575 |
|
|
| 576 |
6 |
fail("Annotation Element Mismatch\nElement " + i + " in original: " |
| 577 |
6 |
+ (an_or == null ? "is null" : an_or.toString()) |
| 578 |
|
+ "\nElement " + i + " in new: " |
| 579 |
6 |
+ (an_new == null ? "is null" : an_new.toString())); |
| 580 |
|
} |
| 581 |
|
} |
| 582 |
|
} |
| 583 |
|
|
| 584 |
|
|
| 585 |
|
@see |
| 586 |
|
|
| 587 |
|
@param |
| 588 |
|
@param |
| 589 |
|
@param |
| 590 |
|
@param |
| 591 |
|
|
| |
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 592 |
28 |
public static void assertNotEqualSecondaryStructure(String message,... |
| 593 |
|
AlignmentAnnotation an_orig, AlignmentAnnotation an_new, |
| 594 |
|
boolean allowNullEquivalence) |
| 595 |
|
{ |
| 596 |
28 |
boolean thrown = false; |
| 597 |
28 |
try |
| 598 |
|
{ |
| 599 |
28 |
assertEqualSecondaryStructure("", an_orig, an_new, |
| 600 |
|
allowNullEquivalence); |
| 601 |
|
} catch (AssertionError af) |
| 602 |
|
{ |
| 603 |
28 |
thrown = true; |
| 604 |
|
} |
| 605 |
28 |
if (!thrown) |
| 606 |
|
{ |
| 607 |
0 |
fail("Expected difference for [" + an_orig + "] and [" + an_new |
| 608 |
|
+ "]"); |
| 609 |
|
} |
| 610 |
|
} |
| 611 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 612 |
26 |
private AlignmentAnnotation makeAnnot(Annotation ae)... |
| 613 |
|
{ |
| 614 |
26 |
return new AlignmentAnnotation("label", "description", |
| 615 |
|
new Annotation[] |
| 616 |
|
{ ae }); |
| 617 |
|
} |
| 618 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 4 |
Complexity Density: 0.14 |
1PASS
|
|
| 619 |
1 |
@Test(groups = { "Functional" })... |
| 620 |
|
public void testAnnotationEquivalence() |
| 621 |
|
{ |
| 622 |
1 |
AlignmentAnnotation one = makeAnnot(new Annotation("", "", ' ', 1)); |
| 623 |
1 |
AlignmentAnnotation anotherOne = makeAnnot( |
| 624 |
|
new Annotation("", "", ' ', 1)); |
| 625 |
1 |
AlignmentAnnotation sheet = makeAnnot(new Annotation("", "", 'E', 0f)); |
| 626 |
1 |
AlignmentAnnotation anotherSheet = makeAnnot( |
| 627 |
|
new Annotation("", "", 'E', 0f)); |
| 628 |
1 |
AlignmentAnnotation sheetWithLabel = makeAnnot( |
| 629 |
|
new Annotation("1", "", 'E', 0f)); |
| 630 |
1 |
AlignmentAnnotation anotherSheetWithLabel = makeAnnot( |
| 631 |
|
new Annotation("1", "", 'E', 0f)); |
| 632 |
1 |
AlignmentAnnotation rnaNoDC = makeAnnot( |
| 633 |
|
new Annotation("", "", '<', 0f)); |
| 634 |
1 |
AlignmentAnnotation anotherRnaNoDC = makeAnnot( |
| 635 |
|
new Annotation("", "", '<', 0f)); |
| 636 |
1 |
AlignmentAnnotation rnaWithDC = makeAnnot( |
| 637 |
|
new Annotation("B", "", '<', 0f)); |
| 638 |
1 |
AlignmentAnnotation anotherRnaWithDC = makeAnnot( |
| 639 |
|
new Annotation("B", "", '<', 0f)); |
| 640 |
|
|
| 641 |
|
|
| 642 |
1 |
for (boolean allowNull : new boolean[] { true, false }) |
| 643 |
|
{ |
| 644 |
2 |
assertEqualSecondaryStructure("Should be equal", one, anotherOne, |
| 645 |
|
allowNull); |
| 646 |
2 |
assertEqualSecondaryStructure("Should be equal", sheet, anotherSheet, |
| 647 |
|
allowNull); |
| 648 |
2 |
assertEqualSecondaryStructure("Should be equal", sheetWithLabel, |
| 649 |
|
anotherSheetWithLabel, allowNull); |
| 650 |
2 |
assertEqualSecondaryStructure("Should be equal", rnaNoDC, |
| 651 |
|
anotherRnaNoDC, allowNull); |
| 652 |
2 |
assertEqualSecondaryStructure("Should be equal", rnaWithDC, |
| 653 |
|
anotherRnaWithDC, allowNull); |
| 654 |
|
|
| 655 |
2 |
assertEqualSecondaryStructure("Should be equal", rnaWithDC, rnaNoDC, |
| 656 |
|
allowNull); |
| 657 |
2 |
assertEqualSecondaryStructure("Should be equal", rnaNoDC, rnaWithDC, |
| 658 |
|
allowNull); |
| 659 |
|
} |
| 660 |
|
|
| 661 |
|
|
| 662 |
1 |
List<AlignmentAnnotation> aaSet = Arrays.asList(one, sheet, |
| 663 |
|
sheetWithLabel, rnaWithDC); |
| 664 |
5 |
for (int p = 0; p < aaSet.size(); p++) |
| 665 |
|
{ |
| 666 |
20 |
for (int q = 0; q < aaSet.size(); q++) |
| 667 |
|
{ |
| 668 |
16 |
if (p != q) |
| 669 |
|
{ |
| 670 |
12 |
assertNotEqualSecondaryStructure("Should be different", |
| 671 |
|
aaSet.get(p), aaSet.get(q), false); |
| 672 |
|
} |
| 673 |
|
else |
| 674 |
|
{ |
| 675 |
4 |
assertEqualSecondaryStructure("Should be same", aaSet.get(p), |
| 676 |
|
aaSet.get(q), false); |
| 677 |
4 |
assertEqualSecondaryStructure("Should be same", aaSet.get(p), |
| 678 |
|
aaSet.get(q), true); |
| 679 |
4 |
assertNotEqualSecondaryStructure( |
| 680 |
|
"Should be different to empty anot", aaSet.get(p), |
| 681 |
|
makeAnnot(Annotation.EMPTY_ANNOTATION), false); |
| 682 |
4 |
assertNotEqualSecondaryStructure( |
| 683 |
|
"Should be different to empty annot", |
| 684 |
|
makeAnnot(Annotation.EMPTY_ANNOTATION), aaSet.get(q), |
| 685 |
|
true); |
| 686 |
4 |
assertNotEqualSecondaryStructure("Should be different to null", |
| 687 |
|
aaSet.get(p), makeAnnot(null), false); |
| 688 |
4 |
assertNotEqualSecondaryStructure("Should be different to null", |
| 689 |
|
makeAnnot(null), aaSet.get(q), true); |
| 690 |
|
} |
| 691 |
|
} |
| 692 |
|
} |
| 693 |
|
|
| 694 |
|
|
| 695 |
|
|
| 696 |
|
} |
| 697 |
|
|
| 698 |
|
String aliFile = ">Dm\nAAACCCUUUUACACACGGGAAAGGG"; |
| 699 |
|
|
| 700 |
|
String annFile = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
| 701 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
| 702 |
|
+ "(|(|(|(|, .|, .|, .|, .|)|)|)|)|\t0.0\nROWPROPERTIES\t" |
| 703 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
| 704 |
|
|
| 705 |
|
String annFileCurlyWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
| 706 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
| 707 |
|
+ "(|(|(|(||{|{||{|{||)|)|)|)||}|}|}|}|\t0.0\nROWPROPERTIES\t" |
| 708 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
| 709 |
|
|
| 710 |
|
String annFileFullWuss = "JALVIEW_ANNOTATION\n# Created: Thu May 04 11:16:52 BST 2017\n\n" |
| 711 |
|
+ "SEQUENCE_REF\tDm\nNO_GRAPH\tsecondary structure\tsecondary structure\t" |
| 712 |
|
+ "(|(|(|(||{|{||[|[||)|)|)|)||}|}|]|]|\t0.0\nROWPROPERTIES\t" |
| 713 |
|
+ "secondary structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false"; |
| 714 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 715 |
1 |
@Test(groups = { "Functional" })... |
| 716 |
|
public void secondaryStructureForRNASequence() throws Exception |
| 717 |
|
{ |
| 718 |
1 |
roundTripSSForRNA(aliFile, annFile); |
| 719 |
|
} |
| 720 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 721 |
1 |
@Test(groups = { "Functional" })... |
| 722 |
|
public void curlyWUSSsecondaryStructureForRNASequence() throws Exception |
| 723 |
|
{ |
| 724 |
1 |
roundTripSSForRNA(aliFile, annFileCurlyWuss); |
| 725 |
|
} |
| 726 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 727 |
1 |
@Test(groups = { "Functional" })... |
| 728 |
|
public void fullWUSSsecondaryStructureForRNASequence() throws Exception |
| 729 |
|
{ |
| 730 |
1 |
roundTripSSForRNA(aliFile, annFileFullWuss); |
| 731 |
|
} |
| 732 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 733 |
1 |
@Test(groups = { "Functional" })... |
| 734 |
|
public void detectWussBrackets() |
| 735 |
|
{ |
| 736 |
1 |
for (char ch : new char[] { '{', '}', '[', ']', '(', ')', '<', '>' }) |
| 737 |
|
{ |
| 738 |
8 |
Assert.assertTrue(StockholmFile.RNASS_BRACKETS.indexOf(ch) >= 0, |
| 739 |
|
"Didn't recognise '" + ch + "' as a WUSS bracket"); |
| 740 |
|
} |
| 741 |
1 |
for (char ch : new char[] { '@', '!', '*', ' ', '-', '.' }) |
| 742 |
|
{ |
| 743 |
6 |
Assert.assertFalse(StockholmFile.RNASS_BRACKETS.indexOf(ch) >= 0, |
| 744 |
|
"Shouldn't recognise '" + ch + "' as a WUSS bracket"); |
| 745 |
|
} |
| 746 |
|
} |
| 747 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 748 |
3 |
private static void roundTripSSForRNA(String aliFile, String annFile)... |
| 749 |
|
throws Exception |
| 750 |
|
{ |
| 751 |
3 |
AlignmentI al = new AppletFormatAdapter().readFile(aliFile, |
| 752 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Fasta); |
| 753 |
3 |
AnnotationFile aaf = new AnnotationFile(); |
| 754 |
3 |
aaf.readAnnotationFile(al, annFile, DataSourceType.PASTE); |
| 755 |
3 |
al.getAlignmentAnnotation()[0].visible = true; |
| 756 |
|
|
| 757 |
|
|
| 758 |
3 |
StockholmFile sf = new StockholmFile(al); |
| 759 |
|
|
| 760 |
3 |
String stockholmFile = sf.print(al.getSequencesArray(), true); |
| 761 |
|
|
| 762 |
3 |
AlignmentI newAl = new AppletFormatAdapter().readFile(stockholmFile, |
| 763 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Stockholm); |
| 764 |
|
|
| 765 |
|
|
| 766 |
|
|
| 767 |
3 |
testAlignmentEquivalence(al, newAl, true, true, true); |
| 768 |
|
|
| 769 |
|
} |
| 770 |
|
|
| 771 |
|
|
| 772 |
|
|
| 773 |
|
String aliFileRnaSS = ">Test.sequence/1-14\n" + "GUACAAAAAAAAAA"; |
| 774 |
|
|
| 775 |
|
String annFileRnaSSAlphaChars = "JALVIEW_ANNOTATION\n" |
| 776 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
| 777 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|(,(|E,E|H,H|B,B|h,h|e,e|b,b|(,(|E,E|),)|e,e|),)|>,>|\t2.0\n" |
| 778 |
|
+ "\n" |
| 779 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
| 780 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
| 781 |
|
|
| 782 |
|
String wrongAnnFileRnaSSAlphaChars = "JALVIEW_ANNOTATION\n" |
| 783 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
| 784 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|(,(|H,H|E,E|B,B|h,h|e,e|b,b|(,(|E,E|),)|e,e|),)|>,>|\t2.0\n" |
| 785 |
|
+ "\n" |
| 786 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
| 787 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
| 788 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 2 |
Complexity Density: 0.1 |
1PASS
|
|
| 789 |
1 |
@Test(groups = { "Functional" })... |
| 790 |
|
public void stockholmFileRnaSSAlphaChars() throws Exception |
| 791 |
|
{ |
| 792 |
1 |
AppletFormatAdapter af = new AppletFormatAdapter(); |
| 793 |
1 |
AlignmentI al = af.readFile(RnaSSTestFile, DataSourceType.FILE, |
| 794 |
|
jalview.io.FileFormat.Stockholm); |
| 795 |
1 |
Iterable<AlignmentAnnotation> aai = al.findAnnotations(null, null, |
| 796 |
|
"Secondary Structure"); |
| 797 |
1 |
AlignmentAnnotation aa = aai.iterator().next(); |
| 798 |
1 |
Assert.assertTrue(aa.isRNA(), |
| 799 |
|
"'" + RnaSSTestFile + "' not recognised as RNA SS"); |
| 800 |
1 |
Assert.assertTrue(aa.isValidStruc(), |
| 801 |
|
"'" + RnaSSTestFile + "' not recognised as valid structure"); |
| 802 |
1 |
Annotation[] as = aa.annotations; |
| 803 |
1 |
char[] As = new char[as.length]; |
| 804 |
15 |
for (int i = 0; i < as.length; i++) |
| 805 |
|
{ |
| 806 |
14 |
As[i] = as[i].secondaryStructure; |
| 807 |
|
} |
| 808 |
1 |
char[] shouldBe = { '<', '(', 'E', 'H', 'B', 'h', 'e', 'b', '(', 'E', |
| 809 |
|
')', 'e', ')', '>' }; |
| 810 |
1 |
Assert.assertTrue(Arrays.equals(As, shouldBe), "Annotation is " |
| 811 |
|
+ new String(As) + " but should be " + new String(shouldBe)); |
| 812 |
|
|
| 813 |
|
|
| 814 |
1 |
AlignmentI newAl = new AppletFormatAdapter().readFile(aliFileRnaSS, |
| 815 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Fasta); |
| 816 |
1 |
AnnotationFile aaf = new AnnotationFile(); |
| 817 |
1 |
aaf.readAnnotationFile(newAl, annFileRnaSSAlphaChars, |
| 818 |
|
DataSourceType.PASTE); |
| 819 |
|
|
| 820 |
1 |
Assert.assertTrue( |
| 821 |
|
testRnaSSAnnotationsEquivalent(al.getAlignmentAnnotation()[0], |
| 822 |
|
newAl.getAlignmentAnnotation()[0]), |
| 823 |
|
"RNA SS Annotations SHOULD be pair-wise equivalent (but apparently aren't): \n" |
| 824 |
|
+ "RNA SS A 1:" + al.getAlignmentAnnotation()[0] + "\n" |
| 825 |
|
+ "RNA SS A 2:" + newAl.getAlignmentAnnotation()[0]); |
| 826 |
|
|
| 827 |
|
|
| 828 |
1 |
newAl = new AppletFormatAdapter().readFile(aliFileRnaSS, |
| 829 |
|
DataSourceType.PASTE, jalview.io.FileFormat.Fasta); |
| 830 |
1 |
aaf = new AnnotationFile(); |
| 831 |
1 |
aaf.readAnnotationFile(newAl, wrongAnnFileRnaSSAlphaChars, |
| 832 |
|
DataSourceType.PASTE); |
| 833 |
|
|
| 834 |
1 |
boolean mismatch = testRnaSSAnnotationsEquivalent( |
| 835 |
|
al.getAlignmentAnnotation()[0], |
| 836 |
|
newAl.getAlignmentAnnotation()[0]); |
| 837 |
1 |
Assert.assertFalse(mismatch, |
| 838 |
|
"RNA SS Annotations SHOULD NOT be pair-wise equivalent (but apparently are): \n" |
| 839 |
|
+ "RNA SS A 1:" + al.getAlignmentAnnotation()[0] + "\n" |
| 840 |
|
+ "RNA SS A 2:" + newAl.getAlignmentAnnotation()[0]); |
| 841 |
|
} |
| 842 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 843 |
4 |
private static boolean testRnaSSAnnotationsEquivalent(... |
| 844 |
|
AlignmentAnnotation a1, AlignmentAnnotation a2) |
| 845 |
|
{ |
| 846 |
4 |
return a1.rnaSecondaryStructureEquivalent(a2); |
| 847 |
|
} |
| 848 |
|
|
| 849 |
|
String annFileRnaSSWithSpaceChars = "JALVIEW_ANNOTATION\n" |
| 850 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
| 851 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|.,.|H,H| , |B,B|h,h| , |b,b|(,(|E,E|.,.|e,e|),)|>,>|\t2.0\n" |
| 852 |
|
+ "\n" |
| 853 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
| 854 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
| 855 |
|
|
| 856 |
|
String annFileRnaSSWithoutSpaceChars = "JALVIEW_ANNOTATION\n" |
| 857 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
| 858 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|.,.|H,H|.,.|B,B|h,h|.,.|b,b|(,(|E,E|.,.|e,e|),)|>,>|\t2.0\n" |
| 859 |
|
+ "\n" |
| 860 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
| 861 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
| 862 |
|
|
| 863 |
|
String wrongAnnFileRnaSSWithoutSpaceChars = "JALVIEW_ANNOTATION\n" |
| 864 |
|
+ "# Created: Thu Aug 02 14:54:57 BST 2018\n" + "\n" |
| 865 |
|
+ "NO_GRAPH\tSecondary Structure\tSecondary Structure\t<,<|.,.|H,H|Z,Z|B,B|h,h|z,z|b,b|(,(|E,E|.,.|e,e|),)|>,>|\t2.0\n" |
| 866 |
|
+ "\n" |
| 867 |
|
+ "ROWPROPERTIES\tSecondary Structure\tscaletofit=true\tshowalllabs=true\tcentrelabs=false\n" |
| 868 |
|
+ "\n" + "\n" + "ALIGNMENT\tID=RNA.SS.TEST\tTP=RNA;"; |
| 869 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 2 |
Complexity Density: 0.07 |
1PASS
|
|
| 870 |
1 |
@Test(groups = { "Functional" })... |
| 871 |
|
public void stockholmFileRnaSSSpaceChars() throws Exception |
| 872 |
|
{ |
| 873 |
1 |
AlignmentI alWithSpaces = new AppletFormatAdapter().readFile( |
| 874 |
|
aliFileRnaSS, DataSourceType.PASTE, |
| 875 |
|
jalview.io.FileFormat.Fasta); |
| 876 |
1 |
AnnotationFile afWithSpaces = new AnnotationFile(); |
| 877 |
1 |
afWithSpaces.readAnnotationFile(alWithSpaces, |
| 878 |
|
annFileRnaSSWithSpaceChars, DataSourceType.PASTE); |
| 879 |
|
|
| 880 |
1 |
Iterable<AlignmentAnnotation> aaiWithSpaces = alWithSpaces |
| 881 |
|
.findAnnotations(null, null, "Secondary Structure"); |
| 882 |
1 |
AlignmentAnnotation aaWithSpaces = aaiWithSpaces.iterator().next(); |
| 883 |
1 |
Assert.assertTrue(aaWithSpaces.isRNA(), |
| 884 |
|
"'" + aaWithSpaces + "' not recognised as RNA SS"); |
| 885 |
1 |
Assert.assertTrue(aaWithSpaces.isValidStruc(), |
| 886 |
|
"'" + aaWithSpaces + "' not recognised as valid structure"); |
| 887 |
1 |
Annotation[] annWithSpaces = aaWithSpaces.annotations; |
| 888 |
1 |
char[] As = new char[annWithSpaces.length]; |
| 889 |
15 |
for (int i = 0; i < annWithSpaces.length; i++) |
| 890 |
|
{ |
| 891 |
14 |
As[i] = annWithSpaces[i].secondaryStructure; |
| 892 |
|
} |
| 893 |
|
|
| 894 |
1 |
char[] shouldBe = { '<', ' ', 'H', ' ', 'B', 'h', ' ', 'b', '(', 'E', |
| 895 |
|
' ', 'e', ')', '>' }; |
| 896 |
1 |
Assert.assertTrue(Arrays.equals(As, shouldBe), "Annotation is " |
| 897 |
|
+ new String(As) + " but should be " + new String(shouldBe)); |
| 898 |
|
|
| 899 |
|
|
| 900 |
1 |
AlignmentI alWithoutSpaces = new AppletFormatAdapter().readFile( |
| 901 |
|
aliFileRnaSS, DataSourceType.PASTE, |
| 902 |
|
jalview.io.FileFormat.Fasta); |
| 903 |
1 |
AnnotationFile afWithoutSpaces = new AnnotationFile(); |
| 904 |
1 |
afWithoutSpaces.readAnnotationFile(alWithoutSpaces, |
| 905 |
|
annFileRnaSSWithoutSpaceChars, DataSourceType.PASTE); |
| 906 |
|
|
| 907 |
1 |
Assert.assertTrue( |
| 908 |
|
testRnaSSAnnotationsEquivalent( |
| 909 |
|
alWithSpaces.getAlignmentAnnotation()[0], |
| 910 |
|
alWithoutSpaces.getAlignmentAnnotation()[0]), |
| 911 |
|
"RNA SS Annotations SHOULD be pair-wise equivalent (but apparently aren't): \n" |
| 912 |
|
+ "RNA SS A 1:" |
| 913 |
|
+ alWithSpaces.getAlignmentAnnotation()[0] |
| 914 |
|
.getRnaSecondaryStructure() |
| 915 |
|
+ "\n" + "RNA SS A 2:" |
| 916 |
|
+ alWithoutSpaces.getAlignmentAnnotation()[0] |
| 917 |
|
.getRnaSecondaryStructure()); |
| 918 |
|
|
| 919 |
|
|
| 920 |
1 |
AlignmentI wrongAlWithoutSpaces = new AppletFormatAdapter().readFile( |
| 921 |
|
aliFileRnaSS, DataSourceType.PASTE, |
| 922 |
|
jalview.io.FileFormat.Fasta); |
| 923 |
1 |
AnnotationFile wrongAfWithoutSpaces = new AnnotationFile(); |
| 924 |
1 |
wrongAfWithoutSpaces.readAnnotationFile(wrongAlWithoutSpaces, |
| 925 |
|
wrongAnnFileRnaSSWithoutSpaceChars, DataSourceType.PASTE); |
| 926 |
|
|
| 927 |
1 |
Assert.assertFalse( |
| 928 |
|
testRnaSSAnnotationsEquivalent( |
| 929 |
|
alWithSpaces.getAlignmentAnnotation()[0], |
| 930 |
|
wrongAlWithoutSpaces.getAlignmentAnnotation()[0]), |
| 931 |
|
"RNA SS Annotations SHOULD NOT be pair-wise equivalent (but apparently are): \n" |
| 932 |
|
+ "RNA SS A 1:" |
| 933 |
|
+ alWithSpaces.getAlignmentAnnotation()[0] |
| 934 |
|
.getRnaSecondaryStructure() |
| 935 |
|
+ "\n" + "RNA SS A 2:" |
| 936 |
|
+ wrongAlWithoutSpaces.getAlignmentAnnotation()[0] |
| 937 |
|
.getRnaSecondaryStructure()); |
| 938 |
|
|
| 939 |
|
|
| 940 |
|
|
| 941 |
1 |
alWithSpaces.getAlignmentAnnotation()[0].visible = true; |
| 942 |
1 |
StockholmFile sf = new StockholmFile(alWithSpaces); |
| 943 |
|
|
| 944 |
1 |
String stockholmFile = sf.print(alWithSpaces.getSequencesArray(), true); |
| 945 |
1 |
Pattern noSpacesInRnaSSAnnotation = Pattern |
| 946 |
|
.compile("\\n#=GC SS_cons\\s+\\S{14}\\n"); |
| 947 |
1 |
Matcher m = noSpacesInRnaSSAnnotation.matcher(stockholmFile); |
| 948 |
1 |
boolean matches = m.find(); |
| 949 |
1 |
Assert.assertTrue(matches, |
| 950 |
|
"StockholmFile output does not contain expected output (may contain spaces):\n" |
| 951 |
|
+ stockholmFile); |
| 952 |
|
|
| 953 |
|
} |
| 954 |
|
} |