X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FStockholmFile.java;h=8527f8b388a520250b7e034ebb25c790b244acb3;hb=5edb9a0c935f7c153bbddedfe2ce36bb389dbb53;hp=27be358ec23e7fc901a0cd1b0753137f31906cab;hpb=37de9310bec3501cbc6381e0c3dcb282fcaad812;p=jalview.git diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index 27be358..8527f8b 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -78,8 +78,8 @@ public class StockholmFile extends AlignFile private static final Regex CLOSE_PAREN = new Regex("(>|\\])", ")"); - private static final Regex DETECT_BRACKETS = new Regex( - "(<|>|\\[|\\]|\\(|\\))"); + public static final Regex DETECT_BRACKETS = new Regex( + "(<|>|\\[|\\]|\\(|\\)|\\{|\\})"); StringBuffer out; // output buffer @@ -97,7 +97,8 @@ public class StockholmFile extends AlignFile this.al = al; } - public StockholmFile(String inFile, String type) throws IOException + public StockholmFile(String inFile, DataSourceType type) + throws IOException { super(inFile, type); } @@ -799,9 +800,9 @@ public class StockholmFile extends AlignFile { String convert1, convert2 = null; - convert1 = OPEN_PAREN.replaceAll(annots); - convert2 = CLOSE_PAREN.replaceAll(convert1); - annots = convert2; + // convert1 = OPEN_PAREN.replaceAll(annots); + // convert2 = CLOSE_PAREN.replaceAll(convert1); + // annots = convert2; String type = label; if (label.contains("_cons")) @@ -880,8 +881,13 @@ public class StockholmFile extends AlignFile return annot; } - public String print(SequenceI[] s) + @Override + public String print(SequenceI[] s, boolean jvSuffix) { + out = new StringBuffer(); + out.append("# STOCKHOLM 1.0"); + out.append(newline); + // find max length of id int max = 0; int maxid = 0; @@ -889,7 +895,7 @@ public class StockholmFile extends AlignFile Hashtable dataRef = null; while ((in < s.length) && (s[in] != null)) { - String tmp = printId(s[in]); + String tmp = printId(s[in], jvSuffix); if (s[in].getSequence().length > max) { max = s[in].getSequence().length; @@ -960,47 +966,44 @@ public class StockholmFile extends AlignFile // output annotations while (i < s.length && s[i] != null) { - if (s[i].getDatasetSequence() != null) + AlignmentAnnotation[] alAnot = s[i].getAnnotation(); + if (alAnot != null) { - SequenceI ds = s[i].getDatasetSequence(); - AlignmentAnnotation[] alAnot; Annotation[] ann; - Annotation annot; - alAnot = s[i].getAnnotation(); - String feature = ""; - if (alAnot != null) + for (int j = 0; j < alAnot.length; j++) { - for (int j = 0; j < alAnot.length; j++) + + String key = type2id(alAnot[j].label); + boolean isrna = alAnot[j].isValidStruc(); + + if (isrna) + { + // hardwire to secondary structure if there is RNA secondary + // structure on the annotation + key = "SS"; + } + if (key == null) { - if (ds.getSequenceFeatures() != null) - { - feature = ds.getSequenceFeatures()[0].type; - } - // ?bug - feature may still have previous loop value - String key = type2id(feature); - if (key == null) - { - continue; - } + continue; + } - // out.append("#=GR "); - out.append(new Format("%-" + maxid + "s").form("#=GR " - + printId(s[i]) + " " + key + " ")); - ann = alAnot[j].annotations; - boolean isrna = alAnot[j].isValidStruc(); - String seq = ""; - for (int k = 0; k < ann.length; k++) - { - seq += outputCharacter(key, k, isrna, ann, s[i]); - } - out.append(seq); - out.append(newline); + // out.append("#=GR "); + out.append(new Format("%-" + maxid + "s").form("#=GR " + + printId(s[i], jvSuffix) + " " + key + " ")); + ann = alAnot[j].annotations; + String seq = ""; + for (int k = 0; k < ann.length; k++) + { + seq += outputCharacter(key, k, isrna, ann, s[i]); } + out.append(seq); + out.append(newline); } } - out.append(new Format("%-" + maxid + "s").form(printId(s[i]) + " ")); + out.append(new Format("%-" + maxid + "s") + .form(printId(s[i], jvSuffix) + " ")); out.append(s[i].getSequenceAsString()); out.append(newline); i++; @@ -1053,6 +1056,10 @@ public class StockholmFile extends AlignFile out.append(newline); } } + + out.append("//"); + out.append(newline); + return out.toString(); } @@ -1077,8 +1084,8 @@ public class StockholmFile extends AlignFile { if (annot == null) { - // sensible gap character if one is available or make one up - return sequenceI == null ? '-' : sequenceI.getCharAt(k); + // sensible gap character + return ' '; } else { @@ -1105,13 +1112,12 @@ public class StockholmFile extends AlignFile return seq; } - @Override public String print() { out = new StringBuffer(); out.append("# STOCKHOLM 1.0"); out.append(newline); - print(getSeqsAsArray()); + print(getSeqsAsArray(), false); out.append("//"); out.append(newline);