X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fvamsas%2FSequencefeature.java;h=0525cf91fbac7e85236d9a0d6ead0fa2cd5331ed;hb=cb105dfc09cebd040a202758a3756fdf6c5fa3b6;hp=1348227a20e9c6b491fd74008dc43667d8f3e8e4;hpb=2de8acfae59aced665e4c37ad0f7dcc2ed68818e;p=jalview.git diff --git a/src/jalview/io/vamsas/Sequencefeature.java b/src/jalview/io/vamsas/Sequencefeature.java index 1348227..0525cf9 100644 --- a/src/jalview/io/vamsas/Sequencefeature.java +++ b/src/jalview/io/vamsas/Sequencefeature.java @@ -1,20 +1,19 @@ /* - * 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 + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) + * Copyright (C) 2010 J Procter, AM Waterhouse, 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This file is part of Jalview. * - * This program 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. + * 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. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * 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; @@ -64,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(); } @@ -90,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; @@ -107,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() @@ -137,6 +141,7 @@ public class Sequencefeature extends Rangetype } } + public void updateFromDoc() { DataSetAnnotations dsa = (DataSetAnnotations) vobj; @@ -146,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(); + } } } @@ -167,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, @@ -197,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()); @@ -240,8 +250,7 @@ public class Sequencefeature extends Rangetype else if (vlu instanceof Integer) { valid = true; - nprop - .setType(uk.ac.vamsas.objects.utils.Properties.INTEGERTYPE); + nprop.setType(uk.ac.vamsas.objects.utils.Properties.INTEGERTYPE); } else if (vlu instanceof Float) { @@ -265,21 +274,23 @@ public class Sequencefeature extends Rangetype } return dsa; } + private SequenceFeature getJalviewSeqFeature(RangeAnnotation dseta) { int[] se = getBounds(dseta); - SequenceFeature sf = new jalview.datamodel.SequenceFeature(dseta - .getType(), dseta.getDescription(), dseta.getStatus(), se[0], - se[1], dseta.getGroup()); + SequenceFeature sf = new jalview.datamodel.SequenceFeature( + dseta.getType(), dseta.getDescription(), dseta.getStatus(), + se[0], se[1], dseta.getGroup()); if (dseta.getLinkCount() > 0) { 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()) @@ -288,8 +299,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()); } } } @@ -299,36 +312,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); }