public void calculatePssm() { pssm = new double[fragments.get(0).fragLength][25]; char c = 'a'; for (ProteinFragment f : fragments) { for (int i = 0; i < f.getSequence().length(); i++) { c = f.getSequence().charAt(i); pssm[i][c - 65] += (1.0 / fragments.size()); } } }
/** * Compares another cluster to this one by comparing their centroid coordinates. NOT an override * of the equals(Object o) function. * * @param f the fragment cluster to compare with * @return true if the coordinates are within an epsilon of each other; false if not */ public boolean equals(FragmentCluster f) { if (f.getCentroid().getFragmentLength() != centroid.getFragmentLength()) return false; for (int i = 0; i < centroid.getFragmentLength(); i++) { for (int j = 0; j < 3; j++) { if (!isInEpsilon(f.getCentroid().getAllResidues()[i][j], centroid.getAllResidues()[i][j])) return false; } } return true; }
/** * returns a string representation of the fragment cluster in pdb format. Each fragment in the * cluster is wrapped as a pdb model. */ @Override public String toString() { int i = 0; StringBuilder result = new StringBuilder(); try { for (ProteinFragment f : fragments) { result.append("REMARK 500 " + f.getSequence() + "\n"); result.append("MODEL " + ++i + "\n"); result.append(f.toString()); result.append("ENDMDL" + "\n"); } return result.toString(); } catch (Exception e) { e.printStackTrace(); } return "problem printing"; // the try-catch block owes its existence to InvocationException calls // from phantom functions. We still don't know what was wrong there, but // apparently we fixed it. }
/** this function calculates the centroid of a cluster. */ public void calculateCentroid() { int clusterSize = fragments.size(); int fragLength = fragments.getFirst().fragLength; double[][] newCentroid = new double[fragLength][3]; ProteinFragment curFragment; double[] curResidue = new double[3]; for (int j = 0; j < clusterSize; j++) { curFragment = fragments.get(j); for (int i = 0; i < fragLength; i++) { curResidue = curFragment.getResidue(i); newCentroid[i][0] += curResidue[0]; newCentroid[i][1] += curResidue[1]; newCentroid[i][2] += curResidue[2]; } } for (int i = 0; i < newCentroid.length; i++) { newCentroid[i][0] /= clusterSize * 1.; newCentroid[i][1] /= clusterSize * 1.; newCentroid[i][2] /= clusterSize * 1.; } if (centroid != null) centroid.setCoordinates(newCentroid); else centroid = new ProteinFragment(name, newCentroid, fragLength); }