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