2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ws.dbsources;
23 import java.util.Locale;
25 import jalview.bin.Cache;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.DBRefEntry;
28 import jalview.io.DataSourceType;
29 import jalview.io.FileFormat;
30 import jalview.io.FormatAdapter;
31 import jalview.ws.seqfetcher.DbSourceProxyImpl;
34 * Acts as a superclass for the Rfam and Pfam classes
36 * @author Lauren Michelle Lui
39 public abstract class Xfam extends DbSourceProxyImpl
47 * the base URL for this Xfam-like service
51 protected abstract String getURLPrefix();
54 public abstract String getDbVersion();
56 abstract String getXfamSource();
59 public AlignmentI getSequenceRecords(String queries) throws Exception
61 // TODO: this is not a perfect implementation. We need to be able to add
62 // individual references to each sequence in each family alignment that's
65 // TODO: trap HTTP 404 exceptions and return null
66 String xfamUrl = getURL(queries);
68 if (Cache.log != null)
70 Cache.log.debug("XFAM URL for retrieval is: " + xfamUrl);
73 AlignmentI rcds = new FormatAdapter().readFile(xfamUrl,
74 DataSourceType.URL, FileFormat.Stockholm);
76 for (int s = 0, sNum = rcds.getHeight(); s < sNum; s++)
78 rcds.getSequenceAt(s).addDBRef(new DBRefEntry(getXfamSource(),
80 getDbVersion(), queries.trim().toUpperCase(Locale.ROOT)));
81 if (!getDbSource().equals(getXfamSource()))
82 { // add the specific ref too
83 rcds.getSequenceAt(s).addDBRef(new DBRefEntry(getDbSource(),
84 getDbVersion(), queries.trim().toUpperCase(Locale.ROOT)));
91 String getURL(String queries)
93 return getURLPrefix() + "/family/" + queries.trim().toUpperCase(Locale.ROOT)
98 * Pfam and Rfam provide alignments
101 public boolean isAlignmentSource()
107 * default suffix to append the retrieval URL for this source.
109 * @return "" for most Xfam sources
111 public String getURLSuffix()