|
1 | 1 | package org.biojava.nbio.structure.align.multiple; |
2 | 2 |
|
| 3 | +import java.io.File; |
| 4 | +import java.io.IOException; |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.Arrays; |
3 | 7 | import java.util.List; |
4 | 8 |
|
5 | | -import org.biojava.nbio.core.sequence.ProteinSequence; |
| 9 | +import org.biojava.nbio.structure.Atom; |
6 | 10 | import org.biojava.nbio.structure.Structure; |
| 11 | +import org.biojava.nbio.structure.StructureException; |
| 12 | +import org.biojava.nbio.structure.StructureTools; |
7 | 13 | import org.biojava.nbio.structure.align.util.AtomCache; |
| 14 | +import org.biojava.nbio.structure.io.PDBFileReader; |
| 15 | +import org.biojava.nbio.structure.io.StructureIOFile; |
8 | 16 | import org.junit.Test; |
9 | 17 |
|
10 | 18 | import static org.junit.Assert.*; |
|
24 | 32 | public class MultipleAlignmentWriterTest { |
25 | 33 |
|
26 | 34 | @Test |
27 | | - public void testFASTA(){ |
| 35 | + public void testFASTA() throws StructureException, IOException{ |
| 36 | + |
| 37 | + MultipleAlignment alignment = generateTestMultipleAlignment(); |
| 38 | + String result = MultipleAlignmentWriter.toFASTA(alignment); |
| 39 | + System.out.println(result); |
| 40 | + |
| 41 | + StringBuffer expected = new StringBuffer(); |
| 42 | + expected.append(">2gox\n"); |
| 43 | + expected.append("---S-tDaErLkhl--IvTpSgAgeq----NmIgMtPt-viAv---HyL-dEt-eqWe-\n"); |
| 44 | + expected.append(">2gox\n"); |
| 45 | + expected.append("GsrS-tDAeRLkh--LiVTpSGaGEqn---MiGMtPTviA-vh--YlDE-tEqwE-Kf-\n"); |
| 46 | + expected.append(">2gox\n"); |
| 47 | + expected.append("GS-rsTDaERLkhl-IvTPSgAGEqnmig--MTPtVIavH-Yld-ETEqwEKf-G-LE-\n"); |
| 48 | + |
| 49 | + assertEquals(result,expected.toString()); |
28 | 50 |
|
29 | 51 | } |
30 | 52 |
|
31 | 53 | @Test |
32 | 54 | public void testFatCat(){ |
33 | 55 |
|
| 56 | + |
34 | 57 | } |
35 | 58 |
|
36 | 59 | @Test |
37 | 60 | public void testAlignedPairs(){ |
38 | 61 |
|
39 | 62 | } |
40 | 63 |
|
41 | | - private List<String> generateTestMSA(){ |
| 64 | + private MultipleAlignment generateTestMultipleAlignment() throws StructureException, IOException{ |
42 | 65 |
|
43 | | - //TODO load a file structure and generate a multiple alignment with multiple blocks |
44 | | - |
45 | | - return null; |
| 66 | + //Obtain the structure atoms |
| 67 | + StructureIOFile reader = new PDBFileReader(); |
| 68 | + File f = new File("src/main/resources/2gox.pdb"); |
| 69 | + Structure structure = null; |
| 70 | + try { |
| 71 | + structure = reader.getStructure(f); |
| 72 | + } catch (IOException e){ |
| 73 | + AtomCache cache = new AtomCache(); |
| 74 | + structure = cache.getStructure("2gox"); |
| 75 | + } |
| 76 | + List<Atom[]> atomArrays = new ArrayList<Atom[]>(3); |
| 77 | + for (int str=0; str<3; str++){ |
| 78 | + Atom[] atoms = StructureTools.getRepresentativeAtomArray(structure); |
| 79 | + atomArrays.add(StructureTools.cloneAtomArray(atoms)); |
| 80 | + } |
| 81 | + |
| 82 | + //Generate the MultipleAlignment - 2 blocks with 2 blocksets each |
| 83 | + MultipleAlignment msa = new MultipleAlignmentImpl(); |
| 84 | + msa.getEnsemble().setStructureNames(Arrays.asList("2gox","2gox","2gox")); |
| 85 | + msa.getEnsemble().setAtomArrays(atomArrays); |
| 86 | + int[] nextResidue = new int[3]; |
| 87 | + for (int bs=0; bs<2; bs++){ |
| 88 | + BlockSet blockSet = new BlockSetImpl(msa); |
| 89 | + for (int b=0; b<2; b++){ |
| 90 | + List<List<Integer>> alnRes = new ArrayList<List<Integer>>(3); |
| 91 | + for (int str=0; str<3; str++){ |
| 92 | + List<Integer> chain = new ArrayList<Integer>(50); |
| 93 | + for (int res=0; res<10; res++){ |
| 94 | + //Introduce gaps and discontinuities to test for all cases |
| 95 | + if (nextResidue[str] % (2+str) == str)chain.add(null); |
| 96 | + else chain.add(nextResidue[str]); |
| 97 | + if (nextResidue[str] % (10) == str) nextResidue[str] ++; |
| 98 | + nextResidue[str]++; |
| 99 | + } |
| 100 | + alnRes.add(chain); |
| 101 | + nextResidue[str]+=str; //Spacing between Blocks |
| 102 | + } |
| 103 | + Block block = new BlockImpl(blockSet); |
| 104 | + block.setAlignRes(alnRes); |
| 105 | + } |
| 106 | + } |
| 107 | + return msa; |
46 | 108 | } |
47 | 109 | } |
0 commit comments