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