X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FSequenceFetcher.java;h=4f9e0abf855c96100002f9abdbf21ac40f49540c;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=073d448e3ffb7c9ff9bd5208fceb538ec6224c08;hpb=54e003f9b2fff47dbfea6401c3944afdb7bd37b3;p=jalview.git
diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java
index 073d448..4f9e0ab 100644
--- a/src/jalview/ws/SequenceFetcher.java
+++ b/src/jalview/ws/SequenceFetcher.java
@@ -1,5 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ */
package jalview.ws;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Vector;
@@ -12,13 +30,15 @@ import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefSource;
import jalview.datamodel.SequenceI;
+import jalview.ws.dbsources.DasSequenceSource;
import jalview.ws.seqfetcher.ASequenceFetcher;
import jalview.ws.seqfetcher.DbSourceProxy;
/**
* This is the the concrete implementation of the sequence retrieval interface
* and abstract class in jalview.ws.seqfetcher. This implements the run-time
- * discovery of sequence database clients, and provides a hardwired main for testing all registered handlers.
+ * discovery of sequence database clients, and provides a hardwired main for
+ * testing all registered handlers.
*
*/
public class SequenceFetcher extends ASequenceFetcher
@@ -36,11 +56,74 @@ public class SequenceFetcher extends ASequenceFetcher
addDBRefSourceImpl(jalview.ws.dbsources.Uniprot.class);
addDBRefSourceImpl(jalview.ws.dbsources.UnprotName.class);
addDBRefSourceImpl(jalview.ws.dbsources.Pdb.class);
- addDBRefSourceImpl(jalview.ws.dbsources.Pfam.class);
+ addDBRefSourceImpl(jalview.ws.dbsources.PfamFull.class);
+ addDBRefSourceImpl(jalview.ws.dbsources.PfamSeed.class); // ensures Seed
+ // alignment is
+ // 'default' for
+ // PFAM
registerDasSequenceSources();
}
+
+ /**
+ * return an ordered list of database sources suitable for using in a GUI
+ * element
+ */
+ public String[] getOrderedSupportedSources()
+ {
+ String[] srcs = this.getSupportedDb();
+ ArrayList dassrc = new ArrayList(), nondas = new ArrayList();
+ for (int i = 0; i < srcs.length; i++)
+ {
+ String nm = getSourceProxy(srcs[i]).getDbName();
+ if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.DasSequenceSource)
+ {
+ if (nm.startsWith("das:"))
+ {
+ nm = nm.substring(4);
+ }
+ dassrc.add(new String[]
+ { srcs[i], nm.toUpperCase() });
+ }
+ else
+ {
+ nondas.add(new String[]
+ { srcs[i], nm.toUpperCase() });
+ }
+ }
+ Object[] sorted = nondas.toArray();
+ String[] tosort = new String[sorted.length];
+ nondas.clear();
+ for (int j = 0; j < sorted.length; j++)
+ {
+ tosort[j] = ((String[]) sorted[j])[1];
+ }
+ jalview.util.QuickSort.sort(tosort, sorted);
+ int i = 0;
+ for (int j = sorted.length - 1; j >= 0; j--, i++)
+ {
+ srcs[i] = ((String[]) sorted[j])[0];
+ sorted[j] = null;
+ }
+
+ sorted = dassrc.toArray();
+ tosort = new String[sorted.length];
+ dassrc.clear();
+ for (int j = 0; j < sorted.length; j++)
+ {
+ tosort[j] = ((String[]) sorted[j])[1];
+ }
+ jalview.util.QuickSort.sort(tosort, sorted);
+ for (int j = sorted.length - 1; j >= 0; j--, i++)
+ {
+ srcs[i] = ((String[]) sorted[j])[0];
+ sorted[j] = null;
+ }
+ return srcs;
+ }
+
/**
* simple run method to test dbsources.
+ *
* @param argv
*/
public static void main(String[] argv)
@@ -48,12 +131,12 @@ public class SequenceFetcher extends ASequenceFetcher
AlignmentI ds = null;
Vector noProds = new Vector();
String usage = "SequenceFetcher.main [ ]\n"
- +"With no arguments, all DbSources will be queried with their test Accession number.\n"
- +"If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to and retrieve from it.";
+ + "With no arguments, all DbSources will be queried with their test Accession number.\n"
+ + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to and retrieve from it.";
if (argv != null && argv.length > 0)
{
DbSourceProxy sp = new SequenceFetcher().getSourceProxy(argv[0]);
- if (sp!=null)
+ if (sp != null)
{
AlignmentI al = null;
try
@@ -62,40 +145,46 @@ public class SequenceFetcher extends ASequenceFetcher
} catch (Exception e)
{
e.printStackTrace();
- System.err.println("Error when retrieving "+argv[1]+" from "+argv[0]+"\nUsage: "+usage);
+ System.err.println("Error when retrieving " + argv[1] + " from "
+ + argv[0] + "\nUsage: " + usage);
}
SequenceI[] prod = al.getSequencesArray();
- if (al!=null)
+ if (al != null)
{
for (int p = 0; p < prod.length; p++)
{
System.out.println("Prod " + p + ": "
- + prod[p].getDisplayId(true) + " : "+prod[p].getDescription());
+ + prod[p].getDisplayId(true) + " : "
+ + prod[p].getDescription());
}
}
return;
- } else {
- System.err.println("Can't resolve "+argv[0]+" as a database name. Allowed values are :\n"+new SequenceFetcher().getSupportedDb());
}
- System.out
- .println(usage);
+ else
+ {
+ System.err.println("Can't resolve " + argv[0]
+ + " as a database name. Allowed values are :\n"
+ + new SequenceFetcher().getSupportedDb());
+ }
+ System.out.println(usage);
}
ASequenceFetcher sfetcher = new SequenceFetcher();
String[] dbSources = sfetcher.getSupportedDb();
- for (int dbsource=0; dbsource 0 && sp.getDbSourceProperties()!=null)
+ if (al != null && al.getHeight() > 0
+ && sp.getDbSourceProperties() != null)
{
boolean dna = sp.getDbSourceProperties().containsKey(
DBRefSource.DNACODINGSEQDB)
@@ -195,7 +284,8 @@ public class SequenceFetcher extends ASequenceFetcher
Alignment prodal = jalview.analysis.CrossRef.findXrefSequences(
seqs, dna, null, ds);
System.out.println("Found "
- + ((prodal == null) ? "no" : "" + prodal.getHeight()) + " products");
+ + ((prodal == null) ? "no" : "" + prodal.getHeight())
+ + " products");
if (prodal != null)
{
SequenceI[] prod = prodal.getSequencesArray(); // note
@@ -209,7 +299,7 @@ public class SequenceFetcher extends ASequenceFetcher
// mapping
// (if
// present)
- for (int p = 0; p < prod.length; p++)
+ for (int p = 0; p < prod.length; p++)
{
System.out.println("Prod " + p + ": "
+ prod[p].getDisplayId(true));
@@ -219,54 +309,99 @@ public class SequenceFetcher extends ASequenceFetcher
}
}
+
/**
- * query the currently defined DAS source registry for sequence sources and add a DasSequenceSource instance for each source to the SequenceFetcher source list.
+ * query the currently defined DAS source registry for sequence sources and
+ * add a DasSequenceSource instance for each source to the SequenceFetcher
+ * source list.
*/
- public void registerDasSequenceSources() {
- DasSource[] sources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();
- for (int s=0;s