import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
+import jalview.analysis.GeneticCodes;
import jalview.api.AlignViewportI;
import jalview.api.FeatureColourI;
+import jalview.bin.Jalview;
+import jalview.datamodel.MappedFeatures;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.datamodel.features.FeatureMatcher;
import jalview.datamodel.features.FeatureMatcherSet;
import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+import jalview.gui.Desktop;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
import jalview.schemes.FeatureColour;
filter.and(FeatureMatcher.byScore(Condition.LE, "0.4"));
assertFalse(fr.isVisible(sf)); // feature doesn't match filter
}
+
+ @Test(groups = "Functional")
+ public void testFindComplementFeaturesAtResidue()
+ {
+ Jalview.main(
+ new String[]
+ { "-nonews", "-props", "test/jalview/testProps.jvprops" });
+
+ // codons for MCWHSE
+ String cdsSeq = ">cds\nATGtgtTGGcacTCAgaa";
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(cdsSeq,
+ DataSourceType.PASTE);
+ af.showTranslation_actionPerformed(
+ GeneticCodes.getInstance().getStandardCodeTable());
+ af.closeMenuItem_actionPerformed(true);
+
+ /*
+ * find the complement frames (ugly)
+ */
+ AlignFrame[] frames = Desktop.getAlignFrames();
+ assertEquals(frames.length, 2);
+ AlignViewport av1 = frames[0].getViewport();
+ AlignViewport av2 = frames[1].getViewport();
+ AlignViewport cds = av1.getAlignment().isNucleotide() ? av1 : av2;
+ AlignViewport peptide = cds == av1 ? av2 : av1;
+ assertNotNull(cds);
+ assertNotNull(peptide);
+
+ /*
+ * add features to CDS at first codon, positions 2-3
+ */
+ SequenceI seq1 = cds.getAlignment().getSequenceAt(0);
+ SequenceFeature sf1 = new SequenceFeature("sequence_variant", "G,GT", 2,
+ 2, "ensembl");
+ seq1.addSequenceFeature(sf1);
+ SequenceFeature sf2 = new SequenceFeature("sequence_variant", "C, CA",
+ 3, 3, "ensembl");
+ seq1.addSequenceFeature(sf2);
+
+ /*
+ * 'find' mapped features from the peptide position
+ * - first with CDS features _not_ shown on peptide alignment
+ */
+ SequenceI seq2 = peptide.getAlignment().getSequenceAt(0);
+ FeatureRenderer frC = new FeatureRenderer(cds);
+ frC.featuresAdded();
+ MappedFeatures mf = frC.findComplementFeaturesAtResidue(seq2, 1);
+ assertNotNull(mf);
+ assertEquals(mf.features.size(), 2);
+ assertSame(mf.features.get(0), sf1);
+ assertSame(mf.features.get(1), sf2);
+
+ /*
+ * add exon feature and verify it is only returned once for a
+ * peptide position, even though it is on all 3 codon positions
+ */
+ SequenceFeature sf3 = new SequenceFeature("exon", "exon1", 4, 12,
+ "ensembl");
+ seq1.addSequenceFeature(sf3);
+ frC.featuresAdded();
+ mf = frC.findComplementFeaturesAtResidue(seq2, 3);
+ assertNotNull(mf);
+ assertEquals(mf.features.size(), 1);
+ assertSame(mf.features.get(0), sf3);
+ }
}