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