All pastes #249941 Raw Edit

Mine

public java v1 · immutable
#249941 ·published 2006-11-16 12:08 UTC
rendered paste body
// 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<numAAs; i++) 					aaOrder[i] = AAMapping.mapAAToNum((byte)split[1].charAt(i));			}			// find MATRIX line (scoring information)			if (line.length() > 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<String> vec = new Vector<String>();				for (int i=0; i<splitUp.length; i++) {			if (!splitUp[i].trim().equals("")) {				vec.add(splitUp[i]);			}		}				return (String[])vec.toArray(new String[0]);			}	}