Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.biojava.nbio.structure.test;

import junit.framework.TestCase;

import org.biojava.nbio.structure.*;
import org.biojava.nbio.structure.align.util.AtomCache;
import org.biojava.nbio.structure.io.FileParsingParameters;
Expand All @@ -35,21 +36,15 @@

public class StructureToolsTest extends TestCase {

Structure structure, structure2, structure3;
Structure structure, structure2, structure3, structure4;

@Override
protected void setUp() throws IOException
{
InputStream inStream = this.getClass().getResourceAsStream("/5pti.pdb");
assertNotNull(inStream);


PDBFileParser pdbpars = new PDBFileParser();
FileParsingParameters params = new FileParsingParameters();
params.setAlignSeqRes(false);
params.setLoadChemCompInfo(false);

pdbpars.setFileParsingParameters(params);

structure = pdbpars.parsePDBFile(inStream) ;

Expand All @@ -59,7 +54,7 @@ protected void setUp() throws IOException

Chain chain = structure.getChain(0);
assertEquals("Wrong number of residues.",123,chain.getAtomLength());

inStream.close();

// Load structure2
Expand Down Expand Up @@ -93,11 +88,32 @@ public void testGetCAAtoms(){
assertEquals("did not find the expected number of Atoms (58), but got " + cas.length,58,cas.length);
}

public void testGetAtomsConsistency() throws IOException, StructureException{
AtomCache cache = new AtomCache();
FileParsingParameters params = new FileParsingParameters();
params.setLoadChemCompInfo(true);
cache.setFileParsingParams(params);

Structure hivA = cache.getStructure("1hiv.A");
Atom[] caSa = StructureTools.getRepresentativeAtomArray(hivA);
Atom[] caCa = StructureTools.getRepresentativeAtomArray(hivA.getChain(0));
assertEquals("did not find the same number of Atoms from structure and from chain..",
caSa.length,caCa.length);
Structure hivB = cache.getStructure("1hiv.B");
Atom[] caSb = StructureTools.getRepresentativeAtomArray(hivB);
Atom[] caCb = StructureTools.getRepresentativeAtomArray(hivB.getChain(0));
assertEquals("did not find the same number of Atoms from structure and from chain..",
caSb.length,caCb.length);
//Both chains have to be the same size (A and B)
assertEquals(caSa.length,99);
assertEquals("did not find the same number of Atoms in both chains...",
caSa.length,caCb.length);
assertEquals(caSa.length, 99);
}

public void testGetNrAtoms(){
int length = StructureTools.getNrAtoms(structure);
assertEquals("did not find the expected number of Atoms (1087), but got " + length,1087,length);


}

public void testGetSubRanges() throws StructureException {
Expand Down Expand Up @@ -188,18 +204,18 @@ public void testGetSubRanges() throws StructureException {
range = "_:";
substr = StructureTools.getSubRanges(structure2, range);
assertEquals("Wrong number of chains in "+range, 1, substr.size());

chain = substr.getChain(0);
assertEquals("Chain _ not converted to chain A.","A",chain.getChainID());
assertEquals("Did not find the expected number of residues in first chain of "+range, 411, chain.getAtomLength() );

try {
// Illegal chain name
range = "X:";
substr = StructureTools.getSubRanges(structure2, range);
fail("Illegal chain name in '"+range+"'. Should throw StructureException");
} catch(StructureException ex) {} //expected

// some negative tests
try {
range = "7-10";
Expand All @@ -217,7 +233,7 @@ public void testRevisedConvention() throws IOException, StructureException{

AtomCache cache = new AtomCache();


String name11 = "4hhb.A";
Structure s = cache.getStructure(name11);
assertTrue(s.getChains().size() == 1);
Expand All @@ -230,7 +246,7 @@ public void testRevisedConvention() throws IOException, StructureException{
String name13 = "4hhb.A_";
s = cache.getStructure(name13);
assertTrue(s.getChains().size() == 1);

String name9 = "4hhb.C_1-83";
String chainId = "C";
s = cache.getStructure(name9);
Expand All @@ -247,47 +263,47 @@ public void testRevisedConvention() throws IOException, StructureException{
ca = StructureTools.getRepresentativeAtomArray(s);
assertEquals(93, ca.length);


}


// this will get replaced by #81
// public void testStructureToolsRegexp(){
//
//
// Pattern p = ResidueRange.RANGE_REGEX;
//
// String t2 = "A_10-20";
// Matcher m2 = p.matcher(t2);
// assertNotNull(m2);
// assertTrue(m2.find());
// assertTrue(m2.matches());
//
// // for (int i=0;i< m2.groupCount();i++){
// // String s = m2.group(i);
// // System.out.println(s);
// // }
// assertEquals(3,m2.groupCount());
//
//
// String t1 = "A:10-20";
// Matcher m1 = p.matcher(t1);
// assertNotNull(m1);
// assertTrue(m1.find());
// assertTrue(m1.matches());
// assertEquals(3,m1.groupCount());
//
//
// String t3 = "A";
// Matcher m3 = p.matcher(t3);
//
// assertNotNull(m3);
// assertTrue(m3.find());
// assertTrue(m3.matches());
// assertEquals(3,m3.groupCount());
//
//
// }
// this will get replaced by #81
// public void testStructureToolsRegexp(){
//
//
// Pattern p = ResidueRange.RANGE_REGEX;
//
// String t2 = "A_10-20";
// Matcher m2 = p.matcher(t2);
// assertNotNull(m2);
// assertTrue(m2.find());
// assertTrue(m2.matches());
//
// // for (int i=0;i< m2.groupCount();i++){
// // String s = m2.group(i);
// // System.out.println(s);
// // }
// assertEquals(3,m2.groupCount());
//
//
// String t1 = "A:10-20";
// Matcher m1 = p.matcher(t1);
// assertNotNull(m1);
// assertTrue(m1.find());
// assertTrue(m1.matches());
// assertEquals(3,m1.groupCount());
//
//
// String t3 = "A";
// Matcher m3 = p.matcher(t3);
//
// assertNotNull(m3);
// assertTrue(m3.find());
// assertTrue(m3.matches());
// assertEquals(3,m3.groupCount());
//
//
// }

/**
* Test some subranges that we used to have problems with
Expand Down Expand Up @@ -408,27 +424,35 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
public void testGroupsWithinShell() {
//TODO
}

public void testCAmmCIF() throws StructureException {
//mmCIF files left justify their atom names (eg "CA "), so can have different behavior
AtomCache pdbCache = new AtomCache();
pdbCache.setUseMmCif(false);
FileParsingParameters params = new FileParsingParameters();
params.setLoadChemCompInfo(true);
pdbCache.setFileParsingParams(params);

AtomCache mmcifCache = new AtomCache();
mmcifCache.setUseMmCif(true);
FileParsingParameters params2 = new FileParsingParameters();
params2.setLoadChemCompInfo(true);
mmcifCache.setFileParsingParams(params2);


Structure pdb=null, mmcif=null;

String name = "3PIU";
try {
pdb = pdbCache.getStructure(name);
mmcif = mmcifCache.getStructure(name);
} catch (IOException e) {
assumeNoException(e);
}

Atom[] pdbCA = StructureTools.getRepresentativeAtomArray(pdb);
Atom[] mmcifCA = StructureTools.getRepresentativeAtomArray(mmcif);

assertEquals("PDB has wrong length",409,pdbCA.length);
assertEquals("PDB has wrong length",409,mmcifCA.length);
}
Expand Down
Loading