X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FStockholmFile.java;fp=src%2Fjalview%2Fio%2FStockholmFile.java;h=71e369eb6163e9bc31ecaa10336175c9d3e61f91;hb=e191ef5205d9700ee33955ff89e0b3a4597d17d1;hp=f5b517728c85ce77ad785c9030e7b7e475ed2046;hpb=1253fe4ed610223c3c3b4e4983ec542e818efdfe;p=jalview.git 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()