File: TestQuaternaryStructureProviders.java

package info (click to toggle)
biojava6-live 6.1.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 109,224 kB
  • sloc: java: 245,617; xml: 27,410; python: 64; makefile: 39; sh: 31
file content (226 lines) | stat: -rw-r--r-- 6,909 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 */

package org.biojava.nbio.structure.io;

import org.biojava.nbio.structure.*;
import org.biojava.nbio.structure.align.util.AtomCache;
import org.biojava.nbio.structure.quaternary.BioAssemblyInfo;
import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation;
import org.junit.Ignore;
import org.junit.Test;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class TestQuaternaryStructureProviders {

        @Ignore("The test requires the network")
	@Test
	public void test1STP() throws IOException, StructureException{
		comparePdbVsMmcif("1stp",1, 4);
	}

        @Ignore("The test requires the network")
	@Test
	public void test3FAD() throws IOException, StructureException{
		comparePdbVsMmcif("3fad",1, 1);
		comparePdbVsMmcif("3fad",2, 2);
	}

        @Ignore("The test requires the network")
	@Test
	public void test5LDH() throws IOException, StructureException{
		comparePdbVsMmcif("5LDH",1, 4);

		// the pdb file of 5ldh contains only 1 bioassembly, whilst the mmcif contains 2,
		// thus we can't test here the comparison between the 2
		//testID("5LDH",2, 2);

		// since v5 remediation there's 4 bioassemblies with numerical ids for 5ldh, no more PAU and XAU
		boolean gotException = false;
		try {
			AtomCache cache = new AtomCache();
			cache.setFiletype(StructureFiletype.CIF);
			StructureIO.setAtomCache(cache);
			StructureIO.getBiologicalAssembly("5LDH",3);
		} catch (StructureException e) {
			gotException = true;
		}

		assertTrue("Bioassembly 3 for PDB id 5LDH should fail with a StructureException!", !gotException);

		// bioassembly 2 does exist in mmcif file, let's check that
		gotException = false;
		try {
			AtomCache cache = new AtomCache();
			cache.setFiletype(StructureFiletype.CIF);
			StructureIO.setAtomCache(cache);
			StructureIO.getBiologicalAssembly("5LDH",2);
		} catch (StructureException e) {
			gotException = true;
		}
		assertTrue("Bioassembly 2 for PDB id 5LDH should not fail with a StructureException!", !gotException);

	}

        @Ignore("The test requires the network")
	@Test
	public void test3NTU() throws IOException, StructureException{
		comparePdbVsMmcif("3NTU",1, 6);
	}

        @Ignore("The test requires the network")
	@Test
	public void test1A29() throws IOException, StructureException{
		comparePdbVsMmcif("1A29",1, 1);
	}

        @Ignore("The test requires the network")
	@Test
	public void test1EI7() throws IOException, StructureException {

		comparePdbVsMmcif("1ei7",1, 68);

	}

        @Ignore("The test requires the network")
	@Test
	public void testGetNrBioAssemblies5LDH() throws IOException, StructureException {
		assertEquals("There should be 4 bioassemblies for 5LDH, see github issue #230", 4, StructureIO.getBiologicalAssemblies("5LDH").size());
	}


	/**
	 * Bioassembly tests for a single PDB entry
	 * @param pdbId
	 * @param bioMolecule the bio assembly identifier to test
	 * @param mmSize the expected mmSize of given bioMolecule number
	 * @throws IOException
	 * @throws StructureException
	 */
	private void comparePdbVsMmcif(String pdbId, int bioMolecule, int mmSize) throws IOException, StructureException{


		Structure pdbS = getPdbBioAssembly(pdbId, bioMolecule, true);

		Structure mmcifS = getMmcifBioAssembly(pdbId, bioMolecule, true);

		PDBHeader pHeader = pdbS.getPDBHeader();
		PDBHeader mHeader = mmcifS.getPDBHeader();

		assertTrue("not correct nr of bioassemblies " + pHeader.getNrBioAssemblies() + " " , pHeader.getNrBioAssemblies() >= bioMolecule);
		assertTrue("not correct nr of bioassemblies " + mHeader.getNrBioAssemblies() + " " , mHeader.getNrBioAssemblies() >= bioMolecule);

		// mmcif files contain sometimes partial virus assemblies, so they can contain more info than pdb
		assertTrue(pHeader.getNrBioAssemblies() <= mHeader.getNrBioAssemblies());


		Map<Integer, BioAssemblyInfo> pMap = pHeader.getBioAssemblies();
		Map<Integer, BioAssemblyInfo> mMap = mHeader.getBioAssemblies();


		assertTrue(pMap.keySet().size()<= mMap.keySet().size());

		assertEquals(mmSize, mMap.get(bioMolecule).getMacromolecularSize());


		for ( int k : pMap.keySet()) {
			assertTrue(mMap.containsKey(k));

			BioAssemblyInfo pBioAssemb = pMap.get(k);
			BioAssemblyInfo mBioAssemb = mMap.get(k);

			assertEquals("Macromolecular sizes don't coincide!",pBioAssemb.getMacromolecularSize(), mBioAssemb.getMacromolecularSize());

			List<BiologicalAssemblyTransformation> pL = pBioAssemb.getTransforms();

			// mmcif list can be longer due to the use of internal chain IDs
			List<BiologicalAssemblyTransformation> mL = mBioAssemb.getTransforms();

			//assertEquals(pL.size(), mL.size());


			for (BiologicalAssemblyTransformation m1 : pL){

				boolean found = false;
				for ( BiologicalAssemblyTransformation m2 : mL){

					if  (! m1.getChainId().equals(m2.getChainId()))
						continue;

					if ( ! m1.getTransformationMatrix().epsilonEquals(m2.getTransformationMatrix(), 0.0001))
						continue;

					found = true;

				}

				if ( ! found ){
					System.err.println("did not find matching matrix " + m1);
					System.err.println(mL);
				}
				assertTrue(found);

			}
		}


		assertEquals("Not the same number of chains!" , pdbS.size(),mmcifS.size());

		Atom[] pdbA = StructureTools.getAllAtomArray(pdbS);

		Atom[] mmcifA = StructureTools.getAllAtomArray(mmcifS);

		assertEquals(pdbA.length, mmcifA.length);

		assertEquals(pdbA[0].toPDB(), mmcifA[0].toPDB());




	}

	private Structure getPdbBioAssembly(String pdbId, int bioMolecule, boolean multiModel) throws IOException, StructureException {
		// get bio assembly from PDB file
		AtomCache cache = new AtomCache();
		cache.setFiletype(StructureFiletype.PDB);
		StructureIO.setAtomCache(cache);
		Structure pdbS = StructureIO.getBiologicalAssembly(pdbId, bioMolecule, multiModel);
		return pdbS;
	}

	private Structure getMmcifBioAssembly(String pdbId, int bioMolecule, boolean multiModel) throws IOException, StructureException {
		// get bio assembly from mmcif file
		AtomCache cache = new AtomCache();
		cache.setFiletype(StructureFiletype.CIF);
		StructureIO.setAtomCache(cache);
		Structure mmcifS = StructureIO.getBiologicalAssembly(pdbId, bioMolecule, multiModel);
		return mmcifS;
	}



}