{\r
SequenceI[] dataset;\r
\r
- AlignFrame af;\r
+ IProgressIndicator af;\r
\r
CutAndPasteTransfer output = new CutAndPasteTransfer();\r
\r
Vector selectedSources;\r
\r
boolean cancelled = false;\r
-\r
+ private void debug(String mesg)\r
+ {\r
+ debug(mesg, null);\r
+ }\r
+ private void debug(String mesg, Exception e)\r
+ {\r
+ if (Cache.log!=null)\r
+ {\r
+ debug(mesg, e);\r
+ } else {\r
+ System.err.println(mesg);\r
+ if (e!=null)\r
+ { \r
+ e.printStackTrace(); \r
+ }\r
+ }\r
+ }\r
long startTime;\r
\r
/**\r
{\r
cancelled = false;\r
startTime = System.currentTimeMillis();\r
- af.setProgressBar("Fetching DAS Sequence Features", startTime);\r
+ if (af!=null)\r
+ {\r
+ af.setProgressBar("Fetching DAS Sequence Features", startTime);\r
+ }\r
\r
DasSource[] sources = new jalview.gui.DasSourceBrowser().getDASSource();\r
\r
&& jalview.util.DBRefUtils.isDasCoordinateSystem(\r
cs[csIndex].getName(), uprefs[j]))\r
{\r
- Cache.log.debug("Launched fetcher for coordinate system "\r
+ debug("Launched fetcher for coordinate system "\r
+ cs[0].getName());\r
// Will have to pass any mapping information to the fetcher\r
//- the start/end for the DBRefEntry may not be the same as the sequence's start/end\r
responseComplete(dasSource, seq); // reduce thread count anyhow\r
return;\r
}\r
- Cache.log.debug("new Das Feature Fetcher for " + dbref.getSource()\r
+ debug("new Das Feature Fetcher for " + dbref.getSource()\r
+ ":" + dbref.getAccessionId() + " querying "\r
+ dasSource.getUrl());\r
FeatureThread fetcher = new FeatureThread(dbref.getAccessionId()\r
public void comeBackLater(FeatureEvent e)\r
{\r
responseComplete(dasSource, seq);\r
- Cache.log.debug("das source " + e.getDasSource().getNickname()\r
+ debug("das source " + e.getSource().getNickname()\r
+ " asked us to come back in " + e.getComeBackLater()\r
+ " secs.");\r
}\r
public void newFeatures(FeatureEvent e)\r
{\r
\r
- Das1Source ds = e.getDasSource();\r
+ Das1Source ds = e.getSource();\r
\r
Map[] features = e.getFeatures();\r
// add features to sequence\r
- Cache.log.debug("das source " + ds.getUrl() + " returned "\r
+ debug("das source " + ds.getUrl() + " returned "\r
+ features.length + " features");\r
\r
if (features.length > 0)\r
if (dbref.getMap() != null && f.getBegin() > 0\r
&& f.getEnd() > 0)\r
{\r
- Cache.log.debug("mapping from " + f.getBegin() + " - "\r
+ debug("mapping from " + f.getBegin() + " - "\r
+ f.getEnd());\r
SequenceFeature vf[] = null;\r
\r
{\r
for (int v = 0; v < vf.length; v++)\r
{\r
- Cache.log.debug("mapping to " + v + ": "\r
+ debug("mapping to " + v + ": "\r
+ vf[v].getBegin() + " - " + vf[v].getEnd());\r
seq.addSequenceFeature(vf[v]);\r
}\r
}\r
if (id != null && id.length() > 0)\r
{\r
- Cache.log.debug("new Das Feature Fetcher for " + id + " querying "\r
+ debug("new Das Feature Fetcher for " + id + " querying "\r
+ dasSource.getUrl());\r
FeatureThread fetcher = new FeatureThread(id\r
// + ":" + start + "," + end,\r
public void comeBackLater(FeatureEvent e)\r
{\r
responseComplete(dasSource, seq);\r
- Cache.log.debug("das source " + e.getDasSource().getNickname()\r
+ debug("das source " + e.getSource().getNickname()\r
+ " asked us to come back in " + e.getComeBackLater()\r
+ " secs.");\r
}\r
public void newFeatures(FeatureEvent e)\r
{\r
\r
- Das1Source ds = e.getDasSource();\r
+ Das1Source ds = e.getSource();\r
\r
Map[] features = e.getFeatures();\r
// add features to sequence\r
- Cache.log.debug("das source " + ds.getUrl() + " returned "\r
+ debug("das source " + ds.getUrl() + " returned "\r
+ features.length + " features");\r
\r
if (features.length > 0)\r
fetcher.start();\r
} else {\r
// invalid fetch - indicate it is finished.\r
- Cache.log.debug("Skipping empty ID for querying "\r
+ debug("Skipping empty ID for querying "\r
+ dasSource.getUrl());\r
responseComplete(dasSource, seq);\r
}\r
System.out.println("ERRR " + e);\r
e.printStackTrace();\r
System.out.println("############");\r
- Cache.log.debug("Failed to parse " + dasfeature.toString(), e);\r
+ debug("Failed to parse " + dasfeature.toString(), e);\r
return null;\r
}\r
}\r
import java.util.Enumeration;\r
import java.util.Vector;\r
\r
+import org.biojava.dasobert.das2.Das2Source;\r
+import org.biojava.dasobert.dasregistry.Das1Source;\r
+import org.biojava.dasobert.dasregistry.DasCoordinateSystem;\r
+import org.biojava.dasobert.dasregistry.DasSource;\r
+\r
import jalview.datamodel.Alignment;\r
import jalview.datamodel.AlignmentI;\r
import jalview.datamodel.DBRefSource;\r
addDBRefSourceImpl(jalview.ws.dbsources.UnprotName.class);\r
addDBRefSourceImpl(jalview.ws.dbsources.Pdb.class);\r
addDBRefSourceImpl(jalview.ws.dbsources.Pfam.class);\r
- };\r
+ registerDasSequenceSources();\r
+ }\r
/**\r
* simple run method to test dbsources.\r
* @param argv\r
continue;\r
DbSourceProxy sp = sfetcher.getSourceProxy(db);\r
System.out\r
- .println("" + db + ": retrieving test:" + sp.getTestQuery());\r
+ .println("Source: "+sp.getDbName()+" (" + db + "): retrieving test:" + sp.getTestQuery());\r
AlignmentI al = null;\r
try\r
{\r
al = sp.getSequenceRecords(sp.getTestQuery());\r
- if (al != null && al.getHeight() > 0)\r
+ if (al != null && al.getHeight() > 0 && sp.getDbSourceProperties()!=null)\r
{\r
boolean dna = sp.getDbSourceProperties().containsKey(\r
DBRefSource.DNACODINGSEQDB)\r
\r
}\r
}\r
+ /**\r
+ * query the currently defined DAS source registry for sequence sources and add a DasSequenceSource instance for each source to the SequenceFetcher source list.\r
+ */\r
+ public void registerDasSequenceSources() {\r
+ DasSource[] sources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();\r
+ for (int s=0;s<sources.length; s++)\r
+ {\r
+ Das1Source d1s=null;\r
+ if (sources[s].hasCapability("sequence"))\r
+ {\r
+ if (sources[s] instanceof Das2Source)\r
+ {\r
+ if (((Das2Source)sources[s]).hasDas1Capabilities()) {\r
+ try {\r
+ d1s = org.biojava.dasobert.das2.DasSourceConverter.toDas1Source((Das2Source) sources[s]);\r
+ } catch (Exception e)\r
+ {\r
+ System.err.println("Ignoring DAS2 sequence source "+sources[s].getNickname()+" - couldn't map to Das1Source.\n");\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ } else {\r
+ if (sources[s] instanceof Das1Source)\r
+ { \r
+ d1s = (Das1Source) sources[s];\r
+ }\r
+ }\r
+ }\r
+ if (d1s!=null)\r
+ {\r
+ DasCoordinateSystem[] css = d1s.getCoordinateSystem();\r
+ for (int c=0;c<css.length;c++)\r
+ {\r
+ try {\r
+ addDbRefSourceImpl(\r
+ new jalview.ws.dbsources.DasSequenceSource("das:"+d1s.getNickname()+" ("+css[c].getName()+")",\r
+ css[c].getName(),d1s, css[c]));\r
+ } catch (Exception e)\r
+ {\r
+ System.err.println("Ignoring sequence coord system "+c+" ("+\r
+ css[c].getName()+") for source "+d1s.getNickname()\r
+ + "- threw exception when constructing fetcher.\n");\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ \r
+ }\r
+ }\r
+\r
}\r
--- /dev/null
+package jalview.ws.dbsources;\r
+\r
+import java.util.Hashtable;\r
+\r
+import org.biojava.dasobert.das.SequenceThread;\r
+import org.biojava.dasobert.das2.Das2Source;\r
+import org.biojava.dasobert.dasregistry.Das1Source;\r
+import org.biojava.dasobert.dasregistry.DasCoordinateSystem;\r
+import org.biojava.dasobert.dasregistry.DasSource;\r
+import org.biojava.dasobert.eventmodel.SequenceEvent;\r
+import org.biojava.dasobert.eventmodel.SequenceListener;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.ws.dbsources.das.DasSequenceSourceListener;\r
+import jalview.ws.seqfetcher.*;\r
+import jalview.datamodel.AlignmentI;\r
+\r
+/**\r
+ * an instance of this class is created for each unique DAS Sequence source (ie one capable of handling the 'sequence' for a particular MapMaster)\r
+ * \r
+ * @author JimP\r
+ *\r
+ */\r
+public class DasSequenceSource extends DbSourceProxyImpl implements\r
+ DbSourceProxy\r
+{\r
+ protected Das1Source source=null;\r
+ protected String dbname="DASCS";\r
+ protected String dbrefname="das:source";\r
+ protected DasCoordinateSystem coordsys = null;\r
+ /**\r
+ * create a new DbSource proxy for a DAS 1 source\r
+ * @param dbnbame Human Readable Name to use when fetching from this source\r
+ * @param dbrefname DbRefName for DbRefs attached to sequences retrieved from this source\r
+ * @param source Das1Source\r
+ * @param coordsys specific coordinate system to use for this source\r
+ * @throws Exception if source is not capable of the 'sequence' command\r
+ */\r
+ public DasSequenceSource(String dbname, String dbrefname, Das1Source source,\r
+ DasCoordinateSystem coordsys) throws Exception\r
+ {\r
+ if (!source.hasCapability("sequence"))\r
+ {\r
+ throw new Exception("Source "+source.getNickname()+" does not support the sequence command.");\r
+ }\r
+ this.source = source;\r
+ this.dbname = dbname;\r
+ this.dbrefname=dbrefname;\r
+ this.coordsys = coordsys;\r
+ }\r
+ public String getAccessionSeparator()\r
+ {\r
+ // cope with single sequences only\r
+ return null;\r
+ }\r
+\r
+ public Regex getAccessionValidator()\r
+ {\r
+ /** ? **/\r
+ return Regex.perlCode("\\S+");\r
+ }\r
+\r
+ public String getDbName()\r
+ {\r
+ // TODO: map to\r
+ return dbname+" (DAS)";\r
+ }\r
+\r
+ public String getDbSource()\r
+ {\r
+ return dbrefname;\r
+ }\r
+\r
+ public String getDbVersion()\r
+ {\r
+ return coordsys.getVersion();\r
+ }\r
+\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception\r
+ {\r
+ SequenceThread seqfetcher = new org.biojava.dasobert.das.SequenceThread(queries, source);\r
+ DasSequenceSourceListener ourlistener = new DasSequenceSourceListener(this, queries);\r
+ seqfetcher.addSequenceListener(ourlistener);\r
+ seqfetcher.start();\r
+ try { Thread.sleep(5); } catch (Exception e) {};\r
+ while (ourlistener.isNotCalled() && seqfetcher.isAlive())\r
+ {\r
+ try { Thread.sleep(5); } catch (Exception e) { };\r
+ }\r
+ if (ourlistener.isNotCalled() || ourlistener.hasNoSequences())\r
+ {\r
+ System.err.println("Sequence Query to "+source.getNickname()+" with '"+queries+"' returned no sequences.");\r
+ return null;\r
+ } else {\r
+ return ourlistener.getSequences();\r
+ }\r
+ }\r
+\r
+ public String getTestQuery()\r
+ {\r
+ return coordsys.getTestCode();\r
+ }\r
+ public boolean isValidReference(String accession)\r
+ {\r
+ // TODO try to validate an accession against source\r
+ // We don't really know how to do this without querying source\r
+ \r
+ return true;\r
+ }\r
+ /**\r
+ * @return the source\r
+ */\r
+ public Das1Source getSource()\r
+ {\r
+ return source;\r
+ }\r
+ /**\r
+ * @return the coordsys\r
+ */\r
+ public DasCoordinateSystem getCoordsys()\r
+ {\r
+ return coordsys;\r
+ }\r
+}\r
\r
public String getDbName()\r
{\r
- return getDbSource();\r
+ return "EMBL"; //getDbSource();\r
}\r
}\r
\r
public String getDbName()\r
{\r
- return getDbSource();\r
+ return "PDB"; // getDbSource();\r
}\r
\r
}\r
\r
public String getDbName()\r
{\r
- return getDbSource();\r
+ return "PFAM"; // getDbSource();\r
}\r
}\r
}\r
public String getDbName()\r
{\r
- return getDbSource();\r
+ return "Uniprot"; // getDbSource();\r
}\r
}\r
--- /dev/null
+package jalview.ws.dbsources.das;\r
+\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.datamodel.Alignment;\r
+import jalview.datamodel.DBRefEntry;\r
+import jalview.datamodel.Sequence;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.ws.dbsources.DasSequenceSource;\r
+\r
+import org.biojava.dasobert.eventmodel.SequenceEvent;\r
+import org.biojava.dasobert.eventmodel.SequenceListener;\r
+\r
+/**\r
+ * Listen for sequence fetch events from a dasobert SequenceThread started with a \r
+ * query string and collect sequences returned from the DAS sequence source. \r
+ * @author JimP\r
+ *\r
+ */\r
+public class DasSequenceSourceListener implements SequenceListener\r
+{\r
+ \r
+ String ourAccession = null;\r
+ DasSequenceSource oursource=null;\r
+ /**\r
+ * \r
+ * @param source the DAS Sequence DbProxy object containing database details for this source\r
+ * @param query the query string sent to the das source that we should be listening for.\r
+ */\r
+ public DasSequenceSourceListener(DasSequenceSource source, String query)\r
+ {\r
+ oursource=source;\r
+ ourAccession=query;\r
+ }\r
+\r
+ public void clearSelection()\r
+ {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+ java.util.Vector seqs = null;\r
+ public void newSequence(SequenceEvent e)\r
+ {\r
+ if (!e.getAccessionCode().equals(ourAccession))\r
+ {\r
+ System.err.println("Warning - received sequence event for strange accession code ("\r
+ +e.getAccessionCode()+") - we expected "+ourAccession);\r
+ \r
+ return;\r
+ }\r
+ if (seqs==null)\r
+ {\r
+ if (e.getSequence().length()==0)\r
+ {\r
+ System.err.println("Empty sequence returned for accession code ("\r
+ +e.getAccessionCode()+") from "+oursource.getDbName());\r
+ called=true;\r
+ noSequences=true;\r
+ return;\r
+ }\r
+ seqs = new java.util.Vector();\r
+ }\r
+ Sequence sq = new Sequence(e.getAccessionCode(), e.getSequence());\r
+ sq.addDBRef(new DBRefEntry(oursource.getDbSource(), oursource.getDbVersion()+":"+e.getVersion(), e.getAccessionCode()));\r
+ seqs.addElement(sq);\r
+ called=true;\r
+ }\r
+\r
+ public void selectedSeqPosition(int position)\r
+ {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void selectedSeqRange(int start, int end)\r
+ {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void selectionLocked(boolean flag)\r
+ {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void newObjectRequested(String accessionCode)\r
+ {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+ boolean noSequences=false;\r
+ public void noObjectFound(String accessionCode)\r
+ {\r
+ if (accessionCode.equals(ourAccession))\r
+ {\r
+ noSequences=true;\r
+ called = true;\r
+ }\r
+ }\r
+ public boolean hasNoSequences() {\r
+ return noSequences;\r
+ }\r
+ boolean called=false;\r
+ public boolean isNotCalled()\r
+ {\r
+ return !called;\r
+ }\r
+\r
+ public AlignmentI getSequences()\r
+ {\r
+ if (noSequences || seqs!=null && seqs.size()==0)\r
+ return null;\r
+ SequenceI[] sqs = new SequenceI[seqs.size()];\r
+ for (int i=0,iSize=seqs.size(); i<iSize;i++)\r
+ {\r
+ sqs[i] = (SequenceI) seqs.elementAt(i);\r
+ }\r
+ Alignment al = new Alignment(sqs);\r
+ if (oursource.getSource().hasCapability("features"))\r
+ {\r
+ java.util.Vector src = new java.util.Vector();\r
+ src.addElement(oursource.getSource());\r
+ new jalview.ws.DasSequenceFeatureFetcher(sqs, \r
+ null,\r
+ src, false, false);\r
+ }\r
+ \r
+ return al;\r
+ }\r
+\r
+}\r
* A class to perform a DAS features request
*
* @author Andreas Prlic
- *
+ * Adapted for jalview use.
+ * @author Andrew Waterhouse
+ * Updated to Das 1.53e feature spec.
+ * @author Jim Procter
*/
public class DAS_FeatureRetrieve
{
-
+ String version;
List features;
Logger logger;
int comeBackLater;
{
xmlreader.parse(insource);
features = cont_handle.get_features();
+ version = cont_handle.getVersion();
+
comeBackLater = cont_handle.getComBackLater();
}
catch (Exception e)
{
return features;
+ }
+
+
+ /** Get the version string of the reference object.
+ * If it does not match the version string that is obtained from the
+ * reference server there is a version problem!
+ *
+ * @return version string. (e.g. a MD5 digest of the reference sequence)
+ */
+ public String getVersion() {
+ return version;
+ }
+
+
+ public void setVersion(String version) {
+ this.version = version;
}
/** returns the comeBackLater value - if a server returned suchh -
/**
* a class to parse the response of a DAS - Feature request
* @author Andreas Prlic
- *
+ * Adapted for jalview use.
+ * @author Andrew Waterhouse
+ * Updated to Das 1.53e feature spec.
+ * @author Jim Procter
+
*/
public class DAS_Feature_Handler
extends DefaultHandler
boolean first_flag;
HashMap feature;
String featurefield;
- String characterdata;
+ StringBuffer characterdata;
String dasCommand;
int comeBackLater;
int maxFeatures;
- public DAS_Feature_Handler()
- {
+ String segmentId ;
+ String version;
+ String type_id;
+ String type_category;
+
+
+ public DAS_Feature_Handler() {
super();
features = new ArrayList();
first_flag = true;
featurefield = "";
- characterdata = "";
+ characterdata = new StringBuffer();
dasCommand = "";
comeBackLater = -1;
maxFeatures = -1;
+ segmentId = "";
+ version = "";
+ type_id = "";
+ type_category="";
+ }
+
+
+
+ /** get the id information specified int the SEGMENT field of the DAS response
+ *
+ * @return the segmentId or an emtpy string if not available
+ */
+ public String getSegmentId() {
+ return segmentId;
+ }
+
+ /** get the version informationspecified in the SEGMENT field of the DAS response
+ *
+ * @return the version information of an empty string if not available
+ */
+ public String getVersion() {
+ return version;
}
+
+ public boolean isMD5Checksum(){
+
+ if ((version != null) && (version.length() == 32))
+ return true;
+ return false;
+ }
+
/** specifies a maximum number of features to be downloaded. if a
server returns more, they will be ignored. default is to load
void start_feature(String uri, String name, String qName, Attributes atts)
{
- if ( (maxFeatures > 0) && (features.size() > maxFeatures))
- {
- characterdata = "";
+ if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) {
+ characterdata = new StringBuffer();
return;
}
feature = new HashMap();
String id = atts.getValue("id");
feature.put("id", id);
feature.put("dassource", dasCommand);
- characterdata = "";
+ characterdata = new StringBuffer();
}
void add_featuredata(String uri, String name, String qName)
}
String data = (String) feature.get(featurefield);
- if (data != null)
- {
- characterdata = data + " " + characterdata;
+ String featureText = characterdata.toString();
+ if (data != null){
+ featureText = data + " " + featureText;
}
- feature.put(featurefield, characterdata);
+ if ( qName.equals("TYPE")){
+ if ( featureText.length() < 1)
+ featureText = type_id;
+
+ feature.put("TYPE_ID",type_id);
+ feature.put("TYPE_CATEGORY", type_category);
+ type_id = "";
+ type_category="";
+ }
+
+
+ feature.put(featurefield,featureText);
featurefield = "";
- characterdata = "";
+ characterdata = new StringBuffer();
}
private void addLink(String uri, String name, String qName, Attributes atts)
{
String href = atts.getValue("href");
feature.put("LINK", href);
- characterdata = "";
+ characterdata= new StringBuffer();
featurefield = "LINK-TEXT";
}
- public void startElement(String uri, String name, String qName,
- Attributes atts)
- {
+ private void addGroup(String uri, String name, String qName, Attributes atts) {
+ String id = atts.getValue("id");
+ feature.put("GROUP",id);
+ characterdata= new StringBuffer();
+ featurefield = "GROUP";
+ }
+
+ public void startElement (String uri, String name, String qName, Attributes atts){
//System.out.println("new element "+qName);
if (qName.equals("FEATURE"))
else if (qName.equals("LINK"))
{
addLink(uri, name, qName, atts);
- }
+ } else if ( qName.equals("GROUP"))
+ { addGroup(uri,name,qName, atts); }
else if (qName.equals("METHOD") ||
qName.equals("TYPE") ||
qName.equals("START") ||
qName.equals("END") ||
qName.equals("NOTE") ||
- qName.equals("SCORE")
- )
- {
- characterdata = "";
+ qName.equals("SCORE") ||
+ qName.equals("ORIENTATION")
+ ){
+ characterdata = new StringBuffer();
featurefield = qName;
- }
+ } else if (qName.equals("SEGMENT")){
+ String id = atts.getValue("id");
+ if (id != null)
+ segmentId = id;
+ String v = atts.getValue("version");
+ if ( v != null)
+ version = v;
+
+
+ }
+ if ( qName.equals("TYPE")){
+ type_id = atts.getValue("id");
+ type_category= atts.getValue("category");
+ }
}
qName.equals("END") ||
qName.equals("NOTE") ||
qName.equals("LINK") ||
- qName.equals("SCORE")
- )
- {
+ qName.equals("SCORE") ||
+ qName.equals("ORIENTATION") ||
+ qName.equals("GROUP")
+ ) {
add_featuredata(uri, name, qName);
}
else if (qName.equals("FEATURE"))
}
}
- public void characters(char ch[], int start, int length)
- {
+ public void characters (char ch[], int start, int length){
+ if ( maxFeatures > 0)
+ if ( features.size() > maxFeatures )
+ return;
- for (int i = start; i < start + length; i++)
- {
+ for (int i = start; i < start + length; i++) {
- characterdata += ch[i];
- }
+ characterdata.append(ch[i]);
+ }
- }
+ }
}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on 19.03.2004
+ * @author Andreas Prlic
+ *
+ */
+package org.biojava.dasobert.das;
+
+
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.Attributes ;
+import java.util.logging.* ;
+
+/**
+ * a class that parses the XML response of a DAS - sequence command.
+ * @author Andreas Prlic
+ *
+ */
+public class DAS_Sequence_Handler extends DefaultHandler {
+
+ StringBuffer sequence ;
+ int length ;
+
+ int maxLength;
+ String version;
+
+ boolean dna_flag;
+ /**
+ *
+ */
+ public DAS_Sequence_Handler() {
+ super();
+
+ sequence = new StringBuffer() ;
+ length = 0;
+ dna_flag = false ;
+ maxLength = -1;
+ version = "";
+ }
+
+
+
+ /** set a maximum length of sequence that should be loaded
+ * default: -1. if -1 no length restriction is being supplied
+ * @return the maximum length or -1 if no restriction
+ */
+ public int getMaxLength() {
+ return maxLength;
+ }
+
+
+
+ /** set a maximum length of sequence that should be loaded
+ * default: -1. if -1 no length restriction is being supplied
+ * @param maxLength the maximum length or -1 if unrestricted
+ */
+ public void setMaxLength(int maxLength) {
+ this.maxLength = maxLength;
+ }
+
+
+
+
+ public void startElement (String uri, String name, String qName, Attributes atts){
+
+ if ( qName.equals("SEQUENCE")){
+ version = atts.getValue("version");
+ String lenstr = atts.getValue("stop");
+ length = Integer.parseInt(lenstr);
+ dna_flag = true ;
+ }
+
+ }
+
+ public void characters (char ch[], int start, int length){
+
+ if (maxLength > 0)
+ if ( sequence.length() > maxLength)
+ return;
+
+ if (dna_flag)
+ for (int i = start; i < start + length; i++) {
+
+ // all sorts of characters can be found in "seqeunces" ... ignore them...
+ switch (ch[i]) {
+ case '\\':
+ //System.out.print("\\\\");
+ break;
+ case '"':
+ //System.out.print("\\\"");
+ break;
+ case '\n':
+ //System.out.print("\\n");
+ break;
+ case '\r':
+ //System.out.print("\\r");
+ break;
+ case '\t':
+ //System.out.print("\\t");
+ break;
+ case ' ':
+ break;
+ default:
+ sequence = sequence.append(ch[i]);
+
+ break;
+ }
+ }
+
+ }
+
+ public String get_sequence() {
+
+ if ( maxLength < 0) {
+ if ( length != sequence.length()) {
+ Logger logger = Logger.getLogger("org.biojava.spice");
+ logger.warning("Sequence does not match specified length!");
+ }
+ }
+
+ return sequence.toString();
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+}
}
List features = ftmp.get_features();
+ String version = ftmp.getVersion();
// a fallback mechanism to prevent DAS sources from bringing down spice
if (features.size() > MAX_NR_FEATURES)
// notify FeatureListeners
Map[] feats = (Map[]) features.toArray(new Map[features.size()]);
- notifyFeatureListeners(feats);
+ notifyFeatureListeners(feats, version);
break;
thread.start();
}
- private void notifyFeatureListeners(Map[] feats)
+ private void notifyFeatureListeners(Map[] feats, String version)
{
logger.finest("FeatureThread found " + feats.length + " features");
- FeatureEvent fevent = new FeatureEvent(feats, dasSource);
+ FeatureEvent fevent = new FeatureEvent(feats, dasSource, version);
Iterator fiter = featureListeners.iterator();
while (fiter.hasNext())
{
*/
private void notifyComeBackLater(int comeBackLater)
{
- FeatureEvent event = new FeatureEvent(new HashMap[0], dasSource);
+ FeatureEvent event = new FeatureEvent(new HashMap[0], dasSource, "");
event.setComeBackLater(comeBackLater);
Iterator fiter = featureListeners.iterator();
while (fiter.hasNext())
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on Nov 20, 2005
+ *
+ */
+package org.biojava.dasobert.das;
+
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.biojava.dasobert.dasregistry.Das1Source;
+import org.biojava.dasobert.eventmodel.SequenceEvent;
+import org.biojava.dasobert.eventmodel.SequenceListener;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.XMLReader;
+import java.util.*;
+
+/** a thread that gets the sequence from a DAS server
+ *
+ * @author Andreas Prlic
+ *
+ */
+public class SequenceThread
+extends Thread {
+
+ Das1Source[] sequenceServers;
+ String sp_accession;
+ List seqListeners;
+ String version ;
+
+ static Logger logger = Logger.getLogger("org.biojava.spice");
+
+ public SequenceThread(String sp_accession,Das1Source ds ) {
+ super();
+ Das1Source[] dss =new Das1Source[1];
+ dss[0] = ds;
+ this.sp_accession = sp_accession;
+ this.sequenceServers =dss ;
+ clearSequenceListeners();
+ version = "";
+ }
+ public SequenceThread(String sp_accession,Das1Source[] ds ) {
+ super();
+
+ this.sp_accession = sp_accession;
+ this.sequenceServers =ds ;
+ clearSequenceListeners();
+ }
+
+ public void clearSequenceListeners(){
+ seqListeners = new ArrayList();
+ }
+
+ public void addSequenceListener(SequenceListener lis){
+ seqListeners.add(lis);
+ }
+
+ public void run() {
+ getSequence();
+ }
+
+ public void getSequence( ){
+
+ boolean gotSequence = false ;
+
+ for ( int i = 0 ; i< sequenceServers.length; i++){
+
+ if ( gotSequence ) break ;
+
+ Das1Source ds = sequenceServers[i];
+ String url = ds.getUrl() ;
+ char lastChar = url.charAt(url.length()-1);
+ if ( ! (lastChar == '/') )
+ url +="/" ;
+ String dascmd = url + "sequence?segment=";
+ String connstr = dascmd + sp_accession ;
+
+ try {
+ version = "";
+
+ String sequence = retrieveSequence(connstr);
+ // bug in aristotle das source?
+ sequence.replaceAll(" ","");
+ gotSequence = true ;
+ // set the sequence ...
+
+ triggerNewSequence(sp_accession,sequence,ds,version);
+
+
+ return;
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ logger.warning(ex.getMessage());
+
+ //triggerException(ex);
+
+ }
+ }
+
+ logger.log(Level.WARNING,"could not retreive UniProt sequence from any available DAS sequence server");
+
+ triggerNoSequence(sp_accession);
+
+ }
+
+
+
+// private void triggerException(Exception e){
+// Iterator iter = seqListeners.iterator();
+// while (iter.hasNext()){
+// SequenceListener li = (SequenceListener)iter.next();
+// li.exceptionOccured(e);
+// }
+// }
+
+ private void triggerNewSequence(String sp_accession,String sequence,Das1Source source,String version){
+
+ Iterator iter = seqListeners.iterator();
+ while (iter.hasNext()){
+ SequenceListener li = (SequenceListener)iter.next();
+ //SequenceEvent event = new SequenceEvent(sequence);
+ SequenceEvent event = new SequenceEvent(sp_accession,sequence,version);
+ event.setSource(source);
+ li.newSequence(event);
+ }
+ }
+
+ private void triggerNoSequence(String ac){
+
+ Iterator iter = seqListeners.iterator();
+ while (iter.hasNext()){
+ SequenceListener li = (SequenceListener)iter.next();
+ li.noObjectFound(ac);
+ }
+
+ }
+
+ /** retrieve the Sequence from a DAS server.
+ *
+ * @param connstr - the DAS - request string. e.g. http://www.ebi.ac.uk/das-srv/uniprot/das/aristotle/sequence?segment=P00280
+ * @return the requested Sequence
+ * @throws Exception
+ */
+ public String retrieveSequence( String connstr)
+ throws Exception
+ {
+
+ //logger.finest("trying: " + connstr) ;
+ URL dasUrl = new URL(connstr);
+ //DAS_httpConnector dhtp = new DAS_httpConnector() ;
+ logger.info("requesting sequence from " + connstr);
+ InputStream dasInStream =open(dasUrl);
+
+
+ SAXParserFactory spfactory =
+ SAXParserFactory.newInstance();
+
+ // never do this
+ //String vali = System.getProperty("XMLVALIDATION");
+ String vali = "false";
+ boolean validate = false ;
+ if ((vali != null) && ( vali.equals("true")) )
+ validate = true ;
+ spfactory.setValidating(validate);
+
+ SAXParser saxParser = null ;
+
+ try{
+ saxParser =
+ spfactory.newSAXParser();
+ } catch (ParserConfigurationException e) {
+ //e.printStackTrace();
+ logger.log(Level.FINER,"Uncaught exception", e);
+ }
+
+ XMLReader xmlreader = saxParser.getXMLReader();
+
+ try {
+ xmlreader.setFeature("http://xml.org/sax/features/validation", validate);
+ } catch (SAXException e) {
+ logger.finer("Cannot set validation to " + validate);
+ logger.log(Level.FINER,"Uncaught exception", e);
+ }
+
+ try {
+ xmlreader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",validate);
+ } catch (SAXNotRecognizedException e){
+ //e.printStackTrace();
+ logger.finer("Cannot set load-external-dtd to" + validate);
+ logger.log(Level.FINER,"Uncaught exception", e);
+ //System.err.println("Cannot set load-external-dtd to" + validate);
+ }
+
+
+ //DAS_DNA_Handler cont_handle = new DAS_DNA_Handler() ;
+ DAS_Sequence_Handler cont_handle = new DAS_Sequence_Handler() ;
+ xmlreader.setContentHandler(cont_handle);
+ xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
+ InputSource insource = new InputSource() ;
+ insource.setByteStream(dasInStream);
+
+ xmlreader.parse(insource);
+ String sequence = cont_handle.get_sequence();
+ version = cont_handle.getVersion();
+ //logger.finest("Got sequence from DAS: " +sequence);
+
+ logger.exiting(this.getClass().getName(), "retreiveSequence", sequence);
+ return sequence ;
+ }
+
+ private InputStream open(URL url) {
+ {
+
+ InputStream inStream = null;
+ try{
+
+
+
+
+ HttpURLConnection huc = null;
+
+ huc = DAS_FeatureRetrieve.openHttpURLConnection(url);
+
+
+ logger.finest(huc.getResponseMessage());
+
+ inStream = huc.getInputStream();
+
+
+ }
+ catch ( Exception ex){
+ ex.printStackTrace();
+ logger.log(Level.WARNING,"exception occured", ex);
+ }
+
+ return inStream;
+ }
+
+ }
+
+}
Date leaseDate;
String id;
boolean local;
-
+ Map properties;
boolean alertAdmin;
public static String EMPTY_ID = "UNK:-1";
{
return capabilities;
}
+ /** test if a this source has a particular capability
+ *
+ * @param testCapability
+ * @return <code>true</code> if the server has this capability.
+ */
+ public boolean hasCapability(String testCapability){
+ for (int i=0 ; i< capabilities.length;i++){
+ String cap = capabilities[i];
+ if ( cap.equals(testCapability))
+ return true;
+ }
+ return false;
+ }
public DasCoordinateSystem[] getCoordinateSystem()
{
public boolean getAlertAdmin()
{
return alertAdmin;
- }
+ }
+ public Map getProperties() {
+ return properties;
+ }
+ public void setProperties(Map properties) {
+ this.properties = properties;
+ }
}
return match;
}
+
+ public int hashCode() {
+ int h = 7;
+
+ h = 31 * h + ( null == name ? 0 : name.hashCode());
+ h = 31 * h + ( null == category ? 0 : category.hashCode());
+
+ return h;
+ }
public Object clone()
{
public void setCoordinateSystem(DasCoordinateSystem[] u);
public void setCapabilities(String[] u);
-
+ /** test if a this source has a particular capability
+ *
+ * @param testCapability
+ * @return <code>true</code> if the server has this capability.
+ */
+ public boolean hasCapability(String testCapability);
public String getUrl();
public String getAdminemail();
public void setAlertAdmin(boolean flag);
public boolean getAlertAdmin();
+
+ /** set Properties for this DAS source, e.g. project name
+ *
+ * @param properties
+ */
+ public void setProperties(Map properties);
+
+ /** get Properties for this DAS source
+ *
+ * @return Properties
+ */
+ public Map getProperties();
+
}
\ No newline at end of file
private final String name;
private static final Map COMPS_BY_NAME;
+ private static final int TWODAYS = 1000 * 60 * 60 * 24 * 2;
public DasSourceComparator(String str)
{
return ds.getNickname();
}
};
+ public static final Comparator BY_STATUS = new DasSourceComparator("status"){
+ protected Comparable getField(DasSource ds) {
+
+ Date now = new Date();
+
+ if (ds.getLeaseDate().getTime() < (now.getTime() - TWODAYS))
+ return new Integer(0);
+ return new Integer(1);
+ }
+ };
+
+
public static final Comparator BY_REGISTER_DATE = new DasSourceComparator(
"registerdate")
{
COMPS_BY_NAME.put(BY_DESCRIPTION.toString(), BY_DESCRIPTION);
COMPS_BY_NAME.put(BY_CAPABILITIES.toString(), BY_CAPABILITIES);
COMPS_BY_NAME.put(BY_COORDINATE_SYSTEM.toString(), BY_COORDINATE_SYSTEM);
+ COMPS_BY_NAME.put(BY_STATUS.toString(), BY_STATUS);
+
}
public static Comparator fromString(String name)
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on Nov 17, 2006
+ *
+ */
+
+package org.biojava.dasobert.eventmodel;
+
+import org.biojava.dasobert.dasregistry.Das1Source;
+
+public class AbstractDasEvent {
+
+ Das1Source dasSource;
+
+ public Das1Source getSource() {
+ return dasSource;
+ }
+
+ public void setSource(Das1Source source) {
+ this.dasSource = source;
+ }
+
+
+
+
+
+}
import org.biojava.dasobert.dasregistry.*;
-public class FeatureEvent
+public class FeatureEvent extends AbstractDasEvent
{
Map[] features;
- Das1Source dasSource;
int comeBackLater;
-
- public FeatureEvent(Map[] features, Das1Source dasSource)
+ String version;
+
+ public FeatureEvent(Map[] features, Das1Source dasSource, String version)
{
super();
this.features = features;
this.dasSource = dasSource;
comeBackLater = -1;
+ this.version = version;
}
public int getComeBackLater()
return features;
}
- public Das1Source getDasSource()
- {
- return dasSource;
- }
+ /** Get the version of the reference object that has been annotated.
+ * Compare the version string with the version string obtained from the reference server.
+ * If they don;t match there is a version problem between the annotation and the reference!
+ * @return the version string (e.g. an MD5 digest of the reference sequence)
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
}
*/
package org.biojava.dasobert.eventmodel;
-public class SequenceEvent
+public class SequenceEvent extends AbstractDasEvent
{
String sequence;
String accessionCode;
- public SequenceEvent(String accessionCode, String seq)
+ String version;
+
+ public SequenceEvent(String accessionCode, String seq, String version)
{
super();
sequence = seq;
this.accessionCode = accessionCode;
+ this.version = version; // bugfix here ?
}
public String getAccessionCode()
return sequence;
}
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on Feb 9, 2005
+ *
+ */
+package org.biojava.dasobert.feature;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/** An Abstract class representing a Feature as being diplayed in the SeqFeaturePanel
+ * A feature corresponds to everything that is visible in a "line" and can contain one or multiple Segments.
+ *
+ *
+ * @author Andreas Prlic
+ *
+ */
+public abstract class AbstractFeatureTrack implements FeatureTrack,Cloneable {
+
+ String name;
+ String method;
+ String type;
+ List segments ;
+ String note;
+ String link;
+ String source;
+ String score;
+ String orientation;
+ String typeID;
+ String typeCategory;
+
+ public AbstractFeatureTrack() {
+ source = "Unknown";
+ method = "Unknown";
+ type = "Unknown";
+ note = "";
+ link = "";
+ score = "";
+ orientation = null;
+ segments = new ArrayList();
+
+ }
+
+ public abstract Object clone();
+
+
+ public String toString() {
+ String str = "Feature: method: " + method +" type: " + type ;
+ if ( name != null)
+ str += " name: " + name;
+
+ if (( note != null) && (! note.equals("null")))
+ {
+ if (note.length() > 40)
+ str += "note: " +note.substring(0,39) + "...";
+ else
+ str += " note: "+note;
+ }
+ str += " # segments: " + segments.size() ;
+ return str ;
+ }
+
+
+ /** returns true if the specified sequence position is within the range of this Feature
+ *
+ * @param seqPosition the position to check
+ * @return true if the position is within the ranges of the segments of this feature
+ */
+ public boolean overlaps(int seqPosition){
+ List segments = getSegments();
+ Iterator iter =segments.iterator();
+
+ while (iter.hasNext()){
+
+ Segment seg = (Segment) iter.next();
+ if ( seg.overlaps(seqPosition) )
+ return true;
+ }
+
+ return false;
+ }
+
+ public void setSource(String s) { source = s;}
+ public String getSource() { return source; };
+
+
+ public void setName(String nam) { name = nam; }
+ public String getName() { return name; }
+
+ public void setMethod(String methd) { method = methd ; }
+ public String getMethod() { return method ; }
+
+ public void setType(String typ) { type = typ ; }
+ public String getType() { return type ; }
+
+ public void setNote(String nte) {
+ if (nte != null)
+ note = nte;
+ }
+ public String getNote() { return note ; }
+
+ public void setLink(String lnk) { link = lnk;}
+ public String getLink() { return link;}
+
+ public void setScore(String s){ score = s;}
+ public String getScore() { return score;}
+
+ /** add a segment to this feature */
+ public void addSegment(int start, int end, String name) {
+ Segment s = new SegmentImpl() ;
+ s.setStart(start);
+ s.setEnd(end) ;
+ s.setName(name);
+ s.setParent(this);
+ segments.add(s);
+ }
+
+ public void addSegment( Segment s ){
+ s.setParent(this);
+ segments.add(s);
+ }
+
+ public List getSegments() {
+ return segments ;
+ }
+
+
+ public String getOrientation() {
+ return orientation;
+ }
+
+ public void setOrientation(String orientation) {
+ this.orientation = orientation;
+ }
+
+ /** test if two features are equivalent
+ * important: only comares type,method and source.
+ * The individual segments are not compared!
+ *
+ * */
+ public boolean equals(FeatureTrack feat) {
+// if ( note == null) {
+ // if (( feat.getNote() == null ) ||
+ // ( feat.getNote().equals(""))) {
+ //} else if ( this.note.equals(feat.getNote())){
+ // return true;
+ //}
+ if ( this.type.equals(feat.getType())){
+ if ( this.method.equals(feat.getMethod())){
+ if ( this.source.equals(feat.getSource())){
+ if (this.note.equals(feat.getNote())){
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+
+ }
+ public String getTypeCategory() {
+ // TODO Auto-generated method stub
+ return typeCategory;
+ }
+
+ public String getTypeID() {
+ // TODO Auto-generated method stub
+ return typeID;
+ }
+
+ public void setTypeCategory(String typeCategory) {
+ this.typeCategory = typeCategory;
+
+ }
+
+ public void setTypeID(String typeID) {
+ this.typeID = typeID;
+
+ }
+
+
+
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on May 22, 2007
+ *
+ */
+
+package org.biojava.dasobert.feature;
+
+import java.awt.Color;
+
+public abstract class AbstractSegment implements Segment,Cloneable {
+ int start ;
+ int end ;
+ String name ;
+ Color color ;
+ FeatureTrack parent ;
+ String txtColor ;
+ String note;
+
+ public abstract Object clone();
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#toString()
+ */
+ public String toString() {
+ String str = "Segment: " +name + " " +start + " " + end ;
+ if ( ( note != null ) && ( ! note.equals("null")))
+ if ( note.length() >40)
+ str += note.substring(0,39)+"...";
+ else
+ str += note;
+ return str ;
+ }
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#getNote()
+ */
+ public String getNote() {
+ return note;
+ }
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#setNote(java.lang.String)
+ */
+ public void setNote(String note) {
+ this.note = note;
+ }
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#setStart(int)
+ */
+ public void setStart(int strt) {start = strt ; }
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#getStart()
+ */
+ public int getStart() {return start ;}
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#setEnd(int)
+ */
+ public void setEnd(int ed) { end = ed;}
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#getEnd()
+ */
+ public int getEnd() { return end;}
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#setName(java.lang.String)
+ */
+ public void setName(String nam) { name = nam;}
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#getName()
+ */
+ public String getName() { return name ; }
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#setColor(java.awt.Color)
+ */
+ public void setColor(Color col) { color = col; }
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#getColor()
+ */
+ public Color getColor() { return color ; }
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#setParent(org.biojava.spice.feature.Feature)
+ */
+ public void setParent(FeatureTrack f) { parent = f;}
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#getParent()
+ */
+ public FeatureTrack getParent(){ return parent;}
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#setTxtColor(java.lang.String)
+ */
+ public void setTxtColor(String str) { txtColor = str; }
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#getTxtColor()
+ */
+ public String getTxtColor() { return txtColor;}
+
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#overlaps(int)
+ */
+ public boolean overlaps(int seqPosition){
+ if ( ( getStart() <= seqPosition) && ( getEnd() >= seqPosition)){
+ return true;
+ }
+ return false;
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.biojava.spice.feature.SegmentIF#overlaps(org.biojava.spice.feature.Segment)
+ */
+ public boolean overlaps(Segment segment){
+ if (! (this.start <= this.end ))
+ throw new IndexOutOfBoundsException("start > end for segment" + this);
+
+ if ( ! (segment.getStart() <= segment.getEnd() ))
+ throw new IndexOutOfBoundsException("start > end for segment" + segment);
+
+ // start must be in region of other
+ if ( this.start >= segment.getStart()){
+ if ( this.start <= segment.getEnd()){
+ return true;
+ }
+ }
+ // or end must be in region of other..
+ if ( this.end >= segment.getStart() ) {
+ if ( this.end <= segment.getEnd()){
+ return true;
+ }
+ }
+
+ if ( this.start <= segment.getStart() ) {
+ if ( this.end >= segment.getEnd() ) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on 23.09.2004
+ * @author Andreas Prlic
+ *
+ */
+
+
+package org.biojava.dasobert.feature ;
+
+import java.util.Comparator ;
+import java.util.Iterator;
+import java.util.List;
+
+
+/** a comparator to sort Features byt type
+ * @author Andreas Prlic
+ */
+
+public class FeatureComparator
+implements Comparator
+{
+
+ public FeatureComparator() {
+ }
+
+ public int compare(Object a, Object b) {
+ FeatureTrack x = (FeatureTrack) a;
+ FeatureTrack y = (FeatureTrack) b;
+
+ String typea = x.getType();
+ String typeb = y.getType();
+
+ if ( ! typea.equals(typeb))
+ return typea.compareTo(typeb);
+
+ List s1 = x.getSegments();
+ List s2 = y.getSegments();
+
+ Iterator iter1 = s1.iterator();
+ Iterator iter2 = s2.iterator();
+
+ while (iter1.hasNext()){
+ Segment seg1 = (Segment)iter1.next();
+ int start1 = seg1.getStart();
+
+ while (iter2.hasNext()){
+ Segment seg2 = (Segment)iter2.next();
+ int start2 = seg2.getStart();
+
+ if ( start1 < start2){
+ return -1;
+ } if ( start1 > start2){
+ return 1;
+ }
+
+ }
+ }
+
+ return 0;
+
+ }
+
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on 23.09.2004
+ * @author Andreas Prlic
+ *
+ */
+
+
+package org.biojava.dasobert.feature ;
+
+import java.util.Comparator ;
+import java.util.Map ;
+
+/** a comparator to sort Features if they are still in a Map ( sorts by type )
+ * @author Andreas Prlic
+ */
+
+public class FeatureMapComparator
+ implements Comparator
+{
+
+ public FeatureMapComparator() {
+ }
+
+ public int compare(Object a, Object b) {
+ Map x = (Map) a;
+ Map y = (Map) b;
+
+ String typea = (String)x.get("TYPE");
+ String typeb = (String)y.get("TYPE");
+
+
+
+ if ( isSecstruc(typea) && isSecstruc(typeb)) {
+ return 0 ;
+ }
+ return typea.compareTo(typeb);
+ }
+
+ public boolean isSecstruc(String type) {
+ if ( type.equals("HELIX")
+ ||
+ type.equals("STRAND")
+ ||
+ type.equals("TURN")
+ ) {
+ return true ;
+ }
+ return false ;
+ }
+
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on Feb 9, 2005
+ *
+ */
+package org.biojava.dasobert.feature;
+
+import java.util.List;
+
+/**
+ * A feature corresponds to a track in Ensembl
+ *
+ * @author Andreas Prlic
+ *
+ */
+public interface FeatureTrack {
+
+
+ public Object clone();
+
+ /** returns true if the specified sequence position is within the range of this Feature
+ *
+ * @param seqPosition the position to check
+ * @return true if the position is within the ranges of the segments of this feature
+ */
+ public boolean overlaps(int seqPosition);
+
+ public String toString();
+
+ public void setSource(String s);
+
+ public String getSource();
+
+ public void setName(String nam);
+
+ public String getName();
+
+ public void setMethod(String methd);
+
+ public String getMethod();
+
+ public void setType(String typ);
+
+ public String getType();
+
+ public void setNote(String nte);
+
+ public String getNote();
+
+ public void setLink(String lnk);
+
+ public String getLink();
+
+ public void setScore(String score);
+
+ public String getScore();
+
+ public void setOrientation(String orientation);
+
+ public String getOrientation();
+
+ /** test if two features are equivalent
+ *
+ * @param feat feature to compare with
+ * @return true if equivalend
+ */
+ public abstract boolean equals(FeatureTrack feat);
+
+ /** add a segment to this feature
+ *
+ * @param start position
+ * @param end position
+ * @param name of feature
+ */
+ public abstract void addSegment(int start, int end, String name);
+
+ public abstract void addSegment(Segment s);
+
+ public abstract List getSegments();
+
+ /** set the data from the DAS - type - id field
+ * (used for Ontology support)
+ * @param typeID
+ */
+ public void setTypeID(String typeID);
+
+ /** set the data from the DAS - type - category field
+ * (used for Ontology support)
+ * @param typeCategory
+ */
+ public void setTypeCategory(String typeCategory);
+
+ public String getTypeID();
+ public String getTypeCategory();
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on Dec 5, 2007
+ *
+ */
+
+package org.biojava.dasobert.feature;
+
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+
+
+/** converts the features from their "raw" representation as a Map
+ * into a Feature class
+ * @author Andreas Prlic
+ *
+ */
+public class FeatureTrackConverter {
+
+ public static final Color HELIX_COLOR = new Color(255,51,51);
+ public static final Color STRAND_COLOR = new Color(255,204,51);
+ public static final Color TURN_COLOR = new Color(204,204,204);
+
+
+ // some annotation types, for which there is a special treatment
+ public static final String DISULFID_TYPE = "DISULFID";
+ public static final String SECSTRUC_TYPE = "SECSTRUC";
+ public static final String METAL_TYPE = "METAL";
+ public static final String MSD_SITE_TYPE = "MSD_SITE";
+
+ String type;
+ public static final String TYPE_HISTOGRAM = "histogram";
+ public static final String TYPE_DEFAULT = "default";
+
+
+ // rotate between these colors
+ public static final Color[] entColors = new Color []{
+ new Color(51,51,255), // blue
+ new Color(102,255,255), // cyan
+ new Color(153,255,153), // green
+ new Color(153,255,153), // green
+ new Color(255,153,153), // pink
+ new Color(255,51,51), // red
+ new Color(255,51,255) // pink
+ };
+
+ public static final String[] txtColors = new String[] {
+ "blue",
+ "pink",
+ "green",
+ "yellow",
+ "red",
+ "cyan",
+ "pink"};
+
+ Map[] stylesheet;
+
+ boolean isHistogram = false;
+
+
+ public FeatureTrackConverter(){
+ type = TYPE_DEFAULT;
+ stylesheet = new Map[0];
+ }
+
+ public FeatureTrackConverter(Map[] stylesheet){
+
+ if (stylesheet == null)
+ stylesheet = new Map[0];
+
+ this.stylesheet = stylesheet;
+
+ }
+
+
+ public FeatureTrackConverter(Map[] stylesheet, boolean isHistogram){
+ this(stylesheet);
+ this.isHistogram = isHistogram;
+ if ( isHistogram)
+ type = TYPE_HISTOGRAM;
+ }
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ if ( type.equals(TYPE_HISTOGRAM))
+ isHistogram = true;
+ this.type = type;
+ }
+
+ public boolean isHistogram() {
+ return isHistogram;
+ }
+
+
+ public void setHistogram(boolean isHistogram) {
+ this.isHistogram = isHistogram;
+ }
+
+
+
+
+
+ public FeatureTrack[] convertMap2Features(Map[] mapfeatures){
+ List features = new ArrayList();
+
+ boolean first = true ;
+ boolean secstruc = false ;
+ boolean isGroup = false;
+
+ FeatureTrack feat = null ;
+ Segment segment = null ;
+
+ int featuresCounter = 0;
+ String prevGroup = null;
+
+ for (int i = 0 ; i< mapfeatures.length;i++) {
+
+ Map currentFeatureMap = mapfeatures[i];
+ String type = (String) currentFeatureMap.get("TYPE") ;
+
+
+
+ String group = (String) currentFeatureMap.get("GROUP");
+ if ( group != null){
+ if ( prevGroup != null) {
+ if ( group.equals(prevGroup)){
+ feat.setName(group);
+ isGroup = true;
+ } else {
+ isGroup = false;
+ }
+ } else {
+ isGroup = false;
+ }
+ } else {
+ isGroup = false;
+ }
+
+ // we are skipping literature references for the moment
+ // TODO: add a display to spice for non-positional features
+ //
+ if ( type.equals("reference") || type.equals("GOA")){
+ continue ;
+ }
+
+ if (! first)
+ {
+ // if not first feature
+
+ if ( (! secstruc ) && (! isGroup) ) {
+
+ // if not secondary structure and not in a group ...
+ features = testAddFeatures(features,feat);
+
+
+ } else if ( !
+ (
+ type.equals("HELIX") ||
+ type.equals("STRAND") ||
+ type.equals("TURN")
+ )
+ )
+ {
+ // end of secondary structure
+ secstruc = false ;
+ if ( feat != null && (! isGroup)) {
+ features = testAddFeatures(features,feat);
+ }
+
+ }
+ } // end of not first
+
+ first = false ;
+ if ( (! secstruc) && (! isGroup)) {
+ featuresCounter +=1;
+ feat = getNewFeat(currentFeatureMap);
+ }
+
+
+
+
+ if (type.equals("STRAND")){
+ secstruc = true ;
+ currentFeatureMap.put("colorTxt","yellow");
+ feat.setName("SECSTRUC");
+ feat.setType("SECSTRUC");
+ }
+
+ else if (type.equals("HELIX")) {
+ secstruc = true ;
+ currentFeatureMap.put("colorTxt","red");
+ feat.setName("SECSTRUC");
+ feat.setType("SECSTRUC");
+ }
+
+ else if (type.equals("TURN")) {
+ secstruc = true ;
+ currentFeatureMap.put("colorTxt","white");
+
+ feat.setName("SECSTRUC");
+ feat.setType("SECSTRUC");
+ }
+ else {
+ secstruc = false ;
+ currentFeatureMap.put("colorTxt",txtColors[featuresCounter%txtColors.length]);
+ if ( ! isGroup) {
+ try {
+ feat.setName(type);
+
+ } catch ( NullPointerException e) {
+ //e.printStackTrace();
+ feat.setName("null");
+ }
+ }
+ }
+
+ segment = getNewSegment(currentFeatureMap);
+
+ feat.addSegment(segment);
+ prevGroup = group;
+ }
+
+ if ( feat != null)
+ features =testAddFeatures(features,feat);
+
+
+ return (FeatureTrack[]) features.toArray(new FeatureTrack[features.size()]);
+ }
+
+ /** test if this features is added as a new feature to the features list,
+ * or if it is joint with an already existing one...
+ *
+ * @param features
+ * @param newFeature
+ * @return a List of FeatureTrack objects
+ */
+ protected List testAddFeatures(List features,FeatureTrack newFeature){
+
+ //System.out.println("testing " + newFeature + " " + newFeature.getScore());
+ Iterator iter = features.iterator();
+
+
+ if ( isHistogramFeatureType(newFeature)) {
+
+ // return histogram type features
+ type = TYPE_HISTOGRAM;
+
+ Segment seg = getHistogramSegmentFromFeature(newFeature);
+
+ while (iter.hasNext()){
+ FeatureTrack knownFeature = (FeatureTrack) iter.next() ;
+ String knownType = knownFeature.getType();
+
+ //System.out.println("found histogram style " + feat);
+ // set type of this DAS source to being HISTOGRAM style
+
+
+ if ( knownType.equals(newFeature.getType())){
+ // convert the feature into a HistogramSegment and add to the already known feature
+
+ knownFeature.addSegment(seg);
+ // we can return now
+ return features;
+ }
+
+
+ }
+ // we could not link this to any existing feature
+ // convert it to a new HistogramFeature
+ HistogramFeature hfeat = new HistogramFeature();
+
+ hfeat.setLink(newFeature.getLink());
+ hfeat.setMethod(newFeature.getMethod());
+ hfeat.setName(newFeature.getName());
+ hfeat.setNote(newFeature.getNote());
+ hfeat.setScore("0");
+ hfeat.setSource(newFeature.getSource());
+ hfeat.addSegment(seg);
+ hfeat.setType(newFeature.getType());
+
+ newFeature = hfeat;
+ features.add(newFeature);
+ return features;
+ }
+
+
+
+ while (iter.hasNext()){
+ FeatureTrack knownFeature = (FeatureTrack) iter.next() ;
+ // this only compares method source and type ...
+ boolean sameFeat = false;
+ if ( knownFeature.equals(newFeature))
+ sameFeat = true;
+
+ if ( ( knownFeature.getSource().equals(newFeature.getSource() )) &&
+ ( knownFeature.getMethod().equals(newFeature.getMethod())) &&
+ ( knownFeature.getNote().equals(newFeature.getNote())) &&
+ isSecondaryStructureFeat(knownFeature) &&
+ isSecondaryStructureFeat(newFeature))
+ sameFeat =true;
+
+ if ( sameFeat) {
+
+ // seems to be of same type, method and source, so check if the segments can be joined
+
+ List tmpsegs = knownFeature.getSegments();
+ Iterator segiter = tmpsegs.iterator();
+ List newsegs = newFeature.getSegments();
+ Iterator newsegsiter = newsegs.iterator();
+ boolean overlap = false;
+ while (newsegsiter.hasNext()){
+ Segment newseg = (Segment)newsegsiter.next();
+
+
+ while (segiter.hasNext()){
+ Segment tmpseg = (Segment) segiter.next();
+
+ if ( tmpseg.overlaps(newseg))
+ overlap = true;
+ }
+ }
+
+ if ( ! overlap){
+ // add all new segments to old features...
+ newsegsiter = newsegs.iterator();
+ while (newsegsiter.hasNext()){
+ Segment newseg = (Segment)newsegsiter.next();
+ knownFeature.addSegment(newseg);
+ }
+
+ return features;
+ }
+ }
+
+ }
+
+ // if we get here, the features could not be joint with any other one, so there is always some overlap
+ // add to the list of known features
+ features.add(newFeature);
+ return features;
+ }
+
+ private FeatureTrack getNewFeat(Map currentFeatureMap) {
+ FeatureTrack feat = new FeatureTrackImpl();
+ //logger.finest(currentFeatureMap);
+ //System.out.println("DrawableDasSource " + currentFeatureMap);
+ feat.setSource((String)currentFeatureMap.get("dassource"));
+ feat.setName( (String)currentFeatureMap.get("NAME"));
+ feat.setType( (String)currentFeatureMap.get("TYPE"));
+ feat.setLink( (String)currentFeatureMap.get("LINK"));
+ feat.setNote( (String)currentFeatureMap.get("NOTE"));
+
+ String typeID = (String) currentFeatureMap.get("TYPE_ID");
+ String typeCategory = (String) currentFeatureMap.get("TYPE_CATEGORY");
+ feat.setTypeID(typeID);
+ feat.setTypeCategory(typeCategory);
+
+ String method = (String)currentFeatureMap.get("METHOD");
+ if ( method == null) { method = "";}
+ feat.setMethod(method);
+ feat.setScore( (String)currentFeatureMap.get("SCORE"));
+ return feat ;
+ }
+
+ private Segment getNewSegment(Map featureMap) {
+ Segment s = new SegmentImpl();
+ String sstart = (String)featureMap.get("START") ;
+ String send = (String)featureMap.get("END") ;
+ int start = Integer.parseInt(sstart) ;
+ int end = Integer.parseInt(send) ;
+ s.setStart(start);
+ s.setEnd(end);
+ s.setName((String)featureMap.get("TYPE"));
+ s.setTxtColor((String)featureMap.get("colorTxt"));
+ s.setColor((Color)featureMap.get("color"));
+ s.setNote((String) featureMap.get("NOTE"));
+ return s ;
+
+ }
+
+ private boolean isSecondaryStructureFeat(FeatureTrack feat){
+ String type = feat.getType();
+ if (
+ type.equals("HELIX") ||
+ type.equals("STRAND") ||
+ type.equals("TURN")
+ ) return true;
+ return false;
+ }
+
+ private boolean isHistogramFeatureType(FeatureTrack feat){
+ String ftype = feat.getType();
+
+ Map[] style = stylesheet;
+
+ //System.out.println("is HistogramFeature type " + ftype + " " + style );
+
+
+ // todo : move this info into a config file...
+
+ if ( ftype.equals("hydrophobicity")){
+ return true;
+ }
+ if ( getType().equals(TYPE_HISTOGRAM) )
+ return true;
+
+
+
+ if (style != null ) {
+
+ for ( int i =0; i< style.length ; i++){
+ Map m = style[i];
+
+ // make sure the stylesheet is for this feature type
+ String styleType = (String) m.get("type");
+ if ( styleType != null) {
+ if ( ! styleType.equals(ftype)){
+ continue;
+ }
+ } else {
+ continue;
+ }
+
+ String type = (String) m.get("style");
+ if ( type != null) {
+ //System.out.println("stylesheet type " + type);
+ if ( type.equals("gradient") || ( type.equals("lineplot")) || ( type.equals("histogram"))){
+
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+ private HistogramSegment getHistogramSegmentFromFeature(FeatureTrack feat){
+ HistogramSegment s = new HistogramSegment();
+
+ double score = 0.0;
+
+ try {
+ score = Double.parseDouble(feat.getScore());
+
+ } catch (Exception e){
+ //e.printStackTrace();
+ }
+ s.setScore(score);
+ List segments = feat.getSegments();
+ if (segments.size() > 0){
+ Segment seg = (Segment) segments.get(0);
+ s.setName(seg.getName());
+ s.setStart(seg.getStart());
+ s.setEnd(seg.getEnd());
+ s.setNote(seg.getNote());
+ s.setColor(seg.getColor());
+ s.setTxtColor(seg.getTxtColor());
+ }
+
+
+ return s;
+ }
+
+
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on 22.09.2004
+ * @author Andreas Prlic
+ *
+ */
+
+package org.biojava.dasobert.feature;
+
+import java.util.Iterator;
+
+/** a class to store FeatureData and to visualize them
+ * coordinate system of features is always UniProt !
+ * PDBresnum features served by DAS need to be converted into UniProt coord sys first.
+ *
+ * a feature consists of one or several segments.
+ * segmetns cotnains <start> and <end> information.
+ *
+ * @author Andreas Prlic
+ */
+public class FeatureTrackImpl
+extends AbstractFeatureTrack
+implements FeatureTrack
+
+{
+
+
+ public Object clone(){
+
+ FeatureTrack f = new FeatureTrackImpl();
+ f.setName(name);
+ f.setMethod(method);
+ f.setType(type);
+ f.setNote(note);
+ f.setLink(link);
+ f.setSource(source);
+ f.setScore(score);
+
+ Iterator iter = segments.iterator();
+
+ while (iter.hasNext()){
+ Segment s = (Segment) iter.next();
+ f.addSegment((Segment)s.clone());
+ }
+
+ return f;
+
+ }
+
+
+
+}
+
+
+
+
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on May 22, 2007
+ *
+ */
+
+package org.biojava.dasobert.feature;
+
+
+import java.util.Iterator;
+
+/** a class that represents Histogram Style features
+ * in addition to normal features they know about Max and Minimum scores for the whole line
+ * Histogram feautes have only one (Histogram) Segment, which contains the scores for each position
+ *
+ * @author Andreas Prlic
+ *
+ */
+public class HistogramFeature
+ extends AbstractFeatureTrack {
+
+ double max;
+ double min;
+
+ public HistogramFeature() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+
+
+ public double getMax() {
+ return max;
+ }
+
+
+
+ public void setMax(double max) {
+ this.max = max;
+ }
+
+
+
+ public double getMin() {
+ return min;
+ }
+
+
+
+ public void setMin(double min) {
+ this.min = min;
+ }
+
+
+
+ public Object clone() {
+
+ HistogramFeature f = new HistogramFeature();
+
+ f.setName(name);
+ f.setMethod(method);
+ f.setType(type);
+ f.setNote(note);
+ f.setLink(link);
+ f.setSource(source);
+ f.setScore(score);
+
+ Iterator iter = segments.iterator();
+
+ while (iter.hasNext()){
+ Segment s = (Segment) iter.next();
+ f.addSegment((Segment)s.clone());
+ }
+
+ return f;
+
+
+ }
+
+
+
+
+
+
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on May 22, 2007
+ *
+ */
+
+package org.biojava.dasobert.feature;
+
+/** a Histogram segment is an extension of the standard Segment with a score
+ *
+ * @author Andreas Prlic
+ *
+ */
+public class HistogramSegment extends AbstractSegment {
+
+ double score;
+
+ public HistogramSegment() {
+ super();
+
+ }
+
+ public double getScore() {
+ return score;
+ }
+
+ public void setScore(double score) {
+ this.score = score;
+ }
+
+
+ public Object clone(){
+
+ Segment s = new HistogramSegment();
+ s.setStart(start);
+ s.setEnd(end);
+ s.setName(name);
+ s.setColor(color);
+ s.setTxtColor(txtColor);
+ s.setNote(note);
+ return s;
+
+ }
+
+
+
+
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on 22.09.2004
+ * @author Andreas Prlic
+ *
+ */
+
+package org.biojava.dasobert.feature ;
+
+import java.awt.Color;
+
+
+/** a class to keep track of location information for a feature */
+public interface Segment {
+
+ public Object clone();
+
+ public String toString();
+
+ public String getNote();
+
+ public void setNote(String note);
+
+ public void setStart(int strt);
+
+ public int getStart();
+
+ public void setEnd(int ed);
+
+ public int getEnd();
+
+ public void setName(String nam);
+
+ public String getName();
+
+ public void setColor(Color col);
+
+ public Color getColor();
+
+ public void setParent(FeatureTrack f);
+
+ public FeatureTrack getParent();
+
+ public void setTxtColor(String str);
+
+ public String getTxtColor();
+
+ /** returns true if the specified sequence position is within the range of this Segment
+ *
+ * @param seqPosition the position to check
+ * @return true if seqPos >= start && seqPos <= end
+ */
+ public boolean overlaps(int seqPosition);
+
+ /** tests if two segments are overlapping
+ *
+ * @param segment to compare with
+ * @return true if segments overlap
+ */
+ public boolean overlaps(Segment segment);
+
+
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on May 22, 2007
+ *
+ */
+
+package org.biojava.dasobert.feature;
+
+import java.util.Comparator;
+
+public class SegmentComparator implements Comparator {
+
+ public int compare(Object arg0, Object arg1) {
+
+ Segment s1 = (Segment) arg0;
+ Segment s2 = (Segment) arg1;
+
+ if (s1.getStart() < s2.getStart())
+ return -1;
+ if (s1.getStart() > s2.getStart())
+ return 1;
+
+ return 0;
+ }
+
+}
--- /dev/null
+/*
+ * BioJava development code
+ *
+ * This code may be freely distributed and modified under the
+ * terms of the GNU Lesser General Public Licence. This should
+ * be distributed with the code. If you do not have a copy,
+ * see:
+ *
+ * http://www.gnu.org/copyleft/lesser.html
+ *
+ * Copyright for this code is held jointly by the individual
+ * authors. These should be listed in @author doc comments.
+ *
+ * For more information on the BioJava project and its aims,
+ * or to join the biojava-l mailing list, visit the home page
+ * at:
+ *
+ * http://www.biojava.org/
+ *
+ * Created on May 22, 2007
+ *
+ */
+
+package org.biojava.dasobert.feature;
+
+import java.awt.Color;
+
+public class SegmentImpl extends AbstractSegment {
+
+ public SegmentImpl() {
+ super();
+ start = 0 ;
+ end = 0 ;
+ name = "Unknown";
+ color = Color.white ;
+ txtColor = "white" ;
+ parent = null ;
+ note = "";
+ }
+
+ public boolean equals(Segment s){
+ if ( s == null)
+ return false;
+
+ if ( ( start == s.getStart() ) &&
+ ( end == s.getEnd() ) &&
+ ( name.equals(s.getName()))
+ )
+ {
+ if ( note == null) {
+ if (s.getNote() == null)
+ return true;
+ } else {
+ if (s.getNote() != null){
+ if (s.getNote().equals(note))
+ return true;
+ }
+ }
+
+ }
+
+
+ return false;
+ }
+
+ public Object clone(){
+
+ Segment s = new SegmentImpl();
+ s.setStart(start);
+ s.setEnd(end);
+ s.setName(name);
+ s.setColor(color);
+ s.setTxtColor(txtColor);
+ s.setNote(note);
+ return s;
+
+ }
+}