sensibly sized example for PFAM source
[jalview.git] / src / jalview / ws / dbsources / Pfam.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)\r
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  * \r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  * \r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  * \r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 package jalview.ws.dbsources;\r
20 \r
21 import java.util.Hashtable;\r
22 \r
23 import com.stevesoft.pat.Regex;\r
24 \r
25 import jalview.datamodel.AlignmentI;\r
26 import jalview.datamodel.DBRefEntry;\r
27 import jalview.io.AppletFormatAdapter;\r
28 import jalview.io.FastaFile;\r
29 import jalview.io.StockholmFile;\r
30 import jalview.ws.seqfetcher.DbSourceProxy;\r
31 import jalview.ws.seqfetcher.DbSourceProxyImpl;\r
32 /**\r
33  * TODO: later PFAM is a complex datasource - it could return a tree in addition to an alignment\r
34  * TODO: create interface to pass alignment properties and tree back to sequence fetcher\r
35  * @author JimP\r
36  *\r
37  */\r
38 abstract public class Pfam extends DbSourceProxyImpl implements DbSourceProxy\r
39 {\r
40 \r
41   public Pfam()\r
42   {\r
43     super();\r
44     // all extensions of this PFAM source base class are DOMAINDB sources \r
45     addDbSourceProperty(jalview.datamodel.DBRefSource.DOMAINDB);\r
46   }\r
47 \r
48   /* (non-Javadoc)\r
49    * @see jalview.ws.DbSourceProxy#getAccessionSeparator()\r
50    */\r
51   public String getAccessionSeparator()\r
52   {\r
53     // TODO Auto-generated method stub\r
54     return null;\r
55   }\r
56 \r
57   /* (non-Javadoc)\r
58    * @see jalview.ws.DbSourceProxy#getAccessionValidator()\r
59    */\r
60   public Regex getAccessionValidator()\r
61   {\r
62     // TODO Auto-generated method stub\r
63     return null;\r
64   }\r
65 \r
66   /* (non-Javadoc)\r
67    * @see jalview.ws.DbSourceProxy#getDbSource()\r
68   public String getDbSource()\r
69   {\r
70     ** this doesn't work - DbSource is key for the hash of DbSourceProxy instances - 1:many mapping for DbSource to proxy will be lost.\r
71     ** suggest : PFAM is an 'alignment' source - means proxy is higher level than a sequence source.\r
72     return jalview.datamodel.DBRefSource.PFAM;\r
73   }\r
74    */\r
75 \r
76   \r
77   /* (non-Javadoc)\r
78    * @see jalview.ws.DbSourceProxy#getDbSourceProperties()\r
79   public Hashtable getDbSourceProperties()\r
80   {\r
81     \r
82     return null;\r
83   }\r
84  */\r
85   \r
86   /* (non-Javadoc)\r
87    * @see jalview.ws.DbSourceProxy#getDbVersion()\r
88    */\r
89   public String getDbVersion()\r
90   {\r
91     // TODO Auto-generated method stub\r
92     return null;\r
93   }\r
94   /**\r
95    * \r
96    * @return PFAM URL stub for this DbSource\r
97    */\r
98   protected abstract String getPFAMURL();\r
99   /* (non-Javadoc)\r
100    * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])\r
101    */\r
102   public AlignmentI getSequenceRecords(String queries) throws Exception\r
103   {\r
104     // TODO: this is not a perfect implementation. We need to be able to add individual references to each sequence in each family alignment that's retrieved. \r
105     startQuery();\r
106     AlignmentI rcds = new jalview.io.FormatAdapter().readFile(getPFAMURL()+queries.trim().toUpperCase(), jalview.io.FormatAdapter.URL,"STH");\r
107     for (int s=0,sNum=rcds.getHeight(); s<sNum;s++)\r
108     {\r
109       rcds.getSequenceAt(s).addDBRef(new DBRefEntry(jalview.datamodel.DBRefSource.PFAM,\r
110               // getDbSource(), \r
111               getDbVersion(), queries.trim().toUpperCase()));\r
112       if (!getDbSource().equals(jalview.datamodel.DBRefSource.PFAM))\r
113       {         // add the specific ref too\r
114         rcds.getSequenceAt(s).addDBRef(\r
115                 new DBRefEntry( getDbSource(), \r
116                         getDbVersion(), queries.trim().toUpperCase()));\r
117       }\r
118     }\r
119     stopQuery();\r
120     return rcds;\r
121   }\r
122 \r
123   /* (non-Javadoc)\r
124    * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)\r
125    */\r
126   public boolean isValidReference(String accession)\r
127   {\r
128     return accession.indexOf("PF")==0;\r
129   }\r
130 \r
131 \r
132   /*public String getDbName()\r
133   {\r
134     return "PFAM"; // getDbSource();\r
135   } */\r
136 }\r