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
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
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
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
19 package jalview.ws.dbsources.das;
\r
21 import jalview.datamodel.AlignmentI;
\r
22 import jalview.datamodel.Alignment;
\r
23 import jalview.datamodel.DBRefEntry;
\r
24 import jalview.datamodel.Sequence;
\r
25 import jalview.datamodel.SequenceI;
\r
26 import jalview.ws.dbsources.DasSequenceSource;
\r
28 import org.biojava.dasobert.eventmodel.SequenceEvent;
\r
29 import org.biojava.dasobert.eventmodel.SequenceListener;
\r
32 * Listen for sequence fetch events from a dasobert SequenceThread started with
\r
33 * a query string and collect sequences returned from the DAS sequence source.
\r
38 public class DasSequenceSourceListener implements SequenceListener
\r
41 String ourAccession = null;
\r
43 DasSequenceSource oursource = null;
\r
48 * the DAS Sequence DbProxy object containing database details
\r
51 * the query string sent to the das source that we should be
\r
54 public DasSequenceSourceListener(DasSequenceSource source, String query)
\r
57 ourAccession = query;
\r
60 public void clearSelection()
\r
62 // TODO Auto-generated method stub
\r
66 java.util.Vector seqs = null;
\r
68 public void newSequence(SequenceEvent e)
\r
70 if (!e.getAccessionCode().equals(ourAccession))
\r
73 .println("Warning - received sequence event for strange accession code ("
\r
74 + e.getAccessionCode()
\r
75 + ") - we expected "
\r
82 if (e.getSequence().length() == 0)
\r
84 System.err.println("Empty sequence returned for accession code ("
\r
85 + e.getAccessionCode() + ") from " + oursource.getDbName());
\r
90 seqs = new java.util.Vector();
\r
92 Sequence sq = new Sequence(e.getAccessionCode(), e.getSequence());
\r
93 sq.addDBRef(new DBRefEntry(oursource.getDbSource(), oursource
\r
95 + ":" + e.getVersion(), e.getAccessionCode()));
\r
96 seqs.addElement(sq);
\r
100 public void selectedSeqPosition(int position)
\r
102 // TODO Auto-generated method stub
\r
106 public void selectedSeqRange(int start, int end)
\r
108 // TODO Auto-generated method stub
\r
112 public void selectionLocked(boolean flag)
\r
114 // TODO Auto-generated method stub
\r
118 public void newObjectRequested(String accessionCode)
\r
120 // TODO Auto-generated method stub
\r
124 boolean noSequences = false;
\r
126 public void noObjectFound(String accessionCode)
\r
128 if (accessionCode.equals(ourAccession))
\r
130 noSequences = true;
\r
135 public boolean hasNoSequences()
\r
137 return noSequences;
\r
140 boolean called = false;
\r
142 public boolean isNotCalled()
\r
147 public AlignmentI getSequences()
\r
149 if (noSequences || seqs != null && seqs.size() == 0)
\r
151 SequenceI[] sqs = new SequenceI[seqs.size()];
\r
152 for (int i = 0, iSize = seqs.size(); i < iSize; i++)
\r
154 sqs[i] = (SequenceI) seqs.elementAt(i);
\r
156 Alignment al = new Alignment(sqs);
\r
157 if (oursource.getSource().hasCapability("features"))
\r
159 java.util.Vector src = new java.util.Vector();
\r
160 src.addElement(oursource.getSource());
\r
161 new jalview.ws.DasSequenceFeatureFetcher(sqs, null, src, false, false);
\r