X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FDasSequenceFeatureFetcher.java;h=b4a7bfde7e802e7665cbf5f68cc324bb6bc10aa3;hb=f5a2fd32ad34d909ba7326ab40c1709cf00bdf32;hp=ef48d9fc186dbecbedba1c75ec41d95c503985fa;hpb=db1e52b178b349f9b43ea05de525fc5350270d58;p=jalview.git diff --git a/src/jalview/ws/DasSequenceFeatureFetcher.java b/src/jalview/ws/DasSequenceFeatureFetcher.java index ef48d9f..b4a7bfd 100644 --- a/src/jalview/ws/DasSequenceFeatureFetcher.java +++ b/src/jalview/ws/DasSequenceFeatureFetcher.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1) + * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,6 +31,7 @@ import org.biojava.dasobert.eventmodel.*; import jalview.bin.Cache; import jalview.datamodel.*; import jalview.gui.*; +import jalview.util.UrlLink; /** * DOCUMENT ME! @@ -89,17 +90,37 @@ public class DasSequenceFeatureFetcher this(sequences, fsettings, selectedSources, true, true); } - public DasSequenceFeatureFetcher(SequenceI[] sequences, - FeatureSettings fsettings, Vector selectedSources, + public DasSequenceFeatureFetcher(SequenceI[] oursequences, + FeatureSettings fsettings, Vector ourselectedSources, boolean checkDbrefs, boolean promptFetchDbrefs) { - this.selectedSources = selectedSources; - this.sequences = sequences; + this.selectedSources = new Vector(); + Enumeration sources = ourselectedSources.elements(); + // filter both sequences and sources to eliminate duplicates + while (sources.hasMoreElements()) + { + Object src = sources.nextElement(); + if (!selectedSources.contains(src)) { + selectedSources.addElement(src); + }; + } + Vector sqs = new Vector(); + for (int i=0; i jalview sequence feature transformation SequenceFeature f = newSequenceFeature(features[i], source .getNickname()); - if (dbref.getMap() != null && f.getBegin() > 0 - && f.getEnd() > 0) + if (!parseSeqFeature(seq, f, features[i], source)) { - debug("mapping from " + f.getBegin() + " - " + f.getEnd()); - SequenceFeature vf[] = null; - - try - { - vf = dbref.getMap().locateFeature(f); - } catch (Exception ex) + if (dbref.getMap() != null && f.getBegin() > 0 + && f.getEnd() > 0) { - Cache.log - .info("Error in 'experimental' mapping of features. Please try to reproduce and then report info to help@jalview.org."); - Cache.log.info("Mapping feature from " + f.getBegin() - + " to " + f.getEnd() + " in dbref " - + dbref.getAccessionId() + " in " - + dbref.getSource()); - Cache.log.info("using das Source " + ds.getUrl()); - Cache.log.info("Exception", ex); - } + debug("mapping from " + f.getBegin() + " - " + f.getEnd()); + SequenceFeature vf[] = null; - if (vf != null) - { - for (int v = 0; v < vf.length; v++) + try { - debug("mapping to " + v + ": " + vf[v].getBegin() + " - " - + vf[v].getEnd()); - seq.addSequenceFeature(vf[v]); + vf = dbref.getMap().locateFeature(f); + } catch (Exception ex) + { + Cache.log + .info("Error in 'experimental' mapping of features. Please try to reproduce and then report info to jalview-discuss@jalview.org."); + Cache.log.info("Mapping feature from " + f.getBegin() + + " to " + f.getEnd() + " in dbref " + + dbref.getAccessionId() + " in " + + dbref.getSource()); + Cache.log.info("using das Source " + ds.getUrl()); + Cache.log.info("Exception", ex); + } + + if (vf != null) + { + for (int v = 0; v < vf.length; v++) + { + debug("mapping to " + v + ": " + vf[v].getBegin() + + " - " + vf[v].getEnd()); + seq.addSequenceFeature(vf[v]); + } } } - } - else - { - seq.addSequenceFeature(f); + else + { + seq.addSequenceFeature(f); + } } } - featuresAdded(seq); } else @@ -578,10 +609,14 @@ public class DasSequenceFeatureFetcher { for (int i = 0; i < features.length; i++) { + // standard DAS feature-> jalview sequence feature transformation SequenceFeature f = newSequenceFeature(features[i], source .getNickname()); - - seq.addSequenceFeature(f); + if (!parseSeqFeature(seq, f, features[i], source)) + { + // just add as a simple sequence feature + seq.addSequenceFeature(f); + } } featuresAdded(seq); @@ -609,6 +644,99 @@ public class DasSequenceFeatureFetcher } /** + * examine the given sequence feature to determine if it should actually be + * turned into sequence annotation or database cross references rather than a + * simple sequence feature. + * + * @param seq + * the sequence to annotate + * @param f + * the jalview sequence feature generated from the DAS feature + * @param map + * the sequence feature attributes + * @param source + * the source that emitted the feature + * @return true if feature was consumed as another kind of annotation. + */ + protected boolean parseSeqFeature(SequenceI seq, SequenceFeature f, + Map map, Das1Source source) + { + SequenceI mseq = seq; + while (seq.getDatasetSequence()!=null) + { + seq = seq.getDatasetSequence(); + } + if (f.getType() != null) + { + String type = f.getType(); + if (type.equalsIgnoreCase("protein_name")) + { + // parse name onto the alignment sequence or the dataset sequence. + if (seq.getDescription()==null || seq.getDescription().trim().length() == 0) + { + // could look at the note series to pick out the first long name, for the moment just use the whole description string + seq.setDescription(f.getDescription()); + } + if (mseq.getDescription()==null || mseq.getDescription().trim().length() == 0) + { + // could look at the note series to pick out the first long name, for the moment just use the whole description string + mseq.setDescription(f.getDescription()); + } + return true; + } + // check if source has biosapiens or other sequence ontology label + if (type.equalsIgnoreCase("DBXREF") || type.equalsIgnoreCase("DBREF")) + { + // try to parse the accession out + + DBRefEntry dbr = new DBRefEntry(); + dbr.setVersion(source.getNickname()); + StringTokenizer st = new StringTokenizer(f.getDescription(), ":"); + if (st.hasMoreTokens()) + { + dbr.setSource(st.nextToken()); + } + if (st.hasMoreTokens()) + { + dbr.setAccessionId(st.nextToken()); + } + seq.addDBRef(dbr); + + if (f.links != null && f.links.size() > 0) + { + // feature is also appended to enable links to be seen. + // TODO: consider extending dbrefs to have their own links ? + // TODO: new feature: extract dbref links from DAS servers and add the URL pattern to the list of DB name associated links in the user's preferences ? + // for the moment - just fix up the existing feature so it displays correctly. + // f.setType(dbr.getSource()); + //f.setDescription(); + f.setValue("linkonly", Boolean.TRUE); + //f.setDescription(""); + Vector newlinks = new Vector(); + Enumeration it = f.links.elements(); + while (it.hasMoreElements()) + { + String elm; + UrlLink urllink = new UrlLink(elm = (String)it.nextElement()); + if (urllink.isValid()) { + urllink.setLabel(f.getDescription()); + newlinks.addElement(urllink.toString()); + } else { + // couldn't parse the link properly. Keep it anyway - just in case. + debug("couldn't parse link string - "+elm); + newlinks.addElement(elm); + } + } + f.links = newlinks; + seq.addSequenceFeature(f); + } + return true; + } + } + return false; + } + + /** * creates a jalview sequence feature from a das feature document * * @param dasfeature @@ -651,7 +779,12 @@ public class DasSequenceFeatureFetcher } try { - score = Integer.parseInt(dasfeature.get("SCORE").toString()); + Object scr = dasfeature.get("SCORE"); + if (scr != null) + { + score = (float) Double.parseDouble(scr.toString()); + + } } catch (Exception ex) { } @@ -662,12 +795,14 @@ public class DasSequenceFeatureFetcher if (dasfeature.containsKey("LINK")) { // Do not put feature extent in link text for non-positional features - if (f.begin==0 && f.end==0) - { f.addLink(f.getType()+"|" - + dasfeature.get("LINK")); - } else { + if (f.begin == 0 && f.end == 0) + { + f.addLink(f.getType() + "|" + dasfeature.get("LINK")); + } + else + { f.addLink(f.getType() + " " + f.begin + "_" + f.end + "|" - + dasfeature.get("LINK")); + + dasfeature.get("LINK")); } } @@ -737,6 +872,7 @@ public class DasSequenceFeatureFetcher .size()]); } catch (Exception ex) { + System.err.println("Failed to contact DAS1 registry at "+registryURL); ex.printStackTrace(); return null; }