merge from 2_4_Release branch
[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 /**\r
34  * TODO: later PFAM is a complex datasource - it could return a tree in addition\r
35  * to an alignment TODO: create interface to pass alignment properties and tree\r
36  * back to sequence fetcher\r
37  * \r
38  * @author JimP\r
39  * \r
40  */\r
41 abstract public class Pfam extends DbSourceProxyImpl implements\r
42         DbSourceProxy\r
43 {\r
44 \r
45   public Pfam()\r
46   {\r
47     super();\r
48     // all extensions of this PFAM source base class are DOMAINDB sources\r
49     addDbSourceProperty(jalview.datamodel.DBRefSource.DOMAINDB);\r
50   }\r
51 \r
52   /*\r
53    * (non-Javadoc)\r
54    * \r
55    * @see jalview.ws.DbSourceProxy#getAccessionSeparator()\r
56    */\r
57   public String getAccessionSeparator()\r
58   {\r
59     // TODO Auto-generated method stub\r
60     return null;\r
61   }\r
62 \r
63   /*\r
64    * (non-Javadoc)\r
65    * \r
66    * @see jalview.ws.DbSourceProxy#getAccessionValidator()\r
67    */\r
68   public Regex getAccessionValidator()\r
69   {\r
70     // TODO Auto-generated method stub\r
71     return null;\r
72   }\r
73 \r
74   /*\r
75    * (non-Javadoc)\r
76    * \r
77    * @see jalview.ws.DbSourceProxy#getDbSource() public String getDbSource() { *\r
78    *      this doesn't work - DbSource is key for the hash of DbSourceProxy\r
79    *      instances - 1:many mapping for DbSource to proxy will be lost. *\r
80    *      suggest : PFAM is an 'alignment' source - means proxy is higher level\r
81    *      than a sequence source. return jalview.datamodel.DBRefSource.PFAM; }\r
82    */\r
83 \r
84   /*\r
85    * (non-Javadoc)\r
86    * \r
87    * @see jalview.ws.DbSourceProxy#getDbSourceProperties() public Hashtable\r
88    *      getDbSourceProperties() {\r
89    * \r
90    * return null; }\r
91    */\r
92 \r
93   /*\r
94    * (non-Javadoc)\r
95    * \r
96    * @see jalview.ws.DbSourceProxy#getDbVersion()\r
97    */\r
98   public String getDbVersion()\r
99   {\r
100     // TODO Auto-generated method stub\r
101     return null;\r
102   }\r
103 \r
104   /**\r
105    * \r
106    * @return PFAM URL stub for this DbSource\r
107    */\r
108   protected abstract String getPFAMURL();\r
109 \r
110   /*\r
111    * (non-Javadoc)\r
112    * \r
113    * @see jalview.ws.DbSourceProxy#getSequenceRecords(java.lang.String[])\r
114    */\r
115   public AlignmentI getSequenceRecords(String queries) throws Exception\r
116   {\r
117     // TODO: this is not a perfect implementation. We need to be able to add\r
118     // individual references to each sequence in each family alignment that's\r
119     // retrieved.\r
120     startQuery();\r
121     AlignmentI rcds = new jalview.io.FormatAdapter().readFile(getPFAMURL()\r
122             + queries.trim().toUpperCase(), jalview.io.FormatAdapter.URL,\r
123             "STH");\r
124     for (int s = 0, sNum = rcds.getHeight(); s < sNum; s++)\r
125     {\r
126       rcds.getSequenceAt(s).addDBRef(\r
127               new DBRefEntry(jalview.datamodel.DBRefSource.PFAM,\r
128               // getDbSource(),\r
129                       getDbVersion(), queries.trim().toUpperCase()));\r
130       if (!getDbSource().equals(jalview.datamodel.DBRefSource.PFAM))\r
131       { // add the specific ref too\r
132         rcds.getSequenceAt(s).addDBRef(\r
133                 new DBRefEntry(getDbSource(), getDbVersion(), queries\r
134                         .trim().toUpperCase()));\r
135       }\r
136     }\r
137     stopQuery();\r
138     return rcds;\r
139   }\r
140 \r
141   /*\r
142    * (non-Javadoc)\r
143    * \r
144    * @see jalview.ws.DbSourceProxy#isValidReference(java.lang.String)\r
145    */\r
146   public boolean isValidReference(String accession)\r
147   {\r
148     return accession.indexOf("PF") == 0;\r
149   }\r
150 \r
151   /*\r
152    * public String getDbName() { return "PFAM"; // getDbSource(); }\r
153    */\r
154 }\r