1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws; |
22 |
|
|
23 |
|
import jalview.analysis.CrossRef; |
24 |
|
import jalview.datamodel.Alignment; |
25 |
|
import jalview.datamodel.AlignmentI; |
26 |
|
import jalview.datamodel.DBRefSource; |
27 |
|
import jalview.datamodel.SequenceI; |
28 |
|
import jalview.gui.JvOptionPane; |
29 |
|
import jalview.ws.seqfetcher.ASequenceFetcher; |
30 |
|
import jalview.ws.seqfetcher.DbSourceProxy; |
31 |
|
|
32 |
|
import java.util.Enumeration; |
33 |
|
import java.util.List; |
34 |
|
import java.util.Vector; |
35 |
|
|
36 |
|
import org.testng.annotations.BeforeClass; |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 129 (129) |
Complexity: 31 |
Complexity Density: 0.39 |
|
38 |
|
public class SequenceFetcherTest |
39 |
|
{ |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
41 |
0 |
@BeforeClass(alwaysRun = true)... |
42 |
|
public void setUpJvOptionPane() |
43 |
|
{ |
44 |
0 |
JvOptionPane.setInteractiveMode(false); |
45 |
0 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
46 |
|
} |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@param |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 40 (40) |
Complexity: 11 |
Complexity Density: 0.42 |
|
53 |
0 |
public static void main(String[] argv)... |
54 |
|
{ |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
0 |
String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n" |
60 |
|
+ "With no arguments, all DbSources will be queried with their test Accession number.\n" |
61 |
|
+ "With one argument, the argument will be resolved to one or more db sources and each will be queried with their test accession only.\n" |
62 |
|
+ "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it."; |
63 |
|
|
64 |
0 |
if (argv != null && argv.length > 0) |
65 |
|
{ |
66 |
0 |
String targs[] = new String[argv.length - 1]; |
67 |
0 |
System.arraycopy(argv, 1, targs, 0, targs.length); |
68 |
0 |
argv = targs; |
69 |
|
} |
70 |
0 |
if (argv != null && argv.length > 0) |
71 |
|
{ |
72 |
0 |
List<DbSourceProxy> sps = new SequenceFetcher() |
73 |
|
.getSourceProxy(argv[0]); |
74 |
|
|
75 |
0 |
if (sps != null) |
76 |
|
{ |
77 |
0 |
for (DbSourceProxy sp : sps) |
78 |
|
{ |
79 |
0 |
AlignmentI al = null; |
80 |
0 |
try |
81 |
|
{ |
82 |
0 |
testRetrieval(argv[0], sp, |
83 |
0 |
argv.length > 1 ? argv[1] : sp.getTestQuery()); |
84 |
|
} catch (Exception e) |
85 |
|
{ |
86 |
0 |
e.printStackTrace(); |
87 |
0 |
System.err.println("Error when retrieving " |
88 |
0 |
+ (argv.length > 1 ? argv[1] : sp.getTestQuery()) |
89 |
|
+ " from " + argv[0] + "\nUsage: " + usage); |
90 |
|
} |
91 |
|
} |
92 |
0 |
return; |
93 |
|
} |
94 |
|
else |
95 |
|
{ |
96 |
0 |
System.err.println("Can't resolve " + argv[0] |
97 |
|
+ " as a database name. Allowed values are :\n" |
98 |
|
+ new SequenceFetcher().getSupportedDb()); |
99 |
|
} |
100 |
0 |
System.out.println(usage); |
101 |
0 |
return; |
102 |
|
} |
103 |
0 |
ASequenceFetcher sfetcher = new SequenceFetcher(); |
104 |
0 |
String[] dbSources = sfetcher.getSupportedDb(); |
105 |
0 |
for (int dbsource = 0; dbsource < dbSources.length; dbsource++) |
106 |
|
{ |
107 |
0 |
String db = dbSources[dbsource]; |
108 |
|
|
109 |
0 |
if (db.equals(DBRefSource.PDB)) |
110 |
|
{ |
111 |
0 |
continue; |
112 |
|
} |
113 |
0 |
for (DbSourceProxy sp : sfetcher.getSourceProxy(db)) |
114 |
|
{ |
115 |
0 |
testRetrieval(db, sp, sp.getTestQuery()); |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
} |
120 |
|
|
|
|
| 0% |
Uncovered Elements: 84 (84) |
Complexity: 19 |
Complexity Density: 0.37 |
|
121 |
0 |
private static void testRetrieval(String db, DbSourceProxy sp,... |
122 |
|
String testQuery) |
123 |
|
{ |
124 |
0 |
AlignmentI ds = null; |
125 |
0 |
Vector<Object[]> noProds = new Vector<>(); |
126 |
0 |
System.out.println("Source: " + sp.getDbName() + " (" + db |
127 |
|
+ "): retrieving test:" + sp.getTestQuery()); |
128 |
|
{ |
129 |
0 |
AlignmentI al = null; |
130 |
0 |
try |
131 |
|
{ |
132 |
0 |
al = sp.getSequenceRecords(testQuery); |
133 |
0 |
if (al != null && al.getHeight() > 0) |
134 |
|
{ |
135 |
0 |
boolean dna = sp.isDnaCoding(); |
136 |
0 |
al.setDataset(null); |
137 |
0 |
AlignmentI alds = al.getDataset(); |
138 |
|
|
139 |
0 |
CrossRef crossRef = new CrossRef(al.getSequencesArray(), alds); |
140 |
0 |
List<String> types = crossRef.findXrefSourcesForSequences(dna); |
141 |
0 |
if (types != null) |
142 |
|
{ |
143 |
0 |
System.out.println("Xref Types for: " + (dna ? "dna" : "prot")); |
144 |
0 |
for (String source : types) |
145 |
|
{ |
146 |
0 |
System.out.println("Type: " + source); |
147 |
0 |
SequenceI[] prod = crossRef.findXrefSequences(source, dna) |
148 |
|
.getSequencesArray(); |
149 |
0 |
System.out.println("Found " |
150 |
0 |
+ ((prod == null) ? "no" : "" + prod.length) |
151 |
|
+ " products"); |
152 |
0 |
if (prod != null) |
153 |
|
{ |
154 |
0 |
for (int p = 0; p < prod.length; p++) |
155 |
|
{ |
156 |
0 |
System.out.println("Prod " + p + ": " |
157 |
|
+ prod[p].getDisplayId(true)); |
158 |
|
} |
159 |
|
} |
160 |
|
} |
161 |
|
} |
162 |
|
else |
163 |
|
{ |
164 |
0 |
noProds.addElement((dna ? new Object[] { al, al } |
165 |
|
: new Object[] { al })); |
166 |
|
} |
167 |
|
|
168 |
|
} |
169 |
|
} catch (Exception ex) |
170 |
|
{ |
171 |
0 |
System.out.println("ERROR:Failed to retrieve test query."); |
172 |
0 |
ex.printStackTrace(System.out); |
173 |
|
} |
174 |
|
|
175 |
0 |
if (al == null) |
176 |
|
{ |
177 |
0 |
System.out.println("ERROR:No alignment retrieved."); |
178 |
0 |
StringBuffer raw = sp.getRawRecords(); |
179 |
0 |
if (raw != null) |
180 |
|
{ |
181 |
0 |
System.out.println(raw.toString()); |
182 |
|
} |
183 |
|
else |
184 |
|
{ |
185 |
0 |
System.out.println("ERROR:No Raw results."); |
186 |
|
} |
187 |
|
} |
188 |
|
else |
189 |
|
{ |
190 |
0 |
System.out.println("Retrieved " + al.getHeight() + " sequences."); |
191 |
0 |
if (ds == null) |
192 |
|
{ |
193 |
0 |
ds = al.getDataset(); |
194 |
|
} |
195 |
|
else |
196 |
|
{ |
197 |
0 |
ds.append(al.getDataset()); |
198 |
0 |
al.setDataset(ds); |
199 |
|
} |
200 |
|
} |
201 |
0 |
System.out.flush(); |
202 |
0 |
System.err.flush(); |
203 |
|
} |
204 |
0 |
if (noProds.size() > 0) |
205 |
|
{ |
206 |
0 |
Enumeration<Object[]> ts = noProds.elements(); |
207 |
0 |
while (ts.hasMoreElements()) |
208 |
|
|
209 |
|
{ |
210 |
0 |
Object[] typeSq = ts.nextElement(); |
211 |
0 |
boolean dna = (typeSq.length > 1); |
212 |
0 |
AlignmentI al = (AlignmentI) typeSq[0]; |
213 |
0 |
System.out.println("Trying getProducts for " |
214 |
|
+ al.getSequenceAt(0).getDisplayId(true)); |
215 |
0 |
System.out.println("Search DS Xref for: " + (dna ? "dna" : "prot")); |
216 |
|
|
217 |
|
|
218 |
0 |
SequenceI[] seqs = al.getSequencesArray(); |
219 |
0 |
Alignment prodal = new CrossRef(seqs, ds).findXrefSequences(null, |
220 |
|
dna); |
221 |
0 |
System.out.println("Found " |
222 |
0 |
+ ((prodal == null) ? "no" : "" + prodal.getHeight()) |
223 |
|
+ " products"); |
224 |
0 |
if (prodal != null) |
225 |
|
{ |
226 |
0 |
SequenceI[] prod = prodal.getSequencesArray(); |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
0 |
for (int p = 0; p < prod.length; p++) |
238 |
|
{ |
239 |
0 |
System.out.println("Prod " + p + ": " |
240 |
|
+ prod[p].getDisplayId(true)); |
241 |
|
} |
242 |
|
} |
243 |
|
} |
244 |
|
} |
245 |
|
} |
246 |
|
} |