From 5e843947fc32d34012e8033b6c0eb8e25b44dd6a Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 19 Dec 2008 15:36:08 +0000 Subject: [PATCH] simple transformation of feature types like dbref and dbxref into database references --- src/jalview/ws/DasSequenceFeatureFetcher.java | 123 +++++++++++++++++-------- 1 file changed, 86 insertions(+), 37 deletions(-) diff --git a/src/jalview/ws/DasSequenceFeatureFetcher.java b/src/jalview/ws/DasSequenceFeatureFetcher.java index 1038ed9..5f7f2ba 100644 --- a/src/jalview/ws/DasSequenceFeatureFetcher.java +++ b/src/jalview/ws/DasSequenceFeatureFetcher.java @@ -477,45 +477,48 @@ 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()); - 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 + { + 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) { - debug("mapping to " + v + ": " + vf[v].getBegin() + " - " - + vf[v].getEnd()); - seq.addSequenceFeature(vf[v]); + 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 +581,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 +616,42 @@ 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) + { + // check if source has biosapiens or other sequence ontology label + if (f.getType()!=null && (f.getType().equalsIgnoreCase("DBXREF") + || f.getType().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); + return true; + } + return false; + } + + /** * creates a jalview sequence feature from a das feature document * * @param dasfeature @@ -651,7 +694,11 @@ public class DasSequenceFeatureFetcher } try { - score = (float) Double.parseDouble(dasfeature.get("SCORE").toString()); + Object scr = dasfeature.get("SCORE"); + if (scr!=null) + {score = (float) Double.parseDouble(scr.toString()); + + } } catch (Exception ex) { } @@ -662,12 +709,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")); } } -- 1.7.10.2