From: jprocter Date: Fri, 1 Aug 2008 13:19:10 +0000 (+0000) Subject: updated jalview version of dasobert 1.53e client and added Das Sequence Source discov... X-Git-Tag: Release_2_4~71 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=54e003f9b2fff47dbfea6401c3944afdb7bd37b3;p=jalview.git updated jalview version of dasobert 1.53e client and added Das Sequence Source discovery to the sequence fetcher --- diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java index 67bcdbf..b007e13 100644 --- a/src/jalview/ws/DBRefFetcher.java +++ b/src/jalview/ws/DBRefFetcher.java @@ -40,7 +40,7 @@ public class DBRefFetcher implements Runnable { SequenceI[] dataset; - AlignFrame af; + IProgressIndicator af; CutAndPasteTransfer output = new CutAndPasteTransfer(); diff --git a/src/jalview/ws/DasSequenceFeatureFetcher.java b/src/jalview/ws/DasSequenceFeatureFetcher.java index 1e7ea06..137bdb8 100644 --- a/src/jalview/ws/DasSequenceFeatureFetcher.java +++ b/src/jalview/ws/DasSequenceFeatureFetcher.java @@ -51,7 +51,23 @@ public class DasSequenceFeatureFetcher Vector selectedSources; boolean cancelled = false; - + private void debug(String mesg) + { + debug(mesg, null); + } + private void debug(String mesg, Exception e) + { + if (Cache.log!=null) + { + debug(mesg, e); + } else { + System.err.println(mesg); + if (e!=null) + { + e.printStackTrace(); + } + } + } long startTime; /** @@ -157,7 +173,10 @@ public class DasSequenceFeatureFetcher { cancelled = false; startTime = System.currentTimeMillis(); - af.setProgressBar("Fetching DAS Sequence Features", startTime); + if (af!=null) + { + af.setProgressBar("Fetching DAS Sequence Features", startTime); + } DasSource[] sources = new jalview.gui.DasSourceBrowser().getDASSource(); @@ -336,7 +355,7 @@ public class DasSequenceFeatureFetcher && jalview.util.DBRefUtils.isDasCoordinateSystem( cs[csIndex].getName(), uprefs[j])) { - Cache.log.debug("Launched fetcher for coordinate system " + debug("Launched fetcher for coordinate system " + cs[0].getName()); // Will have to pass any mapping information to the fetcher //- the start/end for the DBRefEntry may not be the same as the sequence's start/end @@ -407,7 +426,7 @@ public class DasSequenceFeatureFetcher responseComplete(dasSource, seq); // reduce thread count anyhow return; } - Cache.log.debug("new Das Feature Fetcher for " + dbref.getSource() + debug("new Das Feature Fetcher for " + dbref.getSource() + ":" + dbref.getAccessionId() + " querying " + dasSource.getUrl()); FeatureThread fetcher = new FeatureThread(dbref.getAccessionId() @@ -419,7 +438,7 @@ public class DasSequenceFeatureFetcher public void comeBackLater(FeatureEvent e) { responseComplete(dasSource, seq); - Cache.log.debug("das source " + e.getDasSource().getNickname() + debug("das source " + e.getSource().getNickname() + " asked us to come back in " + e.getComeBackLater() + " secs."); } @@ -427,11 +446,11 @@ public class DasSequenceFeatureFetcher public void newFeatures(FeatureEvent e) { - Das1Source ds = e.getDasSource(); + Das1Source ds = e.getSource(); Map[] features = e.getFeatures(); // add features to sequence - Cache.log.debug("das source " + ds.getUrl() + " returned " + debug("das source " + ds.getUrl() + " returned " + features.length + " features"); if (features.length > 0) @@ -443,7 +462,7 @@ public class DasSequenceFeatureFetcher if (dbref.getMap() != null && f.getBegin() > 0 && f.getEnd() > 0) { - Cache.log.debug("mapping from " + f.getBegin() + " - " + debug("mapping from " + f.getBegin() + " - " + f.getEnd()); SequenceFeature vf[] = null; @@ -466,7 +485,7 @@ public class DasSequenceFeatureFetcher { for (int v = 0; v < vf.length; v++) { - Cache.log.debug("mapping to " + v + ": " + debug("mapping to " + v + ": " + vf[v].getBegin() + " - " + vf[v].getEnd()); seq.addSequenceFeature(vf[v]); } @@ -510,7 +529,7 @@ public class DasSequenceFeatureFetcher } if (id != null && id.length() > 0) { - Cache.log.debug("new Das Feature Fetcher for " + id + " querying " + debug("new Das Feature Fetcher for " + id + " querying " + dasSource.getUrl()); FeatureThread fetcher = new FeatureThread(id // + ":" + start + "," + end, @@ -521,7 +540,7 @@ public class DasSequenceFeatureFetcher public void comeBackLater(FeatureEvent e) { responseComplete(dasSource, seq); - Cache.log.debug("das source " + e.getDasSource().getNickname() + debug("das source " + e.getSource().getNickname() + " asked us to come back in " + e.getComeBackLater() + " secs."); } @@ -529,11 +548,11 @@ public class DasSequenceFeatureFetcher public void newFeatures(FeatureEvent e) { - Das1Source ds = e.getDasSource(); + Das1Source ds = e.getSource(); Map[] features = e.getFeatures(); // add features to sequence - Cache.log.debug("das source " + ds.getUrl() + " returned " + debug("das source " + ds.getUrl() + " returned " + features.length + " features"); if (features.length > 0) @@ -563,7 +582,7 @@ public class DasSequenceFeatureFetcher fetcher.start(); } else { // invalid fetch - indicate it is finished. - Cache.log.debug("Skipping empty ID for querying " + debug("Skipping empty ID for querying " + dasSource.getUrl()); responseComplete(dasSource, seq); } @@ -635,7 +654,7 @@ public class DasSequenceFeatureFetcher System.out.println("ERRR " + e); e.printStackTrace(); System.out.println("############"); - Cache.log.debug("Failed to parse " + dasfeature.toString(), e); + debug("Failed to parse " + dasfeature.toString(), e); return null; } } diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index da2dab6..073d448 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -3,6 +3,11 @@ package jalview.ws; import java.util.Enumeration; import java.util.Vector; +import org.biojava.dasobert.das2.Das2Source; +import org.biojava.dasobert.dasregistry.Das1Source; +import org.biojava.dasobert.dasregistry.DasCoordinateSystem; +import org.biojava.dasobert.dasregistry.DasSource; + import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefSource; @@ -32,7 +37,8 @@ public class SequenceFetcher extends ASequenceFetcher addDBRefSourceImpl(jalview.ws.dbsources.UnprotName.class); addDBRefSourceImpl(jalview.ws.dbsources.Pdb.class); addDBRefSourceImpl(jalview.ws.dbsources.Pfam.class); - }; + registerDasSequenceSources(); + } /** * simple run method to test dbsources. * @param argv @@ -84,12 +90,12 @@ public class SequenceFetcher extends ASequenceFetcher continue; DbSourceProxy sp = sfetcher.getSourceProxy(db); System.out - .println("" + db + ": retrieving test:" + sp.getTestQuery()); + .println("Source: "+sp.getDbName()+" (" + db + "): retrieving test:" + sp.getTestQuery()); AlignmentI al = null; try { al = sp.getSequenceRecords(sp.getTestQuery()); - if (al != null && al.getHeight() > 0) + if (al != null && al.getHeight() > 0 && sp.getDbSourceProperties()!=null) { boolean dna = sp.getDbSourceProperties().containsKey( DBRefSource.DNACODINGSEQDB) @@ -213,4 +219,54 @@ public class SequenceFetcher extends ASequenceFetcher } } + /** + * query the currently defined DAS source registry for sequence sources and add a DasSequenceSource instance for each source to the SequenceFetcher source list. + */ + public void registerDasSequenceSources() { + DasSource[] sources = jalview.ws.DasSequenceFeatureFetcher.getDASSources(); + for (int s=0;s 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) @@ -126,28 +164,44 @@ public class DAS_Feature_Handler } 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")) @@ -157,18 +211,32 @@ public class DAS_Feature_Handler 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"); + } } @@ -189,9 +257,10 @@ public class DAS_Feature_Handler 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")) @@ -212,15 +281,16 @@ public class DAS_Feature_Handler } } - 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]); + } - } + } } diff --git a/src/org/biojava/dasobert/das/DAS_Sequence_Handler.java b/src/org/biojava/dasobert/das/DAS_Sequence_Handler.java new file mode 100755 index 0000000..0e3f5b5 --- /dev/null +++ b/src/org/biojava/dasobert/das/DAS_Sequence_Handler.java @@ -0,0 +1,145 @@ +/* + * 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; + } + +} diff --git a/src/org/biojava/dasobert/das/FeatureThread.java b/src/org/biojava/dasobert/das/FeatureThread.java index 83219df..e7c9df9 100755 --- a/src/org/biojava/dasobert/das/FeatureThread.java +++ b/src/org/biojava/dasobert/das/FeatureThread.java @@ -135,6 +135,7 @@ public class FeatureThread } 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) @@ -147,7 +148,7 @@ public class FeatureThread // notify FeatureListeners Map[] feats = (Map[]) features.toArray(new Map[features.size()]); - notifyFeatureListeners(feats); + notifyFeatureListeners(feats, version); break; @@ -162,10 +163,10 @@ public class FeatureThread 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()) { @@ -180,7 +181,7 @@ public class FeatureThread */ 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()) diff --git a/src/org/biojava/dasobert/das/SequenceThread.java b/src/org/biojava/dasobert/das/SequenceThread.java new file mode 100755 index 0000000..efdd50f --- /dev/null +++ b/src/org/biojava/dasobert/das/SequenceThread.java @@ -0,0 +1,268 @@ +/* + * 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; + } + + } + +} diff --git a/src/org/biojava/dasobert/dasregistry/Das1Source.java b/src/org/biojava/dasobert/dasregistry/Das1Source.java index 4b8ae2a..e7541b4 100755 --- a/src/org/biojava/dasobert/dasregistry/Das1Source.java +++ b/src/org/biojava/dasobert/dasregistry/Das1Source.java @@ -49,7 +49,7 @@ public class Das1Source Date leaseDate; String id; boolean local; - + Map properties; boolean alertAdmin; public static String EMPTY_ID = "UNK:-1"; @@ -209,6 +209,19 @@ public class Das1Source { return capabilities; } + /** test if a this source has a particular capability + * + * @param testCapability + * @return true 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() { @@ -263,6 +276,12 @@ public class Das1Source public boolean getAlertAdmin() { return alertAdmin; - } + } + public Map getProperties() { + return properties; + } + public void setProperties(Map properties) { + this.properties = properties; + } } diff --git a/src/org/biojava/dasobert/dasregistry/DasCoordinateSystem.java b/src/org/biojava/dasobert/dasregistry/DasCoordinateSystem.java index 4cb6212..48508d9 100755 --- a/src/org/biojava/dasobert/dasregistry/DasCoordinateSystem.java +++ b/src/org/biojava/dasobert/dasregistry/DasCoordinateSystem.java @@ -83,6 +83,15 @@ public class DasCoordinateSystem 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() { diff --git a/src/org/biojava/dasobert/dasregistry/DasSource.java b/src/org/biojava/dasobert/dasregistry/DasSource.java index a5f3619..fffda83 100755 --- a/src/org/biojava/dasobert/dasregistry/DasSource.java +++ b/src/org/biojava/dasobert/dasregistry/DasSource.java @@ -67,7 +67,12 @@ public interface DasSource public void setCoordinateSystem(DasCoordinateSystem[] u); public void setCapabilities(String[] u); - + /** test if a this source has a particular capability + * + * @param testCapability + * @return true if the server has this capability. + */ + public boolean hasCapability(String testCapability); public String getUrl(); public String getAdminemail(); @@ -101,5 +106,18 @@ public interface DasSource 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 diff --git a/src/org/biojava/dasobert/dasregistry/DasSourceComparator.java b/src/org/biojava/dasobert/dasregistry/DasSourceComparator.java index 2f9db76..3d95d1a 100755 --- a/src/org/biojava/dasobert/dasregistry/DasSourceComparator.java +++ b/src/org/biojava/dasobert/dasregistry/DasSourceComparator.java @@ -38,6 +38,7 @@ public abstract class DasSourceComparator 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) { @@ -61,6 +62,18 @@ public abstract class DasSourceComparator 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") { @@ -131,6 +144,8 @@ public abstract class DasSourceComparator 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) diff --git a/src/org/biojava/dasobert/eventmodel/AbstractDasEvent.java b/src/org/biojava/dasobert/eventmodel/AbstractDasEvent.java new file mode 100644 index 0000000..9d8e101 --- /dev/null +++ b/src/org/biojava/dasobert/eventmodel/AbstractDasEvent.java @@ -0,0 +1,44 @@ +/* + * 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; + } + + + + + +} diff --git a/src/org/biojava/dasobert/eventmodel/FeatureEvent.java b/src/org/biojava/dasobert/eventmodel/FeatureEvent.java index 44de5cc..26711bc 100755 --- a/src/org/biojava/dasobert/eventmodel/FeatureEvent.java +++ b/src/org/biojava/dasobert/eventmodel/FeatureEvent.java @@ -26,19 +26,20 @@ import java.util.*; 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() @@ -69,9 +70,17 @@ public class FeatureEvent 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; + } } diff --git a/src/org/biojava/dasobert/eventmodel/SequenceEvent.java b/src/org/biojava/dasobert/eventmodel/SequenceEvent.java index 2cbc79e..1c4f38e 100755 --- a/src/org/biojava/dasobert/eventmodel/SequenceEvent.java +++ b/src/org/biojava/dasobert/eventmodel/SequenceEvent.java @@ -22,16 +22,19 @@ */ 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() @@ -44,4 +47,13 @@ public class SequenceEvent return sequence; } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + } diff --git a/src/org/biojava/dasobert/feature/AbstractFeatureTrack.java b/src/org/biojava/dasobert/feature/AbstractFeatureTrack.java new file mode 100644 index 0000000..af6236f --- /dev/null +++ b/src/org/biojava/dasobert/feature/AbstractFeatureTrack.java @@ -0,0 +1,200 @@ +/* + * 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; + + } + + + +} diff --git a/src/org/biojava/dasobert/feature/AbstractSegment.java b/src/org/biojava/dasobert/feature/AbstractSegment.java new file mode 100644 index 0000000..daa7f75 --- /dev/null +++ b/src/org/biojava/dasobert/feature/AbstractSegment.java @@ -0,0 +1,163 @@ +/* + * 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; + } +} diff --git a/src/org/biojava/dasobert/feature/FeatureComparator.java b/src/org/biojava/dasobert/feature/FeatureComparator.java new file mode 100644 index 0000000..900d196 --- /dev/null +++ b/src/org/biojava/dasobert/feature/FeatureComparator.java @@ -0,0 +1,81 @@ +/* + * 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; + + } + +} diff --git a/src/org/biojava/dasobert/feature/FeatureMapComparator.java b/src/org/biojava/dasobert/feature/FeatureMapComparator.java new file mode 100644 index 0000000..8aa747b --- /dev/null +++ b/src/org/biojava/dasobert/feature/FeatureMapComparator.java @@ -0,0 +1,69 @@ +/* + * 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 ; + } + +} diff --git a/src/org/biojava/dasobert/feature/FeatureTrack.java b/src/org/biojava/dasobert/feature/FeatureTrack.java new file mode 100644 index 0000000..42136ee --- /dev/null +++ b/src/org/biojava/dasobert/feature/FeatureTrack.java @@ -0,0 +1,113 @@ +/* + * 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 diff --git a/src/org/biojava/dasobert/feature/FeatureTrackConverter.java b/src/org/biojava/dasobert/feature/FeatureTrackConverter.java new file mode 100644 index 0000000..d7dee86 --- /dev/null +++ b/src/org/biojava/dasobert/feature/FeatureTrackConverter.java @@ -0,0 +1,490 @@ +/* + * 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; + } + + +} diff --git a/src/org/biojava/dasobert/feature/FeatureTrackImpl.java b/src/org/biojava/dasobert/feature/FeatureTrackImpl.java new file mode 100644 index 0000000..8eaf6f8 --- /dev/null +++ b/src/org/biojava/dasobert/feature/FeatureTrackImpl.java @@ -0,0 +1,73 @@ +/* + * 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 and 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; + + } + + + +} + + + + diff --git a/src/org/biojava/dasobert/feature/HistogramFeature.java b/src/org/biojava/dasobert/feature/HistogramFeature.java new file mode 100644 index 0000000..ef26891 --- /dev/null +++ b/src/org/biojava/dasobert/feature/HistogramFeature.java @@ -0,0 +1,102 @@ +/* + * 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; + + + } + + + + + + +} diff --git a/src/org/biojava/dasobert/feature/HistogramSegment.java b/src/org/biojava/dasobert/feature/HistogramSegment.java new file mode 100644 index 0000000..2b0fd8b --- /dev/null +++ b/src/org/biojava/dasobert/feature/HistogramSegment.java @@ -0,0 +1,65 @@ +/* + * 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; + + } + + + + +} diff --git a/src/org/biojava/dasobert/feature/Segment.java b/src/org/biojava/dasobert/feature/Segment.java new file mode 100644 index 0000000..f2a0bb6 --- /dev/null +++ b/src/org/biojava/dasobert/feature/Segment.java @@ -0,0 +1,80 @@ +/* + * 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); + + +} diff --git a/src/org/biojava/dasobert/feature/SegmentComparator.java b/src/org/biojava/dasobert/feature/SegmentComparator.java new file mode 100644 index 0000000..535576f --- /dev/null +++ b/src/org/biojava/dasobert/feature/SegmentComparator.java @@ -0,0 +1,43 @@ +/* + * 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; + } + +} diff --git a/src/org/biojava/dasobert/feature/SegmentImpl.java b/src/org/biojava/dasobert/feature/SegmentImpl.java new file mode 100644 index 0000000..5a0585f --- /dev/null +++ b/src/org/biojava/dasobert/feature/SegmentImpl.java @@ -0,0 +1,78 @@ +/* + * 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; + + } +}