// score matrix class for QUASAR format matrices // (class from ProgPrakt WS 05/06) import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Vector; /** * A scoring system including a substitution matrix and a secondary structure matrix */ public class ScoreMatrix { // primary private float[][] scores; /** * Return score for a pair of amino acids AND a pair of * * @param AA1 first amino acid * @param AA2 second amino acid * @param SEC1 first secondary structure char * @param SEC2 second secondary structure char * @return */ public float getScore(byte AA1, byte AA2) { // weight scores and return return scores[AA1][AA2] ; } // read & parse amino acid matrix file public ScoreMatrix (String file) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(file)); byte[] aaOrder=null; int numAAs; // parse, line-by-line String line; int curMatrixLine=0; while ((line = reader.readLine()) != null) { // find ROWINDEX (determine AA order in this mat) if (line.length() > 8 && line.toLowerCase().substring(0,8).equals("rowindex")) { String split[] = splitByWhitespaces(line); numAAs = split[1].length(); aaOrder = new byte[numAAs]; // create scoring array scores = new float[numAAs][numAAs]; // decode the AA order sequence for (int i=0; i 8 && line.toLowerCase().substring(0,6).equals("matrix")) { // splitup line String split[] = splitByWhitespaces(line); curMatrixLine++; for (int i=1; i<=curMatrixLine; i++) { // translate indices int trans1 = aaOrder[i-1]; int trans2 = aaOrder[curMatrixLine-1]; scores[trans1][trans2] = Float.parseFloat(split[i]); scores[trans2][trans1] = scores[trans1][trans2]; } } } reader.close(); } /** * Split up a string by whitespaces... the inefficient way * * @param input the input string * @return */ public static String[] splitByWhitespaces(String input) { // split up by whitespaces String[] splitUp = input.split(" "); // create container Vector vec = new Vector(); for (int i=0; i