From 4816a1eeeec4c5b9ff845a711b2e10d621aed6e8 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 9 May 2017 08:46:21 +0100 Subject: [PATCH] JAL-2505 use constructors to set (what will be) final fields in SequenceFeature --- src/MCview/PDBChain.java | 12 +++++++----- src/jalview/analysis/AlignmentUtils.java | 7 ++++--- src/jalview/datamodel/Mapping.java | 5 ++--- src/jalview/datamodel/SequenceFeature.java | 18 ++++++++++++++++++ src/jalview/ext/ensembl/EnsemblSeqProxy.java | 12 +++++++----- src/jalview/io/gff/Gff3Helper.java | 5 ++--- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/MCview/PDBChain.java b/src/MCview/PDBChain.java index ba93046..1f47014 100755 --- a/src/MCview/PDBChain.java +++ b/src/MCview/PDBChain.java @@ -207,11 +207,13 @@ public class PDBChain if (features[i].getFeatureGroup() != null && features[i].getFeatureGroup().equals(pdbid)) { - SequenceFeature tx = new SequenceFeature(features[i]); - tx.setBegin(1 + residues.elementAt(tx.getBegin() - offset).atoms - .elementAt(0).alignmentMapping); - tx.setEnd(1 + residues.elementAt(tx.getEnd() - offset).atoms - .elementAt(0).alignmentMapping); + int newBegin = 1 + residues.elementAt(features[i].getBegin() + - offset).atoms + .elementAt(0).alignmentMapping; + int newEnd = 1 + residues.elementAt(features[i].getEnd() - offset).atoms + .elementAt(0).alignmentMapping; + SequenceFeature tx = new SequenceFeature(features[i], newBegin, + newEnd, features[i].getFeatureGroup()); tx.setStatus(status + ((tx.getStatus() == null || tx.getStatus().length() == 0) ? "" : ":" + tx.getStatus())); diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 232cb5d..955de28 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -2133,9 +2133,10 @@ public class AlignmentUtils } if (mappedTo != null) { - SequenceFeature copy = new SequenceFeature(sf); - copy.setBegin(Math.min(mappedTo[0], mappedTo[1])); - copy.setEnd(Math.max(mappedTo[0], mappedTo[1])); + int newBegin = Math.min(mappedTo[0], mappedTo[1]); + int newEnd = Math.max(mappedTo[0], mappedTo[1]); + SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd, + sf.getFeatureGroup()); copyTo.addSequenceFeature(copy); count++; } diff --git a/src/jalview/datamodel/Mapping.java b/src/jalview/datamodel/Mapping.java index 1c196be..4dea30c 100644 --- a/src/jalview/datamodel/Mapping.java +++ b/src/jalview/datamodel/Mapping.java @@ -530,9 +530,8 @@ public class Mapping SequenceFeature[] vf = new SequenceFeature[frange.length / 2]; for (int i = 0, v = 0; i < frange.length; i += 2, v++) { - vf[v] = new SequenceFeature(f); - vf[v].setBegin(frange[i]); - vf[v].setEnd(frange[i + 1]); + vf[v] = new SequenceFeature(f, frange[i], frange[i + 1], + f.getFeatureGroup()); if (frange.length > 2) { vf[v].setDescription(f.getDescription() + "\nPart " + (v + 1)); diff --git a/src/jalview/datamodel/SequenceFeature.java b/src/jalview/datamodel/SequenceFeature.java index 8eacb68..719cf52 100755 --- a/src/jalview/datamodel/SequenceFeature.java +++ b/src/jalview/datamodel/SequenceFeature.java @@ -178,6 +178,24 @@ public class SequenceFeature implements FeatureLocationI } /** + * A copy constructor that allows the begin and end positions and group to be + * modified + * + * @param sf + * @param newBegin + * @param newEnd + * @param newGroup + */ + public SequenceFeature(SequenceFeature sf, int newBegin, int newEnd, + String newGroup) + { + this(sf); + begin = newBegin; + end = newEnd; + featureGroup = newGroup; + } + + /** * Two features are considered equal if they have the same type, group, * description, start, end, phase, strand, and (if present) 'Name', ID' and * 'Parent' attributes. diff --git a/src/jalview/ext/ensembl/EnsemblSeqProxy.java b/src/jalview/ext/ensembl/EnsemblSeqProxy.java index 233707b..2d0e3fe 100644 --- a/src/jalview/ext/ensembl/EnsemblSeqProxy.java +++ b/src/jalview/ext/ensembl/EnsemblSeqProxy.java @@ -658,13 +658,15 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient if (mappedRange != null) { - SequenceFeature copy = new SequenceFeature(sf); - copy.setBegin(Math.min(mappedRange[0], mappedRange[1])); - copy.setEnd(Math.max(mappedRange[0], mappedRange[1])); - if (".".equals(copy.getFeatureGroup())) + String group = sf.getFeatureGroup(); + if (".".equals(group)) { - copy.setFeatureGroup(getDbSource()); + group = getDbSource(); } + int newBegin = Math.min(mappedRange[0], mappedRange[1]); + int newEnd = Math.max(mappedRange[0], mappedRange[1]); + SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd, + group); targetSequence.addSequenceFeature(copy); /* diff --git a/src/jalview/io/gff/Gff3Helper.java b/src/jalview/io/gff/Gff3Helper.java index 82e5313..0273f9b 100644 --- a/src/jalview/io/gff/Gff3Helper.java +++ b/src/jalview/io/gff/Gff3Helper.java @@ -310,10 +310,9 @@ public class Gff3Helper extends GffHelperBase * give the mapped sequence a copy of the sequence feature, with * start/end range adjusted */ - SequenceFeature sf2 = new SequenceFeature(sf); - sf2.setBegin(1); int sequenceFeatureLength = 1 + sf.getEnd() - sf.getBegin(); - sf2.setEnd(sequenceFeatureLength); + SequenceFeature sf2 = new SequenceFeature(sf, 1, + sequenceFeatureLength, sf.getFeatureGroup()); mappedSequence.addSequenceFeature(sf2); /* -- 1.7.10.2