From: jprocter Date: Fri, 27 May 2005 11:47:10 +0000 (+0000) Subject: Added nicer header formatting for MSFfile output. X-Git-Tag: Release_2_0~160 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f960a9572b838aa32b8618324a12e9e4767f98cf;p=jalview.git Added nicer header formatting for MSFfile output. --- diff --git a/src/jalview/io/MSFfile.java b/src/jalview/io/MSFfile.java index 3c18432..63827a1 100755 --- a/src/jalview/io/MSFfile.java +++ b/src/jalview/io/MSFfile.java @@ -145,39 +145,58 @@ public class MSFfile extends AlignFile { } public static String print(SequenceI[] s) { - StringBuffer out = new StringBuffer("PileUp\n\n"); + return print(s, false); + } + public static String print(SequenceI[] s, boolean is_NA) { + StringBuffer out = new StringBuffer("!!"+(is_NA ? "NA":"AA")+"_MULTIPLE_ALIGNMENT 1.0\n\n"); // TODO: JBPNote : Jalview doesn't remember NA or AA yet. int max = 0; int maxid = 0; - int i = 0; String big = ""; + while (i < s.length && s[i] != null) { - big += s[i].getSequence(); + String sq; + big += (sq=s[i].getSequence()); + if (sq.length() > max) { + max = sq.length(); + } i++; } + Format maxLenpad = new Format("%"+(new String(""+max)).length()+"d"); + Format maxChkpad = new Format("%"+(new String("1"+max)).length()+"d"); i = 0; - int bigcheck = checkSum(big); - - out.append(" MSF: " + s[0].getSequence().length() + " Type: P Check: " + bigcheck + " ..\n\n\n"); - + long bigcheck = checkSum(big); + long maxNB=0; + out.append(" MSF: " + s[0].getSequence().length() + " Type: "+(is_NA?"N":"P")+" Check: " + bigcheck + " ..\n\n\n"); + String nameBlock[] = new String[s.length]; + String idBlock[] = new String[s.length]; while (i < s.length && s[i] != null) { String seq = s[i].getSequence(); String name = s[i].getName()+ "/" + s[i].getStart() + "-" + s[i].getEnd(); int check = checkSum(s[i].getSequence()); - out.append(" Name: " + name + " oo Len: " + s[i].getSequence().length() + " Check: " + check + " Weight: 1.00\n"); - if (seq.length() > max) { - max = seq.length(); - } + nameBlock[i]=new String(" Name: "+name+" "); + idBlock[i] = new String("Len: " + maxLenpad.form(s[i].getSequence().length()) + " Check:" + maxChkpad.form(check) + " Weight: 1.00\n"); + if (name.length() > maxid) { maxid = name.length(); } + if (nameBlock[i].length()>maxNB) { + maxNB=nameBlock[i].length(); + } + i++; } - if (maxid < 10) { maxid = 10; } + if (maxNB<15) { + maxNB=15; + } + Format nbFormat = new Format("%-"+maxNB+"s"); + for (i=0;i