From 213bb03dc91ef5af6aacbfc641d82420d0bdbb5a Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 6 Sep 2012 14:37:35 +0100 Subject: [PATCH] JAL-1167 method and simple tests for printing score matrices as tab or html formatted tables --- src/jalview/schemes/ScoreMatrix.java | 54 ++++++++++++++++++++++++++ test/jalview/schemes/ScoreMatrixPrinter.java | 29 ++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 test/jalview/schemes/ScoreMatrixPrinter.java diff --git a/src/jalview/schemes/ScoreMatrix.java b/src/jalview/schemes/ScoreMatrix.java index f5d30a9..895ee86 100644 --- a/src/jalview/schemes/ScoreMatrix.java +++ b/src/jalview/schemes/ScoreMatrix.java @@ -83,4 +83,58 @@ public class ScoreMatrix return pog; } + /** + * pretty print the matrix + */ + public String toString() + { + return outputMatrix(false); + } + public String outputMatrix(boolean html) + { + StringBuffer sb=new StringBuffer(); + int[] symbols=(type==0) ? ResidueProperties.aaIndex : ResidueProperties.nucleotideIndex; + int symMax = (type==0) ? ResidueProperties.maxProteinIndex :ResidueProperties.maxNucleotideIndex; + boolean header=true; + if (html) + { + sb.append(""); + } + for (char sym='A';sym<='Z';sym++) + { + if (symbols[sym]>=0 && symbols[sym]" : ""); + for (char sym2='A';sym2<='Z';sym2++) + { + if (symbols[sym2]>=0 && symbols[sym2] " : "\t")+sym2 +(html ? " ": "")); + } + } + header=false; + sb.append(html ? "\n" : "\n"); + } + if (html) + { + sb.append(""); + } + sb.append((html ? "" : "")); + for (char sym2='A';sym2<='Z';sym2++) + { + if (symbols[sym2]>=0 && symbols[sym2]" : "\t")+matrix[symbols[sym]][symbols[sym2]]+(html ? "" : "")); + } + } + sb.append(html ? "\n" : "\n"); + } + } + if (html) + { + sb.append("
" : "")+sym+(html ? "
"); + } + return sb.toString(); + } } diff --git a/test/jalview/schemes/ScoreMatrixPrinter.java b/test/jalview/schemes/ScoreMatrixPrinter.java new file mode 100644 index 0000000..099db3c --- /dev/null +++ b/test/jalview/schemes/ScoreMatrixPrinter.java @@ -0,0 +1,29 @@ +package jalview.schemes; + +import java.util.Map; + +import org.junit.Test; + + +public class ScoreMatrixPrinter +{ + @Test + public void printAllMatrices() + { + for (Map.Entry sm:((Map) ResidueProperties.scoreMatrices).entrySet()) + { + System.out.println("Matrix "+sm.getKey()); + System.out.println(sm.getValue().toString()); + } + } + @Test + public void printHTMLMatrices() + { + for (Map.Entry sm:((Map) ResidueProperties.scoreMatrices).entrySet()) + { + System.out.println("Matrix "+sm.getKey()); + System.out.println(sm.getValue().outputMatrix(true)); + } + } + +} -- 1.7.10.2