|
30 | 30 |
|
31 | 31 | import javax.vecmath.Matrix4d; |
32 | 32 |
|
| 33 | +import org.biojava.nbio.core.exceptions.CompoundNotFoundException; |
| 34 | +import org.biojava.nbio.core.sequence.AccessionID; |
33 | 35 | import org.biojava.nbio.core.sequence.MultipleSequenceAlignment; |
34 | 36 | import org.biojava.nbio.core.sequence.ProteinSequence; |
35 | 37 | import org.biojava.nbio.core.sequence.compound.AminoAcidCompound; |
| 38 | +import org.biojava.nbio.structure.AminoAcid; |
36 | 39 | import org.biojava.nbio.structure.Atom; |
37 | 40 | import org.biojava.nbio.structure.Calc; |
| 41 | +import org.biojava.nbio.structure.Group; |
38 | 42 | import org.biojava.nbio.structure.StructureTools; |
39 | 43 | import org.biojava.nbio.structure.align.multiple.Block; |
40 | 44 | import org.biojava.nbio.structure.align.multiple.BlockSet; |
@@ -671,7 +675,8 @@ public static List<Atom[]> transformAtoms(MultipleAlignment alignment) { |
671 | 675 | for (int j = 0; j < blk.length(); j++) { |
672 | 676 | Integer alignedPos = blk.getAlignRes().get(i).get(j); |
673 | 677 | if (alignedPos != null) { |
674 | | - blocksetAtoms[blockPos] = (Atom) curr[alignedPos].clone(); |
| 678 | + blocksetAtoms[blockPos] = (Atom) curr[alignedPos] |
| 679 | + .clone(); |
675 | 680 | } |
676 | 681 | blockPos++; |
677 | 682 | } |
@@ -762,25 +767,65 @@ public int compare(Block o1, Block o2) { |
762 | 767 |
|
763 | 768 | /** |
764 | 769 | * Convert a MultipleAlignment into a MultipleSequenceAlignment of AminoAcid |
765 | | - * residues. This method is only valid for protein alignments. |
| 770 | + * residues. This method is only valid for protein structure alignments. |
766 | 771 | * |
767 | | - * @param msta Multiple Structure Alignment |
768 | | - * @return MultipleSequenceAlignment |
| 772 | + * @param msta |
| 773 | + * Multiple Structure Alignment |
| 774 | + * @return MultipleSequenceAlignment of protein sequences |
| 775 | + * @throws CompoundNotFoundException |
769 | 776 | */ |
770 | | - @SuppressWarnings("unused") |
771 | 777 | public static MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound> toProteinMSA( |
772 | | - MultipleAlignment msta) { |
773 | | - |
774 | | - MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound> msa = new MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound>(); |
775 | | - |
| 778 | + MultipleAlignment msta) throws CompoundNotFoundException { |
| 779 | + |
| 780 | + // Check that the alignment is of protein structures |
| 781 | + Group g = msta.getAtomArrays().get(0)[0].getGroup(); |
| 782 | + if (!(g instanceof AminoAcid)) { |
| 783 | + throw new IllegalArgumentException( |
| 784 | + "Cannot convert to multiple sequence alignment: " |
| 785 | + + "the structures aligned are not proteins"); |
| 786 | + } |
| 787 | + |
| 788 | + MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound> msa = |
| 789 | + new MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound>(); |
| 790 | + |
776 | 791 | // Extract the sequences and add them to the MSA |
777 | | - List<String> sequences = getSequenceAlignment(msta); |
778 | | - for (String seq : sequences) { |
779 | | - // TODO convert String to ProteinSequence and add it to the MSA |
780 | | - // Additionally set the identifier |
| 792 | + List<String> seqs = getSequenceAlignment(msta); |
| 793 | + for (int i = 0; i < msta.size(); i++) { |
| 794 | + AccessionID id = new AccessionID(msta.getStructureIdentifier(i).toString()); |
| 795 | + ProteinSequence pseq = new ProteinSequence(seqs.get(i)); |
| 796 | + pseq.setAccession(id); |
| 797 | + msa.addAlignedSequence(pseq); |
781 | 798 | } |
782 | | - throw new NullPointerException("Method not implemented yet!"); |
| 799 | + return msa; |
| 800 | + } |
| 801 | + |
| 802 | + /** |
| 803 | + * Calculate the RMSD matrix of a MultipleAlignment, that is, entry (i,j) |
| 804 | + * of the matrix contains the RMSD between structures i and j. |
| 805 | + * |
| 806 | + * @param msa |
| 807 | + * Multiple Structure Alignment |
| 808 | + * @return Matrix of RMSD with size the number of structures |
| 809 | + * squared |
| 810 | + */ |
| 811 | + public static Matrix getRMSDMatrix(MultipleAlignment msa){ |
783 | 812 |
|
784 | | - //return msa; |
| 813 | + Matrix rmsdMat = new Matrix(msa.size(), msa.size()); |
| 814 | + List<Atom[]> superposed = transformAtoms(msa); |
| 815 | + |
| 816 | + for (int i = 0; i < msa.size(); i++) { |
| 817 | + for (int j = i; j < msa.size(); j++) { |
| 818 | + if (i == j) |
| 819 | + rmsdMat.set(i, j, 0.0); |
| 820 | + List<Atom[]> compared = new ArrayList<Atom[]>(); |
| 821 | + compared.add(superposed.get(i)); |
| 822 | + compared.add(superposed.get(j)); |
| 823 | + double rmsd = MultipleAlignmentScorer.getRMSD(compared); |
| 824 | + rmsdMat.set(i, j, rmsd); |
| 825 | + rmsdMat.set(j, i, rmsd); |
| 826 | + } |
| 827 | + } |
| 828 | + return rmsdMat; |
785 | 829 | } |
| 830 | + |
786 | 831 | } |
0 commit comments