From 8ddacd61ecb5a5259b011df1194475f70e50f457 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 11 May 2017 16:20:29 +0100 Subject: [PATCH] JAL-2509 JAL-2507 allow whitespace in GS annotation lines (removed old code for processing GS column annotation into features) --- src/jalview/io/StockholmFile.java | 52 +++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index 8527f8b..e4d9f60 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -45,7 +45,6 @@ import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.StringTokenizer; import java.util.Vector; import com.stevesoft.pat.Regex; @@ -366,6 +365,11 @@ public class StockholmFile extends AlignFile // add alignment annotation for this feature String key = type2id(type); + + /* + * have we added annotation rows for this type ? + */ + boolean annotsAdded = false; if (key != null) { if (accAnnotations != null @@ -374,6 +378,7 @@ public class StockholmFile extends AlignFile Vector vv = (Vector) accAnnotations.get(key); for (int ii = 0; ii < vv.size(); ii++) { + annotsAdded = true; AlignmentAnnotation an = (AlignmentAnnotation) vv .elementAt(ii); seqO.addAlignmentAnnotation(an); @@ -386,6 +391,11 @@ public class StockholmFile extends AlignFile while (j.hasMoreElements()) { String desc = j.nextElement().toString(); + if ("annotations".equals(desc) && annotsAdded) + { + // don't add features if we already added an annotation row + continue; + } String ns = content.get(desc).toString(); char[] byChar = ns.toCharArray(); for (int k = 0; k < byChar.length; k++) @@ -572,22 +582,11 @@ public class StockholmFile extends AlignFile { String acc = s.stringMatched(1); String type = s.stringMatched(2); - String seq = new String(s.stringMatched(3)); - String description = null; - // Check for additional information about the current annotation - // We use a simple string tokenizer here for speed - StringTokenizer sep = new StringTokenizer(seq, " \t"); - description = sep.nextToken(); - if (sep.hasMoreTokens()) - { - seq = sep.nextToken(); - } - else - { - seq = description; - description = new String(); - } - // sequence id with from-to fields + String oseq = s.stringMatched(3); + /* + * copy of annotation field that may be processed into whitespace chunks + */ + String seq = new String(oseq); Hashtable ann; // Get an object with all the annotations for this sequence @@ -602,8 +601,12 @@ public class StockholmFile extends AlignFile ann = new Hashtable(); seqAnn.put(acc, ann); } + + // // start of block for appending annotation lines for wrapped + // stokchholm file // TODO test structure, call parseAnnotationRow with vector from // hashtable for specific sequence + Hashtable features; // Get an object with all the content for an annotation if (ann.containsKey("features")) @@ -631,15 +634,18 @@ public class StockholmFile extends AlignFile content = new Hashtable(); features.put(this.id2type(type), content); } - String ns = (String) content.get(description); + String ns = (String) content.get("annotation"); + if (ns == null) { ns = ""; } + // finally, append the annotation line ns += seq; - content.put(description, ns); + content.put("annotation", ns); + // // end of wrapped annotation block. + // // Now a new row is created with the current set of data - // if(type.equals("SS")){ Hashtable strucAnn; if (seqAnn.containsKey(acc)) { @@ -656,7 +662,8 @@ public class StockholmFile extends AlignFile { alan.visible = false; } - // annotations.addAll(newStruc); + // new annotation overwrites any existing annotation... + strucAnn.put(type, newStruc); seqAnn.put(acc, strucAnn); } @@ -831,12 +838,12 @@ public class StockholmFile extends AlignFile if (DETECT_BRACKETS.search(pos)) { ann.secondaryStructure = Rna.getRNASecStrucState(pos).charAt(0); + ann.displayCharacter = "" + pos.charAt(0); } else { ann.secondaryStructure = ResidueProperties.getDssp3state(pos) .charAt(0); - } if (ann.secondaryStructure == pos.charAt(0)) { @@ -846,6 +853,7 @@ public class StockholmFile extends AlignFile { ann.displayCharacter = " " + ann.displayCharacter; } + } } } -- 1.7.10.2