--- /dev/null
+package jalview.ws;\r
+\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.SequenceI;\r
+\r
+import java.util.Enumeration;\r
+import java.util.Hashtable;\r
+import java.util.Vector;\r
+\r
+public class ASequenceFetcher\r
+{\r
+\r
+ /**\r
+ * set of databases we can retrieve entries from\r
+ */\r
+ protected Hashtable FETCHABLEDBS;\r
+\r
+ public ASequenceFetcher()\r
+ {\r
+ super();\r
+ }\r
+\r
+ /**\r
+ * get list of supported Databases\r
+ * \r
+ * @return database source string for each database - only the latest version\r
+ * of a source db is bound to each source.\r
+ */\r
+ public String[] getSupportedDb()\r
+ {\r
+ if (FETCHABLEDBS == null)\r
+ return null;\r
+ String[] sf = new String[FETCHABLEDBS.size()];\r
+ Enumeration e = FETCHABLEDBS.keys();\r
+ int i = 0;\r
+ while (e.hasMoreElements())\r
+ {\r
+ sf[i++] = (String) e.nextElement();\r
+ }\r
+ ;\r
+ return sf;\r
+ }\r
+\r
+ public boolean isFetchable(String source)\r
+ {\r
+ Enumeration e = FETCHABLEDBS.keys();\r
+ while (e.hasMoreElements())\r
+ {\r
+ String db = (String) e.nextElement();\r
+ if (source.compareToIgnoreCase(db) == 0)\r
+ return true;\r
+ }\r
+ jalview.bin.Cache.log.warn("isFetchable doesn't know about '" + source\r
+ + "'");\r
+ return false;\r
+ }\r
+\r
+ public SequenceI[] getSequences(jalview.datamodel.DBRefEntry[] refs)\r
+ {\r
+ SequenceI[] ret = null;\r
+ Vector rseqs = new Vector();\r
+ Hashtable queries = new Hashtable();\r
+ for (int r = 0; r < refs.length; r++)\r
+ {\r
+ if (!queries.containsKey(refs[r].getSource()))\r
+ {\r
+ queries.put(refs[r].getSource(), new Vector());\r
+ }\r
+ Vector qset = (Vector) queries.get(refs[r].getSource());\r
+ if (!qset.contains(refs[r].getAccessionId()))\r
+ {\r
+ qset.addElement(refs[r].getAccessionId());\r
+ }\r
+ }\r
+ Enumeration e = queries.keys();\r
+ while (e.hasMoreElements())\r
+ {\r
+ Vector query = null;\r
+ String db = null;\r
+ try\r
+ {\r
+ db = (String) e.nextElement();\r
+ query = (Vector) queries.get(db);\r
+ if (!isFetchable(db))\r
+ throw new Exception(\r
+ "Don't know how to fetch from this database :" + db);\r
+ DbSourceProxy fetcher = getSourceProxy(db);\r
+ boolean doMultiple = fetcher.getAccessionSeparator() != null; // No\r
+ // separator\r
+ // - no\r
+ // Multiple\r
+ // Queries\r
+ Enumeration qs = query.elements();\r
+ while (qs.hasMoreElements())\r
+ {\r
+ StringBuffer qsb = new StringBuffer();\r
+ do\r
+ {\r
+ qsb.append((String) qs.nextElement());\r
+ if (qs.hasMoreElements() && doMultiple) // and not reached limit for\r
+ // multiple queries at one\r
+ // time for this source\r
+ {\r
+ qsb.append(fetcher.getAccessionSeparator());\r
+ }\r
+ } while (doMultiple && qs.hasMoreElements());\r
+\r
+ // create a fetcher and go to it\r
+ AlignmentI seqset = fetcher.getSequenceRecords(qsb.toString());\r
+ // TODO: Merge alignment together - perhaps\r
+ if (seqset != null)\r
+ {\r
+ SequenceI seqs[] = seqset.getSequencesArray();\r
+ if (seqs != null)\r
+ {\r
+ for (int is = 0; is < seqs.length; is++)\r
+ {\r
+ rseqs.addElement(seqs[is]);\r
+ seqs[is] = null;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (fetcher.getRawRecords() != null)\r
+ {\r
+ System.out.println("# Retrieved from " + db + ":"\r
+ + qs.toString());\r
+ StringBuffer rrb = fetcher.getRawRecords();\r
+ /*\r
+ * for (int rr = 0; rr<rrb.length; rr++) {\r
+ */\r
+ String hdr;\r
+ // if (rr<qs.length)\r
+ // {\r
+ hdr = "# " + db + ":" + qsb.toString();\r
+ /*\r
+ * } else { hdr = "# part "+rr; }\r
+ */\r
+ System.out.println(hdr);\r
+ if (rrb != null)\r
+ System.out.println(rrb);\r
+ System.out.println("# end of " + hdr);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } catch (Exception ex)\r
+ {\r
+ System.err\r
+ .println("Failed to retrieve the following references from "\r
+ + db);\r
+ Enumeration qv = query.elements();\r
+ int n = 0;\r
+ while (qv.hasMoreElements())\r
+ {\r
+ System.err.print(" " + qv + ";");\r
+ if (n++ > 10)\r
+ {\r
+ System.err.println();\r
+ n = 0;\r
+ }\r
+ }\r
+ System.err.println();\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+ if (rseqs.size() > 0)\r
+ {\r
+ ret = new SequenceI[rseqs.size()];\r
+ rseqs.copyInto(ret);\r
+ }\r
+ return ret;\r
+ }\r
+\r
+ /**\r
+ * Retrieve an instance of the proxy for the given source\r
+ * \r
+ * @param db\r
+ * database source string TODO: add version string/wildcard for\r
+ * retrieval of specific DB source/version combinations.\r
+ * @return an instance of DbSourceProxy for that db.\r
+ */\r
+ public DbSourceProxy getSourceProxy(String db)\r
+ {\r
+ DbSourceProxy dbs = (DbSourceProxy) FETCHABLEDBS.get(db);\r
+ return dbs;\r
+ }\r
+\r
+}
\ No newline at end of file
* along with this program; if not, write to the Free Software\r
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
*/\r
-package jalview.io;\r
+package jalview.ws;\r
\r
import java.io.*;\r
import java.util.*;\r
{\r
sequence = (SequenceI) sequenceMatches.elementAt(m);\r
sequence.addDBRef(new DBRefEntry(DBRefSource.UNIPROT,\r
- "0",\r
+ "0", // TODO: VERSION FROM UNIPROT\r
entry.getAccession().elementAt(0).\r
toString()));\r
\r
PDBEntry pdb = (PDBEntry) e.nextElement();\r
if (!pdb.getType().equals(DBRefSource.PDB))\r
{\r
+ DBRefEntry xref = new DBRefEntry(pdb.getType(), DBRefSource.UNIPROT, pdb.getId());\r
+ sequence.addDBRef(xref);\r
continue;\r
}\r
-\r
+ \r
sequence.addDBRef(new DBRefEntry(DBRefSource.PDB,\r
"0",\r
pdb.getId()));\r
* along with this program; if not, write to the Free Software\r
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
*/\r
-package jalview.io;\r
+package jalview.ws;\r
\r
import java.net.*;\r
import java.util.*;\r
Cache.log.info("Error in 'experimental' mapping of features. Please try to reproduce and then report info to help@jalview.org.");\r
Cache.log.info("Mapping feature from "+f.getBegin()+" to "+f.getEnd()+" in dbref "+dbref.getAccessionId()+" in "+dbref.getSource());\r
Cache.log.info("using das Source "+ds.getUrl());\r
- Cache.log.info(ex);\r
+ Cache.log.info("Exception", ex);\r
}\r
\r
if (vf!=null) {\r
--- /dev/null
+package jalview.ws;\r
+\r
+import jalview.datamodel.AlignmentI;\r
+\r
+import java.util.Hashtable;\r
+\r
+import com.stevesoft.pat.Regex;\r
+/**\r
+ * generic Reference Retrieval interface for a particular database source/version as cited in DBRefEntry.\r
+ * TODO: add/define property to describe max number of queries that this source can cope with at once.\r
+ * TODO: add/define mechanism for retrieval of Trees and distance matrices from a database (unify with io)\r
+ * @author JimP\r
+ *\r
+ */\r
+public interface DbSourceProxy\r
+{\r
+ /**\r
+ * \r
+ * @return source string constant used for this DB source\r
+ */\r
+ public String getDbSource();\r
+ /**\r
+ * \r
+ * @return version string for this database.\r
+ */\r
+ public String getDbVersion();\r
+ /**\r
+ * Separator between individual accession queries for a database that allows multiple IDs\r
+ * to be fetched in a single query. Null implies that only a single ID can be fetched at a time.\r
+ * @return string for separating concatenated queries (as individually validated by the accession validator)\r
+ */\r
+ public String getAccessionSeparator();\r
+ /**\r
+ * Regular expression for checking form of query string understood by this source.\r
+ * @return null or a validation regex\r
+ */\r
+ public Regex getAccessionValidator();\r
+ /**\r
+ * DbSource properties hash - define the capabilities of this source\r
+ * Property hash methods defined in DbSourceProxyImpl.\r
+ * See constants in jalview.datamodel.DBRefSource for definition of properties.\r
+ * @return \r
+ */\r
+ public Hashtable getDbSourceProperties();\r
+ /**\r
+ * \r
+ * @return a test/example query that can be used to validate retrieval and parsing mechanisms\r
+ */\r
+ public String getTestQuery();\r
+ /**\r
+ * optionally implemented\r
+ * @param accession\r
+ * @return\r
+ */\r
+ public boolean isValidReference(String accession);\r
+ /**\r
+ * make one or more queries to the database\r
+ * and attempt to parse the response into an alignment\r
+ * @param queries\r
+ * @return null if queries were successful but result was not parsable\r
+ * @throws Exception TODO\r
+ */\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception;\r
+ /**\r
+ * \r
+ * @return true if a query is currently being made\r
+ */\r
+ public boolean queryInProgress();\r
+ /**\r
+ * get the raw reponse from the last set of queries\r
+ * @return one or more string buffers for each individual query\r
+ */\r
+ public StringBuffer getRawRecords();\r
+}\r
--- /dev/null
+package jalview.ws;\r
+\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.DBRefSource;\r
+import jalview.io.FormatAdapter;\r
+import jalview.io.IdentifyFile;\r
+\r
+import java.util.Hashtable;\r
+\r
+/**\r
+ * common methods for implementations of the DbSourceProxy interface.\r
+ * \r
+ * @author JimP\r
+ *\r
+ */\r
+public abstract class DbSourceProxyImpl implements DbSourceProxy\r
+{\r
+ public DbSourceProxyImpl()\r
+ {\r
+ // default constructor - do nothing probably.\r
+ }\r
+ private Hashtable props=null;\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getDbSourceProperties()\r
+ */\r
+ public Hashtable getDbSourceProperties()\r
+ {\r
+ return props;\r
+ }\r
+ protected void addDbSourceProperty(Object propname)\r
+ {\r
+ addDbSourceProperty(propname, propname);\r
+ }\r
+\r
+ protected void addDbSourceProperty(Object propname, Object propvalue)\r
+ {\r
+ if (props==null)\r
+ {\r
+ props = new Hashtable();\r
+ }\r
+ props.put(propname, propvalue);\r
+ }\r
+ boolean queryInProgress=false;\r
+ protected StringBuffer results = null;\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see jalview.ws.DbSourceProxy#getRawRecords()\r
+ */\r
+ public StringBuffer getRawRecords()\r
+ {\r
+ return results;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#queryInProgress()\r
+ */\r
+ public boolean queryInProgress()\r
+ {\r
+ return queryInProgress;\r
+ }\r
+ /**\r
+ * call to set the queryInProgress flag\r
+ *\r
+ */\r
+ protected void startQuery()\r
+ {\r
+ queryInProgress=true;\r
+ }\r
+ /**\r
+ * call to clear the queryInProgress flag\r
+ *\r
+ */\r
+ protected void stopQuery()\r
+ {\r
+ queryInProgress=false;\r
+ }\r
+\r
+ /**\r
+ * create an alignment from raw text file...\r
+ * @param result\r
+ * @return null or a valid alignment\r
+ * @throws Exception\r
+ */\r
+ protected Alignment parseResult(String result) throws Exception {\r
+ Alignment sequences = null;\r
+ String format = new IdentifyFile().Identify(result, "Paste");\r
+ if (FormatAdapter.isValidFormat(format))\r
+ {\r
+ sequences = new FormatAdapter().readFile(result.toString(), "Paste",\r
+ format);\r
+ }\r
+ return sequences;\r
+ }\r
+ \r
+}\r
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
-package jalview.io;
+package jalview.ws;
import java.io.*;
import java.util.*;
--- /dev/null
+package jalview.ws;\r
+\r
+import java.util.Enumeration;\r
+import java.util.Hashtable;\r
+import java.util.Vector;\r
+\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.DBRefSource;\r
+import jalview.datamodel.SequenceI;\r
+\r
+/**\r
+ * prototype of abstract sequence retrieval interface\r
+ * \r
+ */\r
+public class SequenceFetcher extends ASequenceFetcher\r
+{\r
+ /**\r
+ * Thread safe construction of database proxies TODO: extend to a configurable\r
+ * database plugin mechanism where classes are instantiated by reflection and\r
+ * queried for their DbRefSource and version association.\r
+ * \r
+ */\r
+ public SequenceFetcher()\r
+ {\r
+ FETCHABLEDBS = new Hashtable();\r
+ FETCHABLEDBS.put(DBRefSource.EMBL,\r
+ new jalview.ws.dbsources.EmblSource());\r
+ FETCHABLEDBS.put(DBRefSource.EMBLCDS,\r
+ new jalview.ws.dbsources.EmblCdsSouce());\r
+ FETCHABLEDBS.put(DBRefSource.UNIPROT,\r
+ new jalview.ws.dbsources.Uniprot());\r
+ FETCHABLEDBS.put(DBRefSource.UP_NAME,\r
+ new jalview.ws.dbsources.Uniprot());\r
+ FETCHABLEDBS.put(DBRefSource.PDB, new jalview.ws.dbsources.Pdb());\r
+ FETCHABLEDBS.put(DBRefSource.PFAM, new jalview.ws.dbsources.Pfam());\r
+ };\r
+\r
+ public static void main(String[] argv)\r
+ {\r
+ AlignmentI ds = null;\r
+ Vector noProds = new Vector();\r
+ if (argv != null && argv.length > 0)\r
+ {\r
+ System.out\r
+ .println("Ignoring arguments. Future Usage = dbname:query1;query2;...");\r
+ }\r
+ SequenceFetcher sfetcher = new SequenceFetcher();\r
+ Enumeration e = sfetcher.FETCHABLEDBS.keys();\r
+ while (e.hasMoreElements())\r
+ {\r
+ String db = (String) e.nextElement();\r
+ // skip me\r
+ if (db.equals(DBRefSource.PDB))\r
+ continue;\r
+ DbSourceProxy sp = sfetcher.getSourceProxy(db);\r
+ System.out\r
+ .println("" + db + ": retrieving test:" + sp.getTestQuery());\r
+ AlignmentI al = null;\r
+ try\r
+ {\r
+ al = sp.getSequenceRecords(sp.getTestQuery());\r
+ if (al != null && al.getHeight() > 0)\r
+ {\r
+ boolean dna = sp.getDbSourceProperties().containsKey(\r
+ DBRefSource.DNACODINGSEQDB)\r
+ || sp.getDbSourceProperties().containsKey(\r
+ DBRefSource.DNASEQDB)\r
+ || sp.getDbSourceProperties().containsKey(\r
+ DBRefSource.CODINGSEQDB);\r
+ // try and find products\r
+ String types[] = jalview.analysis.CrossRef.findSequenceXrefTypes(\r
+ dna, al.getSequencesArray());\r
+ if (types != null)\r
+ {\r
+ System.out.println("Xref Types for: "+(dna ? "dna" : "prot"));\r
+ for (int t = 0; t < types.length; t++)\r
+ {\r
+ System.out.println("Type: " + types[t]);\r
+ SequenceI[] prod = jalview.analysis.CrossRef.findXrefSequences(al\r
+ .getSequencesArray(), dna, types[t]).getSequencesArray();\r
+ System.out.println("Found "\r
+ + ((prod == null) ? "no" : "" + prod.length)\r
+ + " products");\r
+ if (prod!=null)\r
+ {\r
+ for (int p=0; p<prod.length; p++)\r
+ {\r
+ System.out.println("Prod "+p+": "+prod[p].getDisplayId(true));\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ noProds.addElement((dna ? new Object[] { al, al } : new Object[] { al }) ); \r
+ }\r
+\r
+ }\r
+ } catch (Exception ex)\r
+ {\r
+ System.out.println("ERROR:Failed to retrieve test query.");\r
+ ex.printStackTrace(System.out);\r
+ }\r
+ if (al == null)\r
+ {\r
+ System.out.println("ERROR:No alignment retrieved.");\r
+ StringBuffer raw = sp.getRawRecords();\r
+ if (raw != null)\r
+ System.out.println(raw.toString());\r
+ else\r
+ System.out.println("ERROR:No Raw results.");\r
+ }\r
+ else\r
+ {\r
+ System.out.println("Retrieved " + al.getHeight() + " sequences.");\r
+ for (int s = 0; s < al.getHeight(); s++)\r
+ {\r
+ SequenceI sq = al.getSequenceAt(s);\r
+ while (sq.getDatasetSequence() != null)\r
+ {\r
+ sq = sq.getDatasetSequence();\r
+\r
+ }\r
+ if (ds == null)\r
+ {\r
+ ds = new Alignment(new SequenceI[]\r
+ { sq });\r
+\r
+ }\r
+ else\r
+ {\r
+ ds.addSequence(sq);\r
+ }\r
+ }\r
+ }\r
+ System.out.flush();\r
+ System.err.flush();\r
+\r
+ }\r
+ if (noProds.size()>0)\r
+ {\r
+ Enumeration ts = noProds.elements();\r
+ while (ts.hasMoreElements())\r
+ \r
+ {\r
+ Object[] typeSq = (Object[]) ts.nextElement();\r
+ boolean dna = (typeSq.length>1);\r
+ AlignmentI al = (AlignmentI) typeSq[0];\r
+ System.out.println("Trying getProducts for "+al.getSequenceAt(0).getDisplayId(true));\r
+ System.out.println("Search DS Xref for: "+(dna ? "dna" : "prot"));\r
+ // have a bash at finding the products amongst all the retrieved sequences.\r
+ SequenceI[] prod = jalview.analysis.CrossRef.findXrefSequences(al\r
+ .getSequencesArray(), dna, null, ds).getSequencesArray(); // note should test rather than throw away codon mapping (if present)\r
+ System.out.println("Found "\r
+ + ((prod == null) ? "no" : "" + prod.length)\r
+ + " products");\r
+ if (prod!=null)\r
+ {\r
+ for (int p=0; p<prod.length; p++)\r
+ {\r
+ System.out.println("Prod "+p+": "+prod[p].getDisplayId(true));\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+ }\r
+}\r
--- /dev/null
+package jalview.ws.dbsources;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.ws.DbSourceProxyImpl;\r
+\r
+public abstract class EbiFileRetrievedProxy extends DbSourceProxyImpl\r
+{\r
+\r
+ /**\r
+ * temp path to retrieved file\r
+ */\r
+ protected String file = null;\r
+\r
+ public StringBuffer getRawRecords()\r
+ {\r
+ if (file==null)\r
+ return null;\r
+ StringBuffer bf=null;\r
+ try {\r
+ File f = new File(file);\r
+ if (f.exists())\r
+ {\r
+ bf = new StringBuffer();\r
+ BufferedReader breader = new BufferedReader(new FileReader(f));\r
+ String line=null;\r
+ while (breader.ready() && (line = breader.readLine())!=null)\r
+ {\r
+ bf.append(line);\r
+ }\r
+ breader.close();\r
+ }\r
+ } catch (Exception e)\r
+ {\r
+ System.err.println("Warning: problens reading temp file "+file);\r
+ return null;\r
+ }\r
+ return bf;\r
+ }\r
+\r
+}\r
--- /dev/null
+package jalview.ws.dbsources;\r
+\r
+import java.util.Hashtable;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.DBRefSource;\r
+import jalview.ws.DbSourceProxy;\r
+\r
+public class EmblCdsSouce extends EmblXmlSource implements DbSourceProxy\r
+{\r
+\r
+ public EmblCdsSouce() {\r
+ super();\r
+ addDbSourceProperty(DBRefSource.CODINGSEQDB); \r
+ }\r
+ \r
+ public String getAccessionSeparator()\r
+ {\r
+ return null;\r
+ }\r
+\r
+ public Regex getAccessionValidator()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ public String getDbSource()\r
+ {\r
+ return DBRefSource.EMBLCDS;\r
+ }\r
+\r
+ public String getDbVersion()\r
+ {\r
+ return "0"; // TODO : this is dynamically set for a returned record - not tied to proxy\r
+ }\r
+\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception\r
+ { \r
+ if (queries.indexOf(".")>-1)\r
+ {\r
+ queries = queries.substring(0, queries.indexOf("."));\r
+ }\r
+ return getEmblSequenceRecords(DBRefSource.EMBLCDS, queries);\r
+ }\r
+\r
+ public boolean isValidReference(String accession)\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return true;\r
+ }\r
+ /**\r
+ * cDNA for LDHA_CHICK swissprot sequence\r
+ */\r
+ public String getTestQuery()\r
+ {\r
+ return "CAA37824";\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * \r
+ */\r
+package jalview.ws.dbsources;\r
+\r
+import java.io.File;\r
+import java.util.Hashtable;\r
+import java.util.Iterator;\r
+import java.util.StringTokenizer;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.DBRefSource;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.datamodel.xdb.embl.EmblEntry;\r
+import jalview.ws.DbSourceProxy;\r
+import jalview.ws.DbSourceProxyImpl;\r
+import jalview.ws.EBIFetchClient;\r
+\r
+/**\r
+ * @author JimP\r
+ *\r
+ */\r
+public class EmblSource extends EmblXmlSource implements DbSourceProxy\r
+{\r
+\r
+ public EmblSource() {\r
+ addDbSourceProperty(DBRefSource.DNASEQDB);\r
+ addDbSourceProperty(DBRefSource.CODINGSEQDB);\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getAccessionSeparator()\r
+ */\r
+ public String getAccessionSeparator()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getAccessionValidator()\r
+ */\r
+ public Regex getAccessionValidator()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getDbSource()\r
+ */\r
+ public String getDbSource()\r
+ {\r
+ return DBRefSource.EMBL;\r
+ }\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getDbVersion()\r
+ */\r
+ public String getDbVersion()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return "0";\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])\r
+ */\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception\r
+ {\r
+ return getEmblSequenceRecords(DBRefSource.EMBL, queries);\r
+ }\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)\r
+ */\r
+ public boolean isValidReference(String accession)\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * return LHD_CHICK coding gene \r
+ */\r
+ public String getTestQuery()\r
+ {\r
+ return "X53828";\r
+ }\r
+\r
+}\r
--- /dev/null
+package jalview.ws.dbsources;\r
+\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.datamodel.xdb.embl.EmblEntry;\r
+import jalview.ws.EBIFetchClient;\r
+\r
+import java.io.File;\r
+import java.util.Iterator;\r
+import java.util.Vector;\r
+\r
+public abstract class EmblXmlSource extends EbiFileRetrievedProxy\r
+{\r
+\r
+ /**\r
+ * Last properly parsed embl file.\r
+ */\r
+ public jalview.datamodel.xdb.embl.EmblFile efile = null;\r
+\r
+ public EmblXmlSource()\r
+ {\r
+ super();\r
+ }\r
+ /**\r
+ * set this to false to *not* add protein products to alignment dataset.\r
+ */\r
+ public boolean getProteinProducts=false;\r
+ /**\r
+ * retrieve and parse an emblxml file\r
+ * @param emprefx either EMBL or EMBLCDS strings are allowed - anything else will not retrieve emblxml\r
+ * @param query\r
+ * @return\r
+ * @throws Exception\r
+ */\r
+ public AlignmentI getEmblSequenceRecords(String emprefx, String query) throws Exception\r
+ {\r
+ startQuery();\r
+ SequenceI seqs[] = null;\r
+ Vector alseq = new Vector(); // the sequences that will actually be presented in the alignment\r
+ StringBuffer result = new StringBuffer();\r
+ EBIFetchClient dbFetch = new EBIFetchClient();\r
+ File reply; \r
+ try {\r
+ reply = dbFetch.fetchDataAsFile(\r
+ emprefx.toLowerCase() + ":" + query.trim(),\r
+ "emblxml",null);\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ stopQuery();\r
+ throw new Exception("EBI EMBL XML retrieval failed on "+emprefx.toLowerCase()+":"+query.trim(),e);\r
+ }\r
+ if (reply != null && reply.exists())\r
+ {\r
+ file = reply.getAbsolutePath();\r
+ efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply);\r
+ }\r
+ if (efile!=null) {\r
+ for (Iterator i=efile.getEntries().iterator(); i.hasNext(); ) {\r
+ EmblEntry entry = (EmblEntry) i.next();\r
+ SequenceI[] seqparts = entry.getSequences(false,!getProteinProducts, emprefx);\r
+ if (seqparts!=null) {\r
+ SequenceI[] newseqs = null;\r
+ int si=0;\r
+ if (seqs==null) {\r
+ newseqs = new SequenceI[seqparts.length];\r
+ } else {\r
+ newseqs = new SequenceI[seqs.length+seqparts.length];\r
+ \r
+ for (;si<seqs.length; si++) {\r
+ newseqs[si] = seqs[si];\r
+ seqs[si] = null;\r
+ }\r
+ }\r
+ for (int j=0;j<seqparts.length; si++, j++) {\r
+ newseqs[si] = seqparts[j].deriveSequence(); // place DBReferences on dataset and refer\r
+ }\r
+ seqs=newseqs;\r
+ \r
+ }\r
+ }\r
+ } else {\r
+ result=null;\r
+ }\r
+ AlignmentI al =null;\r
+ if (seqs!=null && seqs.length>0)\r
+ {\r
+ al = new Alignment(seqs);\r
+ result.append("# Successfully parsed the "+emprefx+" queries into an Alignment");\r
+ results = result;\r
+ }\r
+ stopQuery();\r
+ return al;\r
+ }\r
+\r
+}
\ No newline at end of file
--- /dev/null
+/**\r
+ * \r
+ */\r
+package jalview.ws.dbsources;\r
+\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.DBRefEntry;\r
+import jalview.datamodel.DBRefSource;\r
+import jalview.datamodel.SequenceI;\r
+\r
+import java.io.BufferedInputStream;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.util.Hashtable;\r
+import java.util.Vector;\r
+\r
+import MCview.PDBChain;\r
+import MCview.PDBfile;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.io.FileParse;\r
+import jalview.ws.DbSourceProxy;\r
+import jalview.ws.DbSourceProxyImpl;\r
+import jalview.ws.EBIFetchClient;\r
+\r
+/**\r
+ * @author JimP\r
+ *\r
+ */\r
+public class Pdb extends EbiFileRetrievedProxy implements DbSourceProxy\r
+{\r
+ public Pdb() {\r
+ super();\r
+ addDbSourceProperty(DBRefSource.PROTSEQDB);\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getAccessionSeparator()\r
+ */\r
+ public String getAccessionSeparator()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getAccessionValidator()\r
+ */\r
+ public Regex getAccessionValidator()\r
+ {\r
+ return new Regex("[1-9][0-9A-Za-z]{3}[ _A-Za-z0-9]?");\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getDbSource()\r
+ */\r
+ public String getDbSource()\r
+ {\r
+ return DBRefSource.PDB;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getDbVersion()\r
+ */\r
+ public String getDbVersion()\r
+ {\r
+ return "0";\r
+ }\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])\r
+ */\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception\r
+ {\r
+\r
+ Vector result = new Vector();\r
+ String chain = null;\r
+ String id = null;\r
+ if (queries.indexOf(":") > -1)\r
+ {\r
+ chain = queries.substring(queries.indexOf(":") + 1);\r
+ id = queries.substring(0, queries.indexOf(":"));\r
+ }\r
+ else\r
+ {\r
+ id = queries;\r
+ }\r
+ if (queries.length() > 4 && chain == null)\r
+ {\r
+ chain = queries.substring(4);\r
+ id = queries.substring(0, 4);\r
+ }\r
+ EBIFetchClient ebi = new EBIFetchClient();\r
+ file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw")\r
+ .getAbsolutePath();\r
+ stopQuery();\r
+ if (file == null)\r
+ {\r
+ return null;\r
+ }\r
+ try\r
+ {\r
+ \r
+ PDBfile pdbfile = new PDBfile(file,\r
+ jalview.io.AppletFormatAdapter.FILE);\r
+ for (int i = 0; i < pdbfile.chains.size(); i++)\r
+ {\r
+ if (chain == null\r
+ || ((PDBChain) pdbfile.chains.elementAt(i)).id\r
+ .toUpperCase().equals(chain))\r
+ {\r
+ PDBChain pdbchain = (PDBChain) pdbfile.chains.elementAt(i);\r
+ // Get the Chain's Sequence - who's dataset includes any special features added from the PDB file\r
+ SequenceI sq = pdbchain.sequence;\r
+ // Specially formatted name for the PDB chain sequences retrieved from the PDB\r
+ sq.setName("PDB|" + id + "|" + sq.getName());\r
+ // Might need to add more metadata to the PDBEntry object\r
+ // like below\r
+ /*\r
+ * PDBEntry entry = new PDBEntry();\r
+ // Construct the PDBEntry\r
+ entry.setId(id);\r
+ if (entry.getProperty() == null)\r
+ entry.setProperty(new Hashtable());\r
+ entry.getProperty().put("chains",\r
+ pdbchain.id\r
+ + "=" + sq.getStart()\r
+ + "-" + sq.getEnd());\r
+ sq.getDatasetSequence().addPDBId(entry);\r
+ */\r
+ // Add PDB DB Refs\r
+ // We make a DBRefEtntry because we have obtained the PDB file from a verifiable source\r
+ // JBPNote - PDB DBRefEntry should also carry the chain and mapping information\r
+ DBRefEntry dbentry = new DBRefEntry(getDbSource(),\r
+ getDbVersion(), id + pdbchain.id);\r
+ sq.addDBRef(dbentry);\r
+ // and add seuqence to the retrieved set\r
+ result.addElement(sq.deriveSequence());\r
+ }\r
+ }\r
+\r
+ if (result.size() < 1)\r
+ {\r
+ throw new Exception("No PDB Records for " + id + " chain "\r
+ + ((chain == null) ? " " : chain));\r
+ }\r
+ } catch (Exception ex) // Problem parsing PDB file\r
+ {\r
+ stopQuery();\r
+ throw (ex);\r
+ }\r
+\r
+ SequenceI[] results = new SequenceI[result.size()];\r
+ for (int i = 0, j = result.size(); i < j; i++)\r
+ {\r
+ results[i] = (SequenceI) result.elementAt(i);\r
+ result.setElementAt(null, i);\r
+ }\r
+ return new Alignment(results);\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)\r
+ */\r
+ public boolean isValidReference(String accession)\r
+ {\r
+ Regex r = getAccessionValidator();\r
+ return r.search(accession.trim());\r
+ }\r
+\r
+ /**\r
+ * obtain human glyoxalase chain A sequence\r
+ */\r
+ public String getTestQuery()\r
+ {\r
+ return "1QIPA";\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * \r
+ */\r
+package jalview.ws.dbsources;\r
+\r
+import java.util.Hashtable;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.ws.DbSourceProxy;\r
+import jalview.ws.DbSourceProxyImpl;\r
+/**\r
+ * TODO: later PFAM is a complex datasource - it currently returns a seed alignment, but could optionally return a full alignment.\r
+ * TODO: later PFAM is a complex datasource - it could return a tree in addition to an alignment\r
+ * TODO: HP: Incorporate jalview.gui.SequenceFetcher retrieval code here.\r
+ * @author JimP\r
+ *\r
+ */\r
+public class Pfam extends DbSourceProxyImpl implements DbSourceProxy\r
+{\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getAccessionSeparator()\r
+ */\r
+ public String getAccessionSeparator()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getAccessionValidator()\r
+ */\r
+ public Regex getAccessionValidator()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getDbSource()\r
+ */\r
+ public String getDbSource()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getDbSourceProperties()\r
+ */\r
+ public Hashtable getDbSourceProperties()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getDbVersion()\r
+ */\r
+ public String getDbVersion()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getRawRecords()\r
+ */\r
+ public StringBuffer getRawRecords()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])\r
+ */\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception\r
+ {\r
+ throw new Exception("PFAM Retrieval not yet implemented - see jalview.gui.SequenceFetcher for current implementation");\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)\r
+ */\r
+ public boolean isValidReference(String accession)\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return false;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see jalview.ws.DbSourceProxy#queryInProgress()\r
+ */\r
+ public boolean queryInProgress()\r
+ {\r
+ // TODO Auto-generated method stub\r
+ return false;\r
+ }\r
+\r
+ public String getTestQuery()\r
+ {\r
+ return "PF00535";\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * \r
+ */\r
+package jalview.ws.dbsources;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.Enumeration;\r
+import java.util.Hashtable;\r
+import java.util.Vector;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.DBRefEntry;\r
+import jalview.datamodel.DBRefSource;\r
+import jalview.datamodel.PDBEntry;\r
+import jalview.datamodel.SequenceFeature;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.datamodel.UniprotEntry;\r
+import jalview.io.FormatAdapter;\r
+import jalview.io.IdentifyFile;\r
+import jalview.ws.DBRefFetcher;\r
+import jalview.ws.DbSourceProxy;\r
+import jalview.ws.DbSourceProxyImpl;\r
+import jalview.ws.EBIFetchClient;\r
+\r
+/**\r
+ * @author JimP\r
+ * \r
+ */\r
+public class Uniprot extends DbSourceProxyImpl implements DbSourceProxy\r
+{\r
+ public Uniprot() {\r
+ super();\r
+ addDbSourceProperty(DBRefSource.SEQDB, DBRefSource.SEQDB);\r
+ addDbSourceProperty(DBRefSource.PROTSEQDB);\r
+ addDbSourceProperty(DBRefSource.MULTIACC);\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see jalview.ws.DbSourceProxy#getAccessionSeparator()\r
+ */\r
+ public String getAccessionSeparator()\r
+ {\r
+ return ";";\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see jalview.ws.DbSourceProxy#getAccessionValidator()\r
+ */\r
+ public Regex getAccessionValidator()\r
+ {\r
+ return null;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see jalview.ws.DbSourceProxy#getDbSource()\r
+ */\r
+ public String getDbSource()\r
+ {\r
+ return DBRefSource.UNIPROT;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see jalview.ws.DbSourceProxy#getDbVersion()\r
+ */\r
+ public String getDbVersion()\r
+ {\r
+ return "0"; // we really don't know what version we're on.\r
+ }\r
+\r
+ private EBIFetchClient ebi = null;\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])\r
+ */\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception\r
+ {\r
+ startQuery();\r
+ try\r
+ {\r
+ Alignment al=null;\r
+ ebi = new EBIFetchClient();\r
+ StringBuffer result=new StringBuffer();\r
+ File file = ebi.fetchDataAsFile("uniprot:" + queries, "xml", null);\r
+ DBRefFetcher dbref = new DBRefFetcher();\r
+ Vector entries = dbref.getUniprotEntries(file);\r
+\r
+ if (entries != null)\r
+ {\r
+ // First, make the new sequences\r
+ Enumeration en = entries.elements();\r
+ while (en.hasMoreElements())\r
+ {\r
+ UniprotEntry entry = (UniprotEntry) en.nextElement();\r
+\r
+ StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot");\r
+ Enumeration en2 = entry.getAccession().elements();\r
+ while (en2.hasMoreElements())\r
+ {\r
+ name.append("|");\r
+ name.append(en2.nextElement());\r
+ }\r
+ en2 = entry.getName().elements();\r
+ while (en2.hasMoreElements())\r
+ {\r
+ name.append("|");\r
+ name.append(en2.nextElement());\r
+ }\r
+\r
+ if (entry.getProtein() != null)\r
+ {\r
+ name.append(" " + entry.getProtein().getName().elementAt(0));\r
+ }\r
+\r
+ result.append(name + "\n"\r
+ + entry.getUniprotSequence().getContent() + "\n");\r
+\r
+ }\r
+\r
+ // Then read in the features and apply them to the dataset\r
+ al = parseResult(result.toString());\r
+ if (al!=null)\r
+ {\r
+ // Decorate the alignment with database entries.\r
+ addUniprotXrefs(al, entries);\r
+ } else {\r
+ results = result;\r
+ }\r
+ }\r
+ stopQuery();\r
+ return al;\r
+ } catch (Exception e)\r
+ {\r
+ stopQuery();\r
+ throw(e);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * add an ordered set of UniprotEntry objects to an ordered set of seuqences.\r
+ * \r
+ * @param al -\r
+ * a sequence of n sequences\r
+ * @param entries\r
+ * a seuqence of n uniprot entries to be analysed.\r
+ */\r
+ public void addUniprotXrefs(Alignment al, Vector entries)\r
+ {\r
+ for (int i = 0; i < entries.size(); i++)\r
+ {\r
+ UniprotEntry entry = (UniprotEntry) entries.elementAt(i);\r
+ Enumeration e = entry.getDbReference().elements();\r
+ Vector onlyPdbEntries = new Vector();\r
+ while (e.hasMoreElements())\r
+ {\r
+ PDBEntry pdb = (PDBEntry) e.nextElement();\r
+ if (!pdb.getType().equals("PDB"))\r
+ {\r
+ continue;\r
+ }\r
+\r
+ onlyPdbEntries.addElement(pdb);\r
+ }\r
+ SequenceI sq = al.getSequenceAt(i);\r
+ sq = (sq.getDatasetSequence()==null) ? sq : sq.getDatasetSequence();\r
+\r
+ Enumeration en2 = entry.getAccession().elements();\r
+ while (en2.hasMoreElements())\r
+ {\r
+ sq.addDBRef(\r
+ new DBRefEntry(getDbSource(), getDbVersion(), en2.nextElement()\r
+ .toString()));\r
+ }\r
+ sq.setPDBId(onlyPdbEntries);\r
+ if (entry.getFeature() != null)\r
+ {\r
+ e = entry.getFeature().elements();\r
+ while (e.hasMoreElements())\r
+ {\r
+ SequenceFeature sf = (SequenceFeature) e.nextElement();\r
+ sf.setFeatureGroup("Uniprot");\r
+ sq.addSequenceFeature(sf);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * \r
+ * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)\r
+ */\r
+ public boolean isValidReference(String accession)\r
+ {\r
+ return true;\r
+ }\r
+ /**\r
+ * return LDHA_CHICK uniprot entry\r
+ */\r
+ public String getTestQuery()\r
+ {\r
+ return "P00340";\r
+ }\r
+}\r