From 70426041e78c134bb4052983ac6897933ae5f702 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 6 Dec 2005 11:51:36 +0000 Subject: [PATCH] after merge --- src/jalview/analysis/AlignSeq.java | 72 ++++++++++++++++----------------- src/jalview/analysis/NJTree.java | 43 ++++---------------- src/jalview/analysis/SeqsetUtils.java | 15 ++++--- 3 files changed, 51 insertions(+), 79 deletions(-) diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index 60ad85c..2fd1773 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -69,8 +69,8 @@ public class AlignSeq int maxj; int[] aseq1; int[] aseq2; - String astr1 = ""; - String astr2 = ""; + public String astr1 = ""; + public String astr2 = ""; /** DOCUMENT ME!! */ public int seq1start; @@ -94,7 +94,7 @@ public class AlignSeq int[][] lookup = ResidueProperties.getBLOSUM62(); String[] intToStr = pep; int defInt = 23; - String output = ""; + StringBuffer output = new StringBuffer(); String type; Runtime rt; @@ -169,7 +169,7 @@ public class AlignSeq */ public String getOutput() { - return output; + return output.toString(); } /** @@ -263,7 +263,7 @@ public class AlignSeq } else { - output = output + ("Wrong type = dna or pep only"); + output.append("Wrong type = dna or pep only"); System.exit(0); } @@ -406,7 +406,7 @@ public class AlignSeq /** * DOCUMENT ME! */ - public void printAlignment() + public void printAlignment(java.io.PrintStream os) { // Find the biggest id length for formatting purposes int maxid = s1.getName().length(); @@ -420,39 +420,33 @@ public class AlignSeq int nochunks = ((aseq1.length - count) / len) + 1; pid = 0; - output = output + ("Score = " + score[maxi][maxj] + "\n"); - output = output + - ("Length of alignment = " + (aseq1.length - count) + "\n"); - output = output + ("Sequence "); - output = output + (new Format("%" + maxid + "s").form(s1.getName())); - output = output + - (" : " + seq1start + " - " + seq1end + " (Sequence length = " + + output.append("Score = " + score[maxi][maxj] + "\n"); + output.append("Length of alignment = " + (aseq1.length - count) + "\n"); + output.append("Sequence "); + output.append(new Format("%" + maxid + "s").form(s1.getName())); + output.append(" : " + seq1start + " - " + seq1end + " (Sequence length = " + s1str.length() + ")\n"); - output = output + ("Sequence "); - output = output + (new Format("%" + maxid + "s").form(s2.getName())); - output = output + - (" : " + seq2start + " - " + seq2end + " (Sequence length = " + + output .append("Sequence "); + output.append(new Format("%" + maxid + "s").form(s2.getName())); + output .append(" : " + seq2start + " - " + seq2end + " (Sequence length = " + s2str.length() + ")\n\n"); for (int j = 0; j < nochunks; j++) { // Print the first aligned sequence - output = output + - (new Format("%" + (maxid) + "s").form(s1.getName()) + " "); + output.append(new Format("%" + (maxid) + "s").form(s1.getName()) + " "); for (int i = 0; i < len; i++) { if ((count + i + (j * len)) < aseq1.length) { - output = output + - (new Format("%s").form(intToStr[aseq1[count + i + + output.append(new Format("%s").form(intToStr[aseq1[count + i + (j * len)]])); } } - output = output + ("\n"); - output = output + - (new Format("%" + (maxid) + "s").form(" ") + " "); + output.append("\n"); + output.append(new Format("%" + (maxid) + "s").form(" ") + " "); // Print out the matching chars for (int i = 0; i < len; i++) @@ -464,7 +458,7 @@ public class AlignSeq !intToStr[aseq1[count + i + (j * len)]].equals("-")) { pid++; - output = output + ("|"); + output.append("|"); } else if (type.equals("pep")) { @@ -472,40 +466,42 @@ public class AlignSeq intToStr[aseq1[count + i + (j * len)]], intToStr[aseq2[count + i + (j * len)]]) > 0) { - output = output + ("."); + output.append("."); } else { - output = output + (" "); + output.append(" "); } } else { - output = output + (" "); + output.append(" "); } } } // Now print the second aligned sequence - output = output + ("\n"); - output = output + - (new Format("%" + (maxid) + "s").form(s2.getName()) + " "); + output = output.append("\n"); + output = output.append(new Format("%" + (maxid) + "s").form(s2.getName()) + " "); for (int i = 0; i < len; i++) { if ((count + i + (j * len)) < aseq1.length) { - output = output + - (new Format("%s").form(intToStr[aseq2[count + i + + output .append(new Format("%s").form(intToStr[aseq2[count + i + (j * len)]])); } } - output = output + ("\n\n"); + output = output .append("\n\n"); } pid = pid / (float) (aseq1.length - count) * 100; - output = output + (new Format("Percentage ID = %2.2f\n\n").form(pid)); + output = output.append(new Format("Percentage ID = %2.2f\n\n").form(pid)); + + try{ + os.println(output.toString()); + }catch(Exception ex){} } /** @@ -659,14 +655,14 @@ public class AlignSeq public static String extractGaps(String gapChar, String seq) { StringTokenizer str = new StringTokenizer(seq, gapChar); - String newString = ""; + StringBuffer newString = new StringBuffer(); while (str.hasMoreTokens()) { - newString = newString + str.nextToken(); + newString.append( str.nextToken() ); } - return newString; + return newString.toString(); } /** diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java index 99592f2..0683265 100755 --- a/src/jalview/analysis/NJTree.java +++ b/src/jalview/analysis/NJTree.java @@ -18,13 +18,16 @@ */ package jalview.analysis; -import java.util.*; - import jalview.datamodel.*; -import jalview.io.*; -import jalview.schemes.*; + +import jalview.io.NewickFile; + +import jalview.schemes.ResidueProperties; + import jalview.util.*; +import java.util.*; + /** * DOCUMENT ME! @@ -57,10 +60,6 @@ public class NJTree Object leaves = null; int start; int end; - boolean hasDistances = true; // normal case for jalview trees - boolean hasBootstrap = false; // normal case for jalview trees - - private boolean hasRootDistance = true; /** * Creates a new NJTree object. @@ -82,11 +81,6 @@ public class NJTree public NJTree(SequenceI[] seqs, NewickFile treefile) { top = treefile.getTree(); - - hasDistances = treefile.HasDistances(); - hasBootstrap = treefile.HasBootstrap(); - hasRootDistance = treefile.HasRootDistance(); - maxheight = findHeight(top); SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs); @@ -664,7 +658,7 @@ public class NJTree AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep"); as.calcScoreMatrix(); as.traceAlignment(); - as.printAlignment(); + as.printAlignment(System.out); distance[i][j] = (float) as.maxscore; if (max < distance[i][j]) @@ -1140,27 +1134,6 @@ public class NJTree { return top; } - /** - * - * @return true if tree has real distances - */ - public boolean isHasDistances() { - return hasDistances; - } - - /** - * - * @return true if tree has real bootstrap values - */ - public boolean isHasBootstrap() { - return hasBootstrap; - } - - public boolean isHasRootDistance() - { - return hasRootDistance; - } - } diff --git a/src/jalview/analysis/SeqsetUtils.java b/src/jalview/analysis/SeqsetUtils.java index bd0f45c..564e3f1 100755 --- a/src/jalview/analysis/SeqsetUtils.java +++ b/src/jalview/analysis/SeqsetUtils.java @@ -49,10 +49,10 @@ public class SeqsetUtils sqinfo.put("Name", seq.getName()); sqinfo.put("Start", new Integer(seq.getStart())); sqinfo.put("End", new Integer(seq.getEnd())); - sqinfo.put("SeqFeatures", seq.getSequenceFeatures()); + sqinfo.put("SeqFeatures", (seq.getSequenceFeatures() !=null) ? seq.getSequenceFeatures() : new Vector()); sqinfo.put("PdbId", - (seq.getPDBId() != null) ? seq.getPDBId() : new String("")); - + (seq.getPDBId() != null) ? seq.getPDBId() : new Vector()); + sqinfo.put("datasetSequence", (seq.getDatasetSequence() !=null) ? seq.getDatasetSequence() : new Sequence("THISISAPLACEHOLDER","")); return sqinfo; } @@ -71,8 +71,8 @@ public class SeqsetUtils Integer end = (Integer) sqinfo.get("End"); java.util.Vector sfeatures = (java.util.Vector) sqinfo.get( "SeqFeatures"); - String pdbid = (String) sqinfo.get("PdbId"); - + Vector pdbid = (Vector) sqinfo.get("PdbId"); + Sequence seqds = (Sequence) sqinfo.get("datasetSequence"); if (oldname == null) { namePresent = false; @@ -93,10 +93,13 @@ public class SeqsetUtils sq.setEnd(end.intValue()); } - if (sfeatures != null) + if ((sfeatures != null) && (sfeatures.size()>0)) { sq.setSequenceFeatures(sfeatures); } + if ((seqds!=null) && !(seqds.getName().equals("THISISAPLACEHOLDER") && seqds.getLength()==0)) { + sq.setDatasetSequence(seqds); + } return namePresent; } -- 1.7.10.2