X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fvamsas%2FSequencefeature.java;h=360e7040ca95998709b13f1c8c1cab546c63374f;hb=6486a5333807ca300db4a28a6bf9899f5dddf5a6;hp=0ddfc6ff92dcb2509fcb9186c5db518a59a5b10a;hpb=12e7f97678ce85b0238f987d5f4eaf18512a0b94;p=jalview.git diff --git a/src/jalview/io/vamsas/Sequencefeature.java b/src/jalview/io/vamsas/Sequencefeature.java index 0ddfc6f..360e704 100644 --- a/src/jalview/io/vamsas/Sequencefeature.java +++ b/src/jalview/io/vamsas/Sequencefeature.java @@ -1,5 +1,19 @@ -/** +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ package jalview.io.vamsas; @@ -49,7 +63,8 @@ public class Sequencefeature extends Rangetype public Sequencefeature(VamsasAppDatastore vamsasAppDatastore, DataSetAnnotations dseta, SequenceI dsSeq) { - super(vamsasAppDatastore, dseta, jalview.datamodel.SequenceFeature.class); + super(vamsasAppDatastore, dseta, + jalview.datamodel.SequenceFeature.class); this.dsSeq = dsSeq; doJvUpdate(); } @@ -75,9 +90,12 @@ public class Sequencefeature extends Rangetype public void addFromDocument() { DataSetAnnotations dsa = (DataSetAnnotations) vobj; - if (dsa.getSeqRefCount()!=1) + if (dsa.getSeqRefCount() != 1) { - Cache.log.warn("Not binding "+dsa.getVorbaId()+" to Sequence Feature - has multiple dataset sequence references."); + Cache.log + .warn("Not binding " + + dsa.getVorbaId() + + " to Sequence Feature - has multiple dataset sequence references."); return; } jalview.datamodel.SequenceFeature sf = (jalview.datamodel.SequenceFeature) jvobj; @@ -92,9 +110,10 @@ public class Sequencefeature extends Rangetype DataSetAnnotations dsa = (DataSetAnnotations) vobj; jalview.datamodel.SequenceFeature feature = (jalview.datamodel.SequenceFeature) jvobj; jalview.datamodel.SequenceFeature sf = getJalviewSeqFeature(dsa); - replaceJvObjMapping(feature, sf); // switch binding of dsa from old feature to newly created feature + replaceJvObjMapping(feature, sf); // switch binding of dsa from old feature + // to newly created feature dsSeq.addSequenceFeature(sf); // add new imported feature - addToDocument(); // and create a new feature in the document + addToDocument(); // and create a new feature in the document } public void updateToDoc() @@ -122,6 +141,7 @@ public class Sequencefeature extends Rangetype } } + public void updateFromDoc() { DataSetAnnotations dsa = (DataSetAnnotations) vobj; @@ -131,19 +151,26 @@ public class Sequencefeature extends Rangetype // conflicting update from document - we cannot map this feature anymore. replaceJvObjMapping(feature, null); Cache.log - .warn("annotation ("+dsa.getVorbaId()+" bound to jalview feature cannot be mapped. Removing binding, deleting feature, and deleting feature."); - // - consider deleting the feature ? + .warn("annotation (" + + dsa.getVorbaId() + + " bound to jalview feature cannot be mapped. Removing binding, deleting feature, and deleting feature."); + // - consider deleting the feature ? dsSeq.deleteFeature(feature); // doSync(); } else { - // Sync the features to Jalview - easiest to delete and add the feature again + // Sync the features to Jalview - easiest to delete and add the feature + // again jalview.datamodel.SequenceFeature newsf = getJalviewSeqFeature(dsa); dsSeq.deleteFeature(feature); replaceJvObjMapping(feature, newsf); dsSeq.addSequenceFeature(newsf); - feature.otherDetails.clear(); + if (feature.otherDetails != null) + { + // TODO later: leave this to finalise method ? + feature.otherDetails.clear(); + } } } @@ -152,10 +179,9 @@ public class Sequencefeature extends Rangetype * TODO: refactor to a method in jalview.io.vamsas.RangeAnnotation class * * @param dsa - * (typically DataSetAnnotations or - * AlignmentSequenceAnnotation) + * (typically DataSetAnnotations or AlignmentSequenceAnnotation) * @param feature - * (the feature to be mapped from) + * (the feature to be mapped from) * @return */ private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa, @@ -182,15 +208,14 @@ public class Sequencefeature extends Rangetype { String link = (String) feature.links.elementAt(i); UrlLink ulink = new UrlLink(link); - /* - * int sep = link.indexOf('|'); if (sep > -1) { Link vLink = new Link(); - * if (sep > 0) { vLink.setContent(link.substring(0, sep - 1)); } else { - * vLink.setContent(""); } vLink.setHref(link.substring(sep + 1)); // - * TODO: validate href. dsa.addLink(vLink); } - */ - Link vLink = new Link(); - vLink.setContent(ulink.getLabel()); - vLink.setHref(ulink.getUrl_prefix()); + if (ulink.isValid()) + { + // We only add static links to the document. + Link vLink = new Link(); + vLink.setContent(ulink.getLabel()); + vLink.setHref(ulink.getTarget()); + dsa.addLink(vLink); + } } } dsa.setGroup(feature.getFeatureGroup()); @@ -250,6 +275,7 @@ public class Sequencefeature extends Rangetype } return dsa; } + private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta) { int[] se = getBounds(dseta); @@ -261,10 +287,11 @@ public class Sequencefeature extends Rangetype Link[] links = dseta.getLink(); for (int i = 0; i < links.length; i++) { + // TODO: use URLLink parsing/validation here. sf.addLink(links[i].getContent() + "|" + links[i].getHref()); } } - if (dseta.getScoreCount()>0) + if (dseta.getScoreCount() > 0) { Enumeration scr = dseta.enumerateScore(); while (scr.hasMoreElements()) @@ -273,8 +300,10 @@ public class Sequencefeature extends Rangetype if (score.getName().equals(sf.getType())) { sf.setScore(score.getContent()); - } else { - sf.setValue(score.getName(), ""+score.getContent()); + } + else + { + sf.setValue(score.getName(), "" + score.getContent()); } } } @@ -284,36 +313,41 @@ public class Sequencefeature extends Rangetype { Property p = (Property) props.nextElement(); Object val = null; - if (Properties.isValid(p)) + if (Properties.isValid(p)) { if (Properties.isString(p)) { - val = p.getContent(); + val = p.getContent(); } if (Properties.isBoolean(p)) { - try { + try + { val = new Boolean(p.getContent()); - } catch (Exception e) {} + } catch (Exception e) + { + } } if (Properties.isFloat(p)) { - try { - val = new Float(p.getContent()); - - } catch (Exception e) - { - } + try + { + val = new Float(p.getContent()); + + } catch (Exception e) + { } - if(Properties.isInteger(p)) + } + if (Properties.isInteger(p)) { - try { - val = new Integer(p.getContent()); + try + { + val = new Integer(p.getContent()); } catch (Exception e) { - } + } } - if (val!=null) + if (val != null) { sf.setValue(p.getName(), val); }