X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FAlignmentUtils.java;h=6ab49b27575086a59ec507741236224830cdadcc;hb=982963f55ceecf1c0591656b79dba5ad3aba0b06;hp=0fdabc86d04e411f4001f4927feb3a09820aff3d;hpb=571d610157d2c8ae01464b20d6d9c1ea935705d6;p=jalview.git diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 0fdabc8..6ab49b2 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -184,10 +184,10 @@ public class AlignmentUtils // TODO use Character.toLowerCase to avoid creating String objects? char[] upstream = new String(ds .getSequence(s.getStart() - 1 - ustream_ds, s.getStart() - 1)) - .toLowerCase(Locale.ROOT).toCharArray(); + .toLowerCase(Locale.ROOT).toCharArray(); char[] downstream = new String( ds.getSequence(s_end - 1, s_end + dstream_ds)) - .toLowerCase(Locale.ROOT).toCharArray(); + .toLowerCase(Locale.ROOT).toCharArray(); char[] coreseq = s.getSequence(); char[] nseq = new char[offset + upstream.length + downstream.length + coreseq.length]; @@ -1471,19 +1471,20 @@ public class AlignmentUtils */ final Iterable matchedAlignmentAnnotations = al .findAnnotations(seq, dsann.getCalcId(), dsann.label); - boolean found=false; + boolean found = false; if (matchedAlignmentAnnotations != null) { - for (AlignmentAnnotation matched:matchedAlignmentAnnotations) + for (AlignmentAnnotation matched : matchedAlignmentAnnotations) { if (dsann.description.equals(matched.description)) { - found=true; + found = true; break; } } } - if (!found) { + if (!found) + { result.add(dsann); if (labelForCalcId != null) { @@ -1503,14 +1504,15 @@ public class AlignmentUtils /** * Adds annotations to the top of the alignment annotations, in the same order - * as their related sequences. If you already have an annotation and want to add it to a sequence in an alignment use {@code addReferenceAnnotationTo} + * as their related sequences. If you already have an annotation and want to + * add it to a sequence in an alignment use {@code addReferenceAnnotationTo} * * @param annotations * the annotations to add * @param alignment * the alignment to add them to * @param selectionGroup - * current selection group (or null if none) + * current selection group - may be null, if provided then any added annotation will be trimmed to just those columns in the selection group */ public static void addReferenceAnnotations( Map> annotations, @@ -1520,52 +1522,60 @@ public class AlignmentUtils { for (AlignmentAnnotation ann : annotations.get(seq)) { - addReferenceAnnotationTo(alignment, seq,ann,selectionGroup); + addReferenceAnnotationTo(alignment, seq, ann, selectionGroup); } } } + /** - * Make a copy of a reference annotation {@code ann} and add it to an alignment sequence {@code seq} in {@code alignment}, optionally limited to the extent of {@code selectionGroup} + * Make a copy of a reference annotation {@code ann} and add it to an + * alignment sequence {@code seq} in {@code alignment}, optionally limited to + * the extent of {@code selectionGroup} + * * @param alignment * @param seq * @param ann - * @param selectionGroup - may be null + * @param selectionGroup + * current selection group - may be null, if provided then any added annotation will be trimmed to just those columns in the selection group * @return annotation added to {@code seq and {@code alignment} */ - public static AlignmentAnnotation addReferenceAnnotationTo(final AlignmentI alignment, final SequenceI seq,final AlignmentAnnotation ann,final SequenceGroup selectionGroup) + public static AlignmentAnnotation addReferenceAnnotationTo( + final AlignmentI alignment, final SequenceI seq, + final AlignmentAnnotation ann, final SequenceGroup selectionGroup) { - AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann); - int startRes = 0; - int endRes = ann.annotations.length; - if (selectionGroup != null) - { - startRes = -1+Math.min(seq.getEnd(), Math.max(seq.getStart(),seq.findPosition(selectionGroup.getStartRes()))); - endRes = -1+Math.min(seq.getEnd(),seq.findPosition(selectionGroup.getEndRes())); - - } - copyAnn.restrict(startRes, endRes + 0); + AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann); + int startRes = 0; + int endRes = ann.annotations.length; + if (selectionGroup != null) + { + startRes = -1 + Math.min(seq.getEnd(), Math.max(seq.getStart(), + seq.findPosition(selectionGroup.getStartRes()))); + endRes = -1 + Math.min(seq.getEnd(), + seq.findPosition(selectionGroup.getEndRes())); - /* - * Add to the sequence (sets copyAnn.datasetSequence), unless the - * original annotation is already on the sequence. - */ - if (!seq.hasAnnotation(ann)) - { - ContactMatrixI cm = seq.getDatasetSequence() - .getContactMatrixFor(ann); - if (cm != null) - { - seq.addContactListFor(copyAnn, cm); - } - seq.addAlignmentAnnotation(copyAnn); - } - // adjust for gaps - copyAnn.adjustForAlignment(); - // add to the alignment and set visible - alignment.addAnnotation(copyAnn); - copyAnn.visible = true; - - return copyAnn; + } + copyAnn.restrict(startRes, endRes + 0); + + /* + * Add to the sequence (sets copyAnn.datasetSequence), unless the + * original annotation is already on the sequence. + */ + if (!seq.hasAnnotation(ann)) + { + ContactMatrixI cm = seq.getDatasetSequence().getContactMatrixFor(ann); + if (cm != null) + { + seq.addContactListFor(copyAnn, cm); + } + seq.addAlignmentAnnotation(copyAnn); + } + // adjust for gaps + copyAnn.adjustForAlignment(); + // add to the alignment and set visible + alignment.addAnnotation(copyAnn); + copyAnn.visible = true; + + return copyAnn; } /**