2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.AssertJUnit.assertTrue;
25 import jalview.analysis.CrossRef;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.AlignFrame;
30 import jalview.gui.CrossRefAction;
31 import jalview.gui.Desktop;
33 import java.util.IdentityHashMap;
34 import java.util.List;
36 import org.testng.Assert;
37 import org.testng.annotations.Test;
39 @Test(singleThreaded = true)
40 public class CrossRef2xmlTests extends Jalview2xmlBase
44 * test store and recovery of expanded views
48 @Test(groups = { "Operational" }, enabled = true)
49 public void testRetrieveAndShowCrossref() throws Exception
51 // for every set of db queries
53 // verify presence of expected xrefs
54 // show xrefs - verify expected type of frame is shown for each xref
56 // - verify original -> xref -> xref(original) recovers frame containing at
57 // least the first retrieved sequence
60 // 2. individual frames
61 // 3. load each one back and verify
62 // . aligned sequences (.toString() )
63 // . xrefs (.toString() )
67 for (String[] did : new String[][] { { "UNIPROT", "P01731" } })
69 AlignFrame af = jalview.gui.SequenceFetcher.fetchAndShow(did[0],
71 assertTrue("Didn't read in the example file correctly.", af != null);
72 boolean dna = af.getViewport().getAlignment().isNucleotide();
73 AlignmentI retral = af.getViewport().getAlignment();
74 AlignmentI dataset = retral.getDataset();
75 SequenceI[] seqs = retral.getSequencesArray();
76 List<String> ptypes = (seqs == null || seqs.length == 0) ? null
77 : new CrossRef(seqs, dataset)
78 .findXrefSourcesForSequences(dna);
80 * map between a view, and views generated after retrieving xrefs
82 IdentityHashMap<AlignmentViewPanel, List<AlignmentViewPanel>> viewxrefview = new IdentityHashMap<AlignmentViewPanel, List<AlignmentViewPanel>>();
84 * map between a particular view and it's originating dbref path
86 IdentityHashMap<AlignmentViewPanel, String> viewsourcedb = new IdentityHashMap<AlignmentViewPanel, String>();
88 String first = did[0] + " " + did[1];
89 viewsourcedb.put(af.alignPanel, first);
90 for (String db : ptypes)
92 // retrieve and show cross-refs in this thread
93 CrossRefAction cra = new CrossRefAction(af, seqs, dna, db);
95 Assert.assertTrue(cra.getXrefViews().size() > 0,
96 "No crossrefs retrieved for " + db);
97 viewxrefview.put(af.alignPanel, cra.getXrefViews());
99 for (AlignmentViewPanel avp : cra.getXrefViews())
102 SequenceI[] xrseqs = avp.getAlignment().getSequencesArray();
103 String nextxref = first + " -> " + db;
104 viewsourcedb.put(avp, nextxref);
105 List<String> xrptypes = (seqs == null || seqs.length == 0) ? null
106 : new CrossRef(xrseqs, dataset)
107 .findXrefSourcesForSequences(avp
108 .getAlignViewport().isNucleotide());
109 for (String xrefdb : xrptypes)
111 AlignFrame nextaf = Desktop.getAlignFrameFor(avp
112 .getAlignViewport());
113 cra = new CrossRefAction(nextaf, xrseqs, avp.getAlignViewport()
114 .isNucleotide(), xrefdb);
116 Assert.assertTrue(cra.getXrefViews().size() > 0,
117 "No crossrefs found for '" + nextxref + "' to "
118 + xrefdb + " via '" + nextaf.getTitle() + "'");
119 // save views for analysis
120 viewxrefview.put(avp, cra.getXrefViews());
121 for (AlignmentViewPanel nextavp : cra.getXrefViews())
124 viewsourcedb.put(nextavp, nextxref + " -> " + xrefdb);