|
| 1 | +package demo; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.biojava.nbio.structure.Atom; |
| 9 | +import org.biojava.nbio.structure.StructureException; |
| 10 | +import org.biojava.nbio.structure.align.gui.MultipleAlignmentDisplay; |
| 11 | +import org.biojava.nbio.structure.align.multiple.Block; |
| 12 | +import org.biojava.nbio.structure.align.multiple.BlockImpl; |
| 13 | +import org.biojava.nbio.structure.align.multiple.BlockSet; |
| 14 | +import org.biojava.nbio.structure.align.multiple.BlockSetImpl; |
| 15 | +import org.biojava.nbio.structure.align.multiple.MultipleAlignment; |
| 16 | +import org.biojava.nbio.structure.align.multiple.MultipleAlignmentEnsemble; |
| 17 | +import org.biojava.nbio.structure.align.multiple.MultipleAlignmentEnsembleImpl; |
| 18 | +import org.biojava.nbio.structure.align.multiple.MultipleAlignmentImpl; |
| 19 | +import org.biojava.nbio.structure.align.multiple.MultipleAlignmentScorer; |
| 20 | +import org.biojava.nbio.structure.align.multiple.MultipleAlignmentWriter; |
| 21 | +import org.biojava.nbio.structure.align.multiple.MultipleSuperimposer; |
| 22 | +import org.biojava.nbio.structure.align.multiple.ReferenceSuperimposer; |
| 23 | +import org.biojava.nbio.structure.align.util.AtomCache; |
| 24 | + |
| 25 | +/** |
| 26 | + * Demo for visualizing the results of a Multiple Alignment, from a sample MultipleAlignment object. |
| 27 | + * |
| 28 | + * @author Aleix Lafita |
| 29 | + * |
| 30 | + */ |
| 31 | +public class DemoMultipleAlignmentJmol { |
| 32 | + |
| 33 | + public static void main(String[] args) throws IOException, StructureException { |
| 34 | + |
| 35 | + //Specify the structures to align |
| 36 | + //List<String> names = Arrays.asList("1tim.a", "1vzw", "1nsj", "3tha.a"); //TIM barrels |
| 37 | + List<String> names = Arrays.asList("1mbc", "1hlb", "1thb.a", "1ith.a"); //globins |
| 38 | + |
| 39 | + //Load the CA atoms of the structures |
| 40 | + AtomCache cache = new AtomCache(); |
| 41 | + List<Atom[]> atomArrays = new ArrayList<Atom[]>(); |
| 42 | + for (String name:names) atomArrays.add(cache.getAtoms(name)); |
| 43 | + |
| 44 | + //Here the multiple structural alignment algorithm comes in place to generate the alignment object |
| 45 | + MultipleAlignment fakeMultAln = fakeMultipleAlignment("globins", atomArrays); |
| 46 | + fakeMultAln.getEnsemble().setStructureNames(names); |
| 47 | + |
| 48 | + //Generate a pairwise alignment and convert it to a MultipleAlignment |
| 49 | + //FatCat fatcat = new FatCat(); |
| 50 | + //AFPChain afpChain = fatcat.alignRigid(atomArrays.get(0),atomArrays.get(1)); |
| 51 | + //MultipleAlignmentEnsemble ensemble = new MultipleAlignmentEnsembleImpl(afpChain, atomArrays.get(0),atomArrays.get(1)); |
| 52 | + //MultipleAlignment pairwise = ensemble.getMultipleAlignments().get(0); |
| 53 | + |
| 54 | + System.out.println(MultipleAlignmentWriter.toFASTA(fakeMultAln)); |
| 55 | + MultipleAlignmentDisplay.display(fakeMultAln); |
| 56 | + //StructureAlignmentDisplay.display(pairwise); |
| 57 | + //For comparison display the original AFP |
| 58 | + //StructureAlignmentDisplay.display(afpChain,atomArrays.get(0),atomArrays.get(1)); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Method that constructs a fake MultipleAlignment with two BlockSets, with two and one Blocks respectively. Used to |
| 63 | + * test the correctness of the DataStructure. In the future it will be in the Test packages. |
| 64 | + * @param family name of the protein family |
| 65 | + * @param atomArrays |
| 66 | + * @return MultipleAlignment |
| 67 | + * @throws StructureException |
| 68 | + * @throws StructureAlignmentException |
| 69 | + */ |
| 70 | + private static MultipleAlignment fakeMultipleAlignment(String family, List<Atom[]>atomArrays) throws StructureException { |
| 71 | + |
| 72 | + //Initialize the multiple alignment parent ensemble |
| 73 | + MultipleAlignmentEnsemble ensemble = new MultipleAlignmentEnsembleImpl(); |
| 74 | + ensemble.setAtomArrays(atomArrays); |
| 75 | + ensemble.setAlgorithmName("fakeAlgorithm"); |
| 76 | + MultipleAlignment fakeMultAln = new MultipleAlignmentImpl(ensemble); |
| 77 | + |
| 78 | + if (family == "globins"){ |
| 79 | + |
| 80 | + BlockSet blockSet1 = new BlockSetImpl(fakeMultAln); //first BlockSet with 2 Blocks |
| 81 | + BlockSet blockSet2 = new BlockSetImpl(fakeMultAln); //second BlockSet with 1 Block |
| 82 | + |
| 83 | + Block block1 = new BlockImpl(blockSet1); |
| 84 | + Block block2 = new BlockImpl(blockSet1); |
| 85 | + |
| 86 | + Block block3 = new BlockImpl(blockSet2); |
| 87 | + |
| 88 | + //Alignment obtained from MUSTANG multiple alignment (just some of the residues, not the whole alignment) |
| 89 | + List<Integer> aligned11 = Arrays.asList(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21); |
| 90 | + List<Integer> aligned12 = Arrays.asList(29,30,31,32,33,34,35,36,38); |
| 91 | + List<Integer> aligned13 = Arrays.asList(123,124,125,126,127,128,129,130,131,132,133,134); |
| 92 | + |
| 93 | + List<Integer> aligned21 = Arrays.asList(10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,null,27,28,29,30,31); |
| 94 | + List<Integer> aligned22 = Arrays.asList(39,40,41,42,43,44,45,46,48); |
| 95 | + List<Integer> aligned23 = Arrays.asList(133,134,135,136,137,138,139,140,141,142,143,144); |
| 96 | + |
| 97 | + List<Integer> aligned31 = Arrays.asList(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21); |
| 98 | + List<Integer> aligned32 = Arrays.asList(29,30,31,32,33,34,35,36,38); |
| 99 | + List<Integer> aligned33 = Arrays.asList(117,118,119,120,121,122,123,124,125,126,127,128); |
| 100 | + |
| 101 | + List<Integer> aligned41 = Arrays.asList(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,null,17,18,19,20,21); |
| 102 | + List<Integer> aligned42 = Arrays.asList(30,31,32,33,34,35,36,37,39); |
| 103 | + List<Integer> aligned43 = Arrays.asList(121,122,123,124,125,126,127,128,129,130,131,132); |
| 104 | + |
| 105 | + block1.getAlignRes().add(aligned11); |
| 106 | + block1.getAlignRes().add(aligned21); |
| 107 | + block1.getAlignRes().add(aligned31); |
| 108 | + block1.getAlignRes().add(aligned41); |
| 109 | + |
| 110 | + block2.getAlignRes().add(aligned12); |
| 111 | + block2.getAlignRes().add(aligned22); |
| 112 | + block2.getAlignRes().add(aligned32); |
| 113 | + block2.getAlignRes().add(aligned42); |
| 114 | + |
| 115 | + block3.getAlignRes().add(aligned13); |
| 116 | + block3.getAlignRes().add(aligned23); |
| 117 | + block3.getAlignRes().add(aligned33); |
| 118 | + block3.getAlignRes().add(aligned43); |
| 119 | + |
| 120 | + //Calculating all information in the alignment is as easy as that line, once the residue equivalencies are set |
| 121 | + MultipleSuperimposer imposer = new ReferenceSuperimposer(); |
| 122 | + imposer.superimpose(fakeMultAln); |
| 123 | + MultipleAlignmentScorer.calculateScores(fakeMultAln); |
| 124 | + } |
| 125 | + return fakeMultAln; |
| 126 | + } |
| 127 | + |
| 128 | +} |
0 commit comments