import java.lang.reflect.Method;
+
+
/**
* A class to perform a DAS features request
*
int comeBackLater;
URL url;
/**
+ * @param url the URL the features should be downloaded from
*
*/
public DAS_FeatureRetrieve(URL url) {
comeBackLater = cont_handle.getComBackLater();
}
catch ( Exception e){
- System.out.println("ERROR PARSING RESULT FROM "+url+ "\n"+e+"\n");
- // e.printStackTrace();
+ e.printStackTrace();
logger.log(Level.FINE,"error while parsing response from "+ url);
comeBackLater = -1;
features = new ArrayList();
}
}
+
/** open HttpURLConnection. Recommended way to open
* HttpURLConnections, since this take care of setting timeouts
* properly for java 1.4 and 1.5*/
return huc;
}
+
private InputStream open(URL url)
throws java.io.IOException, java.net.ConnectException
{
}
- /** returns a List of Features */
+ /** returns a List of Features
+ * @return a List of Maps containing the features*/
public List get_features() {
return features;
String dasCommand ;
int comeBackLater ;
-
+
+ int maxFeatures ;
+
public DAS_Feature_Handler() {
super();
characterdata = "";
dasCommand = "" ;
comeBackLater = -1;
+ maxFeatures = -1;
+ }
+
+ /** specifies a maximum number of features to be downloaded. if a
+ server returns more, they will be ignored. default is to load
+ all features
+ @param max the maximium number of features to be downloaded
+ */
+
+ public void setMaxFeatures(int max) {
+ maxFeatures = max;
+ }
+
+ public int getMaxFeatures() {
+ return maxFeatures;
}
public void setDASCommand(String cmd) { dasCommand = cmd ;}
}
void start_feature(String uri, String name, String qName, Attributes atts) {
+
+ if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) {
+ characterdata = "";
+ return;
+ }
feature = new HashMap() ;
String id = atts.getValue("id");
feature.put("id",id);
//System.out.println("featurefield "+featurefield+ " data "+characterdata);
// NOTE can have multiple lines ..
+ if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) {
+ return;
+ }
+
+
String data = (String)feature.get(featurefield);
if (data != null){
characterdata = data + " " + characterdata;
}
public void startDocument() {
- //System.out.println("start document");
}
- public void endDocument () {
- //System.out.println("adding feature " + feature);
- //features.add(feature);
-
+ public void endDocument () {
}
public void endElement(String uri, String name, String qName) {
- //System.out.println("end "+name);
+
if ( qName.equals("METHOD") ||
qName.equals("TYPE") ||
qName.equals("START") ||
add_featuredata(uri,name,qName);
}
else if ( qName.equals("FEATURE")) {
- //System.out.println("adding ffeature " + feature);
- features.add(feature);
+
+ if ( maxFeatures > 0 ) {
+ if ( features.size() < maxFeatures ) {
+ features.add(feature);
+ }
+ } else {
+ // no restriction
+ features.add(feature);
+ }
}
}
public void characters (char ch[], int start, int length){
- //System.out.println("characters");
+
for (int i = start; i < start + length; i++) {
characterdata += ch[i];
import org.biojava.dasobert.dasregistry.Das1Source;
/** a thread that connects to a DAS - Feature service and gets the features
- *
+ *
* @author Andreas Prlic
*/
public class FeatureThread
- implements Runnable
+ implements Runnable
{
-
+
/** number of times the client tries to reconnect to the server if a "come back later" is returned.
* the server should provide a reasonable estimation how long it will take him to create results.
* if this number of requests is still not successfull, give up.
String ac ;
List featureListeners;
Thread thread;
-
+
public FeatureThread (String accessionCode, Das1Source dasSource) {
this.dasSource = dasSource;
this.ac = accessionCode;
public void addFeatureListener(FeatureListener li) {
featureListeners.add(li);
}
-
+
public void clearFeatureListeners() {
featureListeners.clear();
}
notify();
}
-
+
public void run() {
cmd = new URL(queryString);
} catch (MalformedURLException e ) {
logger.warning("got MalformedURL from das source " +dasSource);
- e.printStackTrace();
+ e.printStackTrace();
+
}
logger.info("requesting features from " + cmd);
DAS_FeatureRetrieve ftmp = new DAS_FeatureRetrieve(cmd);
-
-
+
+
int comeBackLater = ftmp.getComeBackLater();
int securityCounter = 0;
while ( (thread == me) && ( comeBackLater > 0 )) {
securityCounter++;
if ( securityCounter >= MAX_COME_BACK_ITERATIONS){
- comeBackLater = -1;
+ comeBackLater = -1;
break;
-
+
}
notifyComeBackLater(comeBackLater);
// server is still calculating - asks us to come back later
comeBackLater = -1;
break;
}
-
+
ftmp.reload();
- comeBackLater = ftmp.getComeBackLater();
+ comeBackLater = ftmp.getComeBackLater();
}
if ( ! (thread == me ) ) {
}
List features = ftmp.get_features();
-
+
// a fallback mechanism to prevent DAS sources from bringing down spice
if ( features.size() > MAX_NR_FEATURES){
logger.warning("DAS source returned more than " + MAX_NR_FEATURES + "features. " +
" throwing away excess features at " +cmd);
features = features.subList(0,MAX_NR_FEATURES);
}
-
-
+
+
// notify FeatureListeners
Map[] feats = (Map[])features.toArray(new Map[features.size()]);
notifyFeatureListeners(feats);
fi.newFeatures(fevent);
}
}
-
+
/** the Annotation server requested to be queried again in a while
- *
+ *
* @param comeBackLater
*/
private void notifyComeBackLater(int comeBackLater){
FeatureListener fi = (FeatureListener)fiter.next();
fi.comeBackLater(event);
}
-
+
}
/** checks if this capability is actually of das1 style
*
- * @return
+ * @return boolean true if the capability is in DAS1 style
*/
public boolean isDas1Style();
String[] formats;
String queryId;
- public static String DAS1_CAPABILITY_PREFIX = "das1";
+ public static String DAS1_CAPABILITY_PREFIX = "das1:";
public Das2CapabilityImpl() {
super();
* if true - this source can be converted into a DAS1 source by using
* DasSourceConverter.toDas1(Das2Source);
*
+ * @return true if the DasSource has DAS1 capabilties
*/
public boolean hasDas1Capabilities();
}
*/
package org.biojava.dasobert.das2;
+//import org.biojava.bio.program.das.dasalignment.DASException;
import org.biojava.dasobert.dasregistry.Das1Source;
public class DasSourceConverter {
* This only will work if is passes the Das2Source.isDas1Source() test
* i.e. this is really a das1 server there
*
- * @return
+ * @param das2source a DAS2Source to be converted
+ * @return a Das1Source
+ * @throws DASException
*/
public static Das1Source toDas1Source (Das2Source das2source) throws Exception{
if ( ! das2source.hasDas1Capabilities())
ds.setCoordinateSystem(das2source.getCoordinateSystem());
ds.setNickname(das2source.getNickname());
ds.setId(das2source.getId());
+ ds.setLabels(das2source.getLabels());
// convert the capabilitites to das1 capabiltities and get the url
Das2Capability[] caps = das2source.getDas2Capabilities();
String[] das1capabilitites = new String[caps.length];
- int DASPREFIXLENGTH = 4;
+ int DASPREFIXLENGTH = Das2CapabilityImpl.DAS1_CAPABILITY_PREFIX.length();
+
for ( int i = 0 ; i< caps.length;i++){
Das2Capability cap = caps[i];
String c = cap.getCapability();
- das1capabilitites[i] = c.substring(4,c.length());
+
+ das1capabilitites[i] = c.substring(DASPREFIXLENGTH,c.length());
+
String query_uri = cap.getQueryUri();
String url = query_uri.substring(0,(query_uri.length() - c.length() + DASPREFIXLENGTH));
Das2Source currentSource;
List coordinates;
List capabilities;
-
+ List labels;
+
+ public static final String LABELPROPERTY = "label";
+
public DAS2SourceHandler() {
super();
- sources = new ArrayList();
+ sources = new ArrayList();
currentSource = new Das2SourceImpl();
- coordinates = new ArrayList();
- capabilities = new ArrayList();
+ coordinates = new ArrayList();
+ capabilities = new ArrayList();
+ labels = new ArrayList();
}
private void startSource (String uri, String name, String qName, Attributes atts){
} else if ( qName.equals("CAPABILITY")){
Das2Capability cap = getCapability(uri,name,qName,atts);
capabilities.add(cap);
- }
-
- //TODO: add support for "labels"
-
+ } else if (qName.equals("PROPERTY")) {
+ addProperty(uri,name,qName,atts);
+ }
}
private Das2Capability getCapability(String uri, String name, String qName, Attributes atts){
}
+ private void addProperty(String uri, String name, String qName, Attributes atts){
+ String pname = atts.getValue("name");
+ String label = atts.getValue("value");
+ if ( pname.equals(LABELPROPERTY) )
+ labels.add(label);
+ }
+
public void startDocument(){
sources = new ArrayList();
coordinates = new ArrayList();
currentSource.setDas2Capabilities((Das2Capability[])capabilities.toArray(new Das2Capability[capabilities.size()]));
//System.out.println("got coordinates " + coordinates.size());
currentSource.setCoordinateSystem((DasCoordinateSystem[])coordinates.toArray(new DasCoordinateSystem[coordinates.size()]));
+
+ currentSource.setLabels((String[])labels.toArray(new String[labels.size()]));
+ labels.clear();
+
//System.out.println("Das2SourceHandler endElement name " + name + " uri " + uri + " qName " + qName);
//System.out.println("Das2SourceHandler adding to source: " + currentSource.getId());
sources.add(currentSource);
currentSource = new Das2SourceImpl();
- }
+ }
}
public DasSource[] getSources(){
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+//import org.biojava.dasobert.das.AlignmentThread;
+import org.biojava.dasobert.das.DAS_FeatureRetrieve;
import org.biojava.dasobert.dasregistry.DasSource;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.XMLReader;
-import org.biojava.dasobert.das.DAS_FeatureRetrieve;
public class DasSourceReaderImpl implements DasSourceReader {
import java.io.StringWriter;
+//import org.biojava.dasobert.das2.io.DasSourceWriter;
+//import org.biojava.dasobert.das2.io.DasSourceWriterImpl;
+//import org.biojava.utils.xml.PrettyXMLWriter;
+
/** a simple Bean class to be returned via SOAP
* @author Andreas Prlic
return h;
}
+ /** the DAS2 string representation of this DAS source
+ *
+ public String toString() {
+
+ StringWriter writer = new StringWriter();
+
+ PrintWriter pw = new PrintWriter(writer);
+ PrettyXMLWriter xw = new PrettyXMLWriter(pw);
+
+ DasSourceWriter dswriter = new DasSourceWriterImpl();
+ try {
+ dswriter.writeDasSource(xw,this);
+ } catch (IOException e){
+ e.printStackTrace();
+ }
+
+ return writer.toString();
+
+ }
+ */
public void setLocal(boolean flag){ local = flag;}
public boolean isLocal(){return local;}
/** compare if two das sources are equal
*
* @param ds
- * @return
+ * @return returns true if two DAS sources are equivalent
*/
public boolean equals(DasSource ds);
/** classes that implement equals, should also implement hashKey
*
- * @return
+ * @return the hash code of a das source
*/
public int hashCode();
* identifier. The public DAS-Registry has Auto_Ids that look like
* DASSOURCE:12345; public look like XYZ:12345, where the XYZ
* prefix can be configured in the config file.
+ * @return String the ID of a Das Source
*/
public String getId();
* System.out.println(type);
* }
* </pre>
- * @return
+ * @return a Map containng the features
*/
public Map[] getFeatures(){
return features;
/* select a certain sequence position */
public void selectedSeqPosition(int position);
- /** select a certain range of a sequence */
+ /** select a certain range of a sequence
+ * @param start the start
+ * @param end the end of the range
+ * */
public void selectedSeqRange(int start, int end);
- /** the current selecetion is locked and can not be changed */
+ /** the current selecetion is locked and can not be changed
+ * @param flag true if selection should be locked
+ * */
public void selectionLocked(boolean flag);
public void newSequence(SequenceEvent e);