2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
\r
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\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
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
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
18 package jalview.ws.dbsources.das;
\r
20 import jalview.datamodel.AlignmentI;
\r
21 import jalview.datamodel.Alignment;
\r
22 import jalview.datamodel.DBRefEntry;
\r
23 import jalview.datamodel.Sequence;
\r
24 import jalview.datamodel.SequenceI;
\r
25 import jalview.ws.dbsources.DasSequenceSource;
\r
27 import org.biojava.dasobert.eventmodel.SequenceEvent;
\r
28 import org.biojava.dasobert.eventmodel.SequenceListener;
\r
31 * Listen for sequence fetch events from a dasobert SequenceThread started with
\r
32 * a query string and collect sequences returned from the DAS sequence source.
\r
37 public class DasSequenceSourceListener implements SequenceListener
\r
40 String ourAccession = null;
\r
42 DasSequenceSource oursource = null;
\r
47 * the DAS Sequence DbProxy object containing database details for
\r
50 * the query string sent to the das source that we should be
\r
53 public DasSequenceSourceListener(DasSequenceSource source, String query)
\r
56 ourAccession = query;
\r
59 public void clearSelection()
\r
61 // TODO Auto-generated method stub
\r
65 java.util.Vector seqs = null;
\r
67 public void newSequence(SequenceEvent e)
\r
69 if (!e.getAccessionCode().equals(ourAccession))
\r
72 .println("Warning - received sequence event for strange accession code ("
\r
73 + e.getAccessionCode()
\r
74 + ") - we expected "
\r
81 if (e.getSequence().length() == 0)
\r
83 System.err.println("Empty sequence returned for accession code ("
\r
84 + e.getAccessionCode() + ") from " + oursource.getDbName());
\r
89 seqs = new java.util.Vector();
\r
91 Sequence sq = new Sequence(e.getAccessionCode(), e.getSequence());
\r
92 sq.addDBRef(new DBRefEntry(oursource.getDbSource(), oursource
\r
94 + ":" + e.getVersion(), e.getAccessionCode()));
\r
95 seqs.addElement(sq);
\r
99 public void selectedSeqPosition(int position)
\r
101 // TODO Auto-generated method stub
\r
105 public void selectedSeqRange(int start, int end)
\r
107 // TODO Auto-generated method stub
\r
111 public void selectionLocked(boolean flag)
\r
113 // TODO Auto-generated method stub
\r
117 public void newObjectRequested(String accessionCode)
\r
119 // TODO Auto-generated method stub
\r
123 boolean noSequences = false;
\r
125 public void noObjectFound(String accessionCode)
\r
127 if (accessionCode.equals(ourAccession))
\r
129 noSequences = true;
\r
134 public boolean hasNoSequences()
\r
136 return noSequences;
\r
139 boolean called = false;
\r
141 public boolean isNotCalled()
\r
146 public AlignmentI getSequences()
\r
148 if (noSequences || seqs != null && seqs.size() == 0)
\r
150 SequenceI[] sqs = new SequenceI[seqs.size()];
\r
151 for (int i = 0, iSize = seqs.size(); i < iSize; i++)
\r
153 sqs[i] = (SequenceI) seqs.elementAt(i);
\r
155 Alignment al = new Alignment(sqs);
\r
156 if (oursource.getSource().hasCapability("features"))
\r
158 java.util.Vector src = new java.util.Vector();
\r
159 src.addElement(oursource.getSource());
\r
160 new jalview.ws.DasSequenceFeatureFetcher(sqs, null, src, false, false);
\r