From d2e495268df6f50286b972f1145f302ad181da00 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Mon, 14 Aug 2017 15:49:33 +0100 Subject: [PATCH] JAL-2629 remove gap padding, and now has option to remove annotations --- src/jalview/io/StockholmFile.java | 154 +++++++++++++++++++------------------ 1 file changed, 80 insertions(+), 74 deletions(-) diff --git a/src/jalview/io/StockholmFile.java b/src/jalview/io/StockholmFile.java index ead653f..8d340f2 100644 --- a/src/jalview/io/StockholmFile.java +++ b/src/jalview/io/StockholmFile.java @@ -916,6 +916,13 @@ public class StockholmFile extends AlignFile @Override public String print(SequenceI[] s, boolean jvSuffix) { + String string = print(s, jvSuffix, false); + return string; + } + + public String print(SequenceI[] s, boolean jvSuffix, + boolean removeAnnotations) + { out = new StringBuffer(); out.append("# STOCKHOLM 1.0"); out.append(newline); @@ -995,102 +1002,101 @@ public class StockholmFile extends AlignFile } } - // output annotations - while (i < s.length && s[i] != null) - { - AlignmentAnnotation[] alAnot = s[i].getAnnotation(); - if (alAnot != null) + + // output annotations + while (i < s.length && s[i] != null) { - Annotation[] ann; - for (int j = 0; j < alAnot.length; j++) + AlignmentAnnotation[] alAnot = s[i].getAnnotation(); + if (alAnot != null && !removeAnnotations) { + Annotation[] ann; + for (int j = 0; j < alAnot.length; j++) + { - String key = type2id(alAnot[j].label); - boolean isrna = alAnot[j].isValidStruc(); + 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 (isrna) + { + // hardwire to secondary structure if there is RNA secondary + // structure on the annotation + key = "SS"; + } + if (key == null) + { - continue; - } + continue; + } - // 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++) - { - char character = outputCharacter(key, k, isrna, ann, s[i]); - if (character == ' ') + // 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++) { - character = '.'; + seq += outputCharacter(key, k, isrna, ann, s[i]); } - seq += character; + out.append(seq); + out.append(newline); } - out.append(seq); - out.append(newline); } - } - out.append(new Format("%-" + maxid + "s") - .form(printId(s[i], jvSuffix) + " ")); - out.append(s[i].getSequenceAsString()); - out.append(newline); - i++; - } + out.append(new Format("%-" + maxid + "s") + .form(printId(s[i], jvSuffix) + " ")); + out.append(s[i].getSequenceAsString()); + out.append(newline); + i++; + } - // alignment annotation - AlignmentAnnotation aa; - if (al.getAlignmentAnnotation() != null) + if (!removeAnnotations) { - for (int ia = 0; ia < al.getAlignmentAnnotation().length; ia++) + // alignment annotation + AlignmentAnnotation aa; + if (al.getAlignmentAnnotation() != null) { - aa = al.getAlignmentAnnotation()[ia]; - if (aa.autoCalculated || !aa.visible || aa.sequenceRef != null) - { - continue; - } - String seq = ""; - String label; - String key = ""; - if (aa.label.equals("seq")) + for (int ia = 0; ia < al.getAlignmentAnnotation().length; ia++) { - label = "seq_cons"; - } - else - { - key = type2id(aa.label.toLowerCase()); - if (key == null) + aa = al.getAlignmentAnnotation()[ia]; + if (aa.autoCalculated || !aa.visible || aa.sequenceRef != null) { - label = aa.label; + continue; + } + String seq = ""; + String label; + String key = ""; + if (aa.label.equals("seq")) + { + label = "seq_cons"; } else { - label = key + "_cons"; + key = type2id(aa.label.toLowerCase()); + if (key == null) + { + label = aa.label; + } + else + { + label = key + "_cons"; + } } - } - if (label == null) - { - label = aa.label; - } - label = label.replace(" ", "_"); + if (label == null) + { + label = aa.label; + } + label = label.replace(" ", "_"); - out.append(new Format("%-" + maxid + "s").form("#=GC " + label - + " ")); - boolean isrna = aa.isValidStruc(); - for (int j = 0; j < aa.annotations.length; j++) - { - seq += outputCharacter(key, j, isrna, aa.annotations, null); + out.append(new Format("%-" + maxid + "s") + .form("#=GC " + label + " ")); + boolean isrna = aa.isValidStruc(); + for (int j = 0; j < aa.annotations.length; j++) + { + seq += outputCharacter(key, j, isrna, aa.annotations, null); + } + out.append(seq); + out.append(newline); } - out.append(seq); - out.append(newline); } } -- 1.7.10.2