From: bsoares Date: Mon, 30 Jul 2018 16:24:51 +0000 (+0100) Subject: Fixed bug ignoring "alpha" extended braces in RNA SS line in X-Git-Tag: Release_2_10_5~34^2~5 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e191ef5205d9700ee33955ff89e0b3a4597d17d1;p=jalview.git Fixed bug ignoring "alpha" extended braces in RNA SS line in StockholmFile.java (loading a stockholm file with alpha braces in the SS_cons line) --- diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 0098d76..f84b18d 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -294,6 +294,7 @@ public class AlignmentAnnotation char firstChar = 0; for (int i = 0; i < annotations.length; i++) { + // DEBUG System.out.println(i + ": " + annotations[i]); if (annotations[i] == null) { continue; @@ -301,12 +302,15 @@ public class AlignmentAnnotation if (annotations[i].secondaryStructure == 'H' || annotations[i].secondaryStructure == 'E') { + // DEBUG System.out.println( "/H|E/ '" + + // annotations[i].secondaryStructure + "'"); hasIcons |= true; } else // Check for RNA secondary structure { - // System.out.println(annotations[i].secondaryStructure); + // DEBUG System.out.println( "/else/ '" + + // annotations[i].secondaryStructure + "'"); // TODO: 2.8.2 should this ss symbol validation check be a function in // RNA/ResidueProperties ? if (annotations[i].secondaryStructure == '(' @@ -317,10 +321,10 @@ public class AlignmentAnnotation || annotations[i].secondaryStructure == 'B' || annotations[i].secondaryStructure == 'C' || annotations[i].secondaryStructure == 'D' - || annotations[i].secondaryStructure == 'E' + // || annotations[i].secondaryStructure == 'E' || annotations[i].secondaryStructure == 'F' || annotations[i].secondaryStructure == 'G' - || annotations[i].secondaryStructure == 'H' + // || annotations[i].secondaryStructure == 'H' || annotations[i].secondaryStructure == 'I' || annotations[i].secondaryStructure == 'J' || annotations[i].secondaryStructure == 'K' @@ -367,7 +371,7 @@ public class AlignmentAnnotation // && // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure firstChar != ' ' && firstChar != '$' && firstChar != 0xCE - && firstChar != '(' && firstChar != '[' && firstChar != '>' + && firstChar != '(' && firstChar != '[' && firstChar != '<' && firstChar != '{' && firstChar != 'A' && firstChar != 'B' && firstChar != 'C' && firstChar != 'D' && firstChar != 'E' && firstChar != 'F' && firstChar != 'G' && firstChar != 'H' diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index f5b5177..71e369e 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -83,6 +83,8 @@ public class StockholmFile extends AlignFile public static final Regex DETECT_BRACKETS = new Regex( "(<|>|\\[|\\]|\\(|\\)|\\{|\\})"); + public static final String RNASS_BRACKETS = "<>[]() {}AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; + StringBuffer out; // output buffer AlignmentI al; @@ -197,7 +199,7 @@ public class StockholmFile extends AlignFile String version; // String id; Hashtable seqAnn = new Hashtable(); // Sequence related annotations - LinkedHashMap seqs = new LinkedHashMap(); + LinkedHashMap seqs = new LinkedHashMap<>(); Regex p, r, rend, s, x; // Temporary line for processing RNA annotation // String RNAannot = ""; @@ -658,7 +660,7 @@ public class StockholmFile extends AlignFile strucAnn = new Hashtable(); } - Vector newStruc = new Vector(); + Vector newStruc = new Vector<>(); parseAnnotationRow(newStruc, type, ns); for (AlignmentAnnotation alan : newStruc) { @@ -710,7 +712,7 @@ public class StockholmFile extends AlignFile private void guessDatabaseFor(Sequence seqO, String dbr, String dbsource) { DBRefEntry dbrf = null; - List dbrs = new ArrayList(); + List dbrs = new ArrayList<>(); String seqdb = "Unknown", sdbac = "" + dbr; int st = -1, en = -1, p; if ((st = sdbac.indexOf("/")) > -1) @@ -814,6 +816,12 @@ public class StockholmFile extends AlignFile // convert1 = OPEN_PAREN.replaceAll(annots); // convert2 = CLOSE_PAREN.replaceAll(convert1); // annots = convert2; + + // DEBUG + System.out.println( + "*** parseAnnotationRow called with\n annotation='" + + annotation + "'\n label='" + label + + "'\n annots='" + annots + "'"); String type = label; if (label.contains("_cons")) @@ -824,9 +832,12 @@ public class StockholmFile extends AlignFile } boolean ss = false, posterior = false; type = id2type(type); + + boolean isrnass = false; if (type.equalsIgnoreCase("secondary structure")) { ss = true; + isrnass = DETECT_BRACKETS.search(annots); } if (type.equalsIgnoreCase("posterior probability")) { @@ -844,7 +855,7 @@ public class StockholmFile extends AlignFile { // if (" .-_".indexOf(pos) == -1) { - if (DETECT_BRACKETS.search(pos)) + if (isrnass && RNASS_BRACKETS.indexOf(pos) >= 0) { ann.secondaryStructure = Rna.getRNASecStrucState(pos).charAt(0); ann.displayCharacter = "" + pos.charAt(0); @@ -1008,7 +1019,9 @@ public class StockholmFile extends AlignFile String key = type2id(alAnot[j].label); boolean isrna = alAnot[j].isValidStruc(); - + // bs debug + System.out.println("SEQUENCE " + i + "/" + s.length + " ISRNA=" + + isrna + "."); if (isrna) { // hardwire to secondary structure if there is RNA secondary @@ -1030,6 +1043,9 @@ public class StockholmFile extends AlignFile { seq += outputCharacter(key, k, isrna, ann, s[i]); } + // bs debug + System.out.println("APPENDING SEQ: KEY=" + key + " ISRNA=" + isrna + + ".\n" + "SEQ=" + seq + "\n"); out.append(seq); out.append(newline); } @@ -1038,6 +1054,8 @@ public class StockholmFile extends AlignFile out.append(new Format("%-" + maxid + "s") .form(printId(s[i], jvSuffix) + " ")); out.append(s[i].getSequenceAsString()); + // bs debug + System.out.println("ALSO APPENDING " + s[i].getSequenceAsString()); out.append(newline); i++; } @@ -1085,6 +1103,12 @@ public class StockholmFile extends AlignFile { seq += outputCharacter(key, j, isrna, aa.annotations, null); } + + // bs debug + System.out.println( + "PRINTING SEQ: KEY=" + key + " ISRNA=" + isrna + ".\n" + + "SEQ=" + seq + "\n"); + out.append(seq); out.append(newline); } @@ -1117,18 +1141,30 @@ public class StockholmFile extends AlignFile : annot.displayCharacter; if (key != null && key.equals("SS")) { + char ssannotchar = ' '; + boolean charset = false; if (annot == null) { // sensible gap character - return ' '; + ssannotchar = ' '; + charset = true; } else { // valid secondary structure AND no alternative label (e.g. ' B') if (annot.secondaryStructure > ' ' && ch.length() < 2) { - return annot.secondaryStructure; + ssannotchar = annot.secondaryStructure; + charset = true; + } + } + if (charset) + { + if (ssannotchar == ' ' && isrna) + { + ssannotchar = '.'; } + return ssannotchar; } } @@ -1144,7 +1180,9 @@ public class StockholmFile extends AlignFile { seq = ch.charAt(1); } - return seq; + + return (seq == ' ' && key != null && key.equals("SS") && isrna) ? '.' + : seq; } public String print()