Skip to content

Commit 31dd4f1

Browse files
committed
Create utility method for StructureIdentifiers in MultipleAlignment
1 parent d8062da commit 31dd4f1

3 files changed

Lines changed: 67 additions & 15 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ public Block getBlock(int index){
171171
public List<Atom[]> getAtomArrays() {
172172
return parent.getAtomArrays();
173173
}
174+
175+
@Override
176+
public StructureIdentifier getStructureIdentifier(int index) {
177+
return parent.getStructureIdentifiers().get(index);
178+
}
174179

175180
@Override
176181
public int size() {
@@ -239,4 +244,5 @@ public MultipleAlignmentEnsemble getEnsemble() {
239244
public void setEnsemble(MultipleAlignmentEnsemble parent) {
240245
this.parent = parent;
241246
}
247+
242248
}

biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/util/MultipleAlignmentTools.java

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@
3030

3131
import javax.vecmath.Matrix4d;
3232

33+
import org.biojava.nbio.core.exceptions.CompoundNotFoundException;
34+
import org.biojava.nbio.core.sequence.AccessionID;
3335
import org.biojava.nbio.core.sequence.MultipleSequenceAlignment;
3436
import org.biojava.nbio.core.sequence.ProteinSequence;
3537
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
38+
import org.biojava.nbio.structure.AminoAcid;
3639
import org.biojava.nbio.structure.Atom;
3740
import org.biojava.nbio.structure.Calc;
41+
import org.biojava.nbio.structure.Group;
3842
import org.biojava.nbio.structure.StructureTools;
3943
import org.biojava.nbio.structure.align.multiple.Block;
4044
import org.biojava.nbio.structure.align.multiple.BlockSet;
@@ -671,7 +675,8 @@ public static List<Atom[]> transformAtoms(MultipleAlignment alignment) {
671675
for (int j = 0; j < blk.length(); j++) {
672676
Integer alignedPos = blk.getAlignRes().get(i).get(j);
673677
if (alignedPos != null) {
674-
blocksetAtoms[blockPos] = (Atom) curr[alignedPos].clone();
678+
blocksetAtoms[blockPos] = (Atom) curr[alignedPos]
679+
.clone();
675680
}
676681
blockPos++;
677682
}
@@ -762,25 +767,65 @@ public int compare(Block o1, Block o2) {
762767

763768
/**
764769
* 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.
766771
*
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
769776
*/
770-
@SuppressWarnings("unused")
771777
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+
776791
// 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);
781798
}
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){
783812

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;
785829
}
830+
786831
}

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/utils/SymmetryTools.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,4 +956,5 @@ public static void updateSymmetryTransformation(SymmetryAxes axes,
956956
imposer.superimpose(msa);
957957
}
958958
}
959+
959960
}

0 commit comments

Comments
 (0)