Java Code Examples for org.biojava.nbio.structure.io.FileParsingParameters#setHeaderOnly()

The following examples show how to use org.biojava.nbio.structure.io.FileParsingParameters#setHeaderOnly() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DemoAtomCache.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void demoAtomCache() {
	AtomCache cache = new AtomCache();

	FileParsingParameters params = cache.getFileParsingParams();

	params.setAlignSeqRes(true);
	params.setHeaderOnly(false);
	params.setParseCAOnly(false);
	params.setParseSecStruc(false);

	String[] pdbIDs = new String[]{"4hhb", "1cdg","5pti","1gav", "WRONGID" };

	for (String pdbID : pdbIDs){

		try {
			Structure s = cache.getStructure(pdbID);
			if ( s == null) {
				System.out.println("could not find structure " + pdbID);
				continue;
			}
			// do something with the structure
			System.out.println(s);

		} catch (Exception e){
			// something crazy happened...
			System.err.println("Can't load structure " + pdbID + " reason: " + e.getMessage());
			//e.printStackTrace();
		}
	}

}
 
Example 2
Source File: Test2JA5.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void test2JA5() throws IOException, StructureException {

	FileParsingParameters fileParsingParameters = new FileParsingParameters();
	fileParsingParameters.setAlignSeqRes(true); // Need to align seqres to match chains.
	fileParsingParameters.setHeaderOnly(false); // Need header only off to have chains to match.

	AtomCache cache = new AtomCache();
	cache.setUseMmCif(false);
	cache.setFileParsingParams(fileParsingParameters);

	StructureIO.setAtomCache(cache);

	Structure s1 = StructureIO.getStructure("2ja5");

	// This is not applicable anymore, we need to parse atoms to have chains to match.
	// assertTrue(StructureTools.getNrAtoms(s1) == 0);

	// SeqRes contains 14 chains, but since we cannot align Chain N to AtomGroups => 14.
	// 2ja5 has been remediated on March 2017, now it has 14 chains in seqres matching the 14 chains in atoms (chain N has been removed)
	assertEquals(14, s1.getPolyChains().size());

	Chain nChain = s1.getPolyChain("N");

	assertNotNull(nChain);

	Chain chain = s1.getPolyChainByPDB("N");
	assertNull(chain);
}
 
Example 3
Source File: Test2JA5.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void test2JA5noHeader() throws IOException, StructureException {

	FileParsingParameters fileParsingParameters = new FileParsingParameters();
	fileParsingParameters.setHeaderOnly(true);

	AtomCache cache = new AtomCache();
	cache.setUseMmCif(false);
	cache.setFileParsingParams(fileParsingParameters);

	StructureIO.setAtomCache(cache);


	Structure s1 = StructureIO.getStructure("2ja5");

	// This is not applicable anymore, we need to parse atoms to have chains to match.
	assertEquals(0, StructureTools.getNrAtoms(s1));

	// 2ja5 has been remediated on March 2017, now it has 14 chains in seqres matching the 14 chains in atoms (chain N has been removed)
	assertEquals(14, s1.getPolyChains().size());

	Chain nChain = s1.getPolyChainByPDB("N");

	assertNull(nChain);
}
 
Example 4
Source File: CifFileConsumerIntegrationTest.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void comparePDB2cif(String id, String chainId) throws IOException {
    String fileName = binary ? "/" + id + ".bcif" : "/" + id + ".cif";
    System.out.println(fileName);
    InputStream inStream = getClass().getResourceAsStream(fileName);
    assertNotNull("Could not find file " + fileName + ". Config problem?", inStream);

    LocalPDBDirectory reader = binary ? new BcifFileReader() : new CifFileReader();

    FileParsingParameters params = new FileParsingParameters();
    params.setHeaderOnly(headerOnly);
    reader.setFileParsingParameters(params);

    Structure cifStructure = reader.getStructure(inStream);
    assertNotNull(cifStructure);

    // load the PDB file via the PDB parser
    Structure pdbStructure;
    InputStream pinStream = this.getClass().getResourceAsStream("/" + id + ".pdb");
    assertNotNull(inStream);

    PDBFileParser pdbParser = new PDBFileParser();
    pdbParser.setFileParsingParameters(params);

    pdbStructure = pdbParser.parsePDBFile(pinStream);

    assertNotNull(pdbStructure);

    // check NMR data
    assertEquals(id + ": the isNMR flag is not the same!",
            pdbStructure.isNmr(),
            cifStructure.isNmr());

    if (pdbStructure.isNmr()) {
        assertEquals(id + ": the nr of NMR models is not the same!",
                pdbStructure.nrModels(),
                pdbStructure.nrModels());
        checkNMR(pdbStructure);
        checkNMR(cifStructure);
    }

    Chain a_pdb = pdbStructure.getPolyChainByPDB(chainId);
    Chain a_cif = cifStructure.getPolyChainByPDB(chainId);

    String pdb_SEQseq = a_pdb.getSeqResSequence();
    String cif_SEQseq = a_cif.getSeqResSequence();

    assertEquals(id + ": the SEQRES sequences don't match!",
            pdb_SEQseq,
            cif_SEQseq);

    assertEquals(id + ":  The nr of ATOM groups does not match!",
            a_pdb.getAtomGroups(GroupType.AMINOACID).size(),
            a_cif.getAtomGroups(GroupType.AMINOACID).size());

    // actually this check not necessarily works, since there can be waters in PDB that we don;t deal with yet in cif...
    for (int i = 0; i < a_pdb.getAtomGroups(GroupType.AMINOACID).size(); i++) {
        Group gp = a_pdb.getAtomGroups(GroupType.AMINOACID).get(i);
        List<Group> cifGroups = a_cif.getAtomGroups(GroupType.AMINOACID);
        Group gc = cifGroups.get(i);
        checkGroups(gp, gc);
    }

    String pdb_seq = a_pdb.getAtomSequence();
    String cif_seq = a_cif.getAtomSequence();

    assertEquals("the sequences obtained from PDB and mmCif don't match!", pdb_seq, cif_seq);

    List<DBRef> pdb_dbrefs = pdbStructure.getDBRefs();
    List<DBRef> cif_dbrefs = cifStructure.getDBRefs();

    assertEquals("nr of DBrefs found does not match!", pdb_dbrefs.size(), cif_dbrefs.size());

    DBRef p = pdb_dbrefs.get(0);
    DBRef c = cif_dbrefs.get(0);

    String pdb_dbref = p.toPDB();
    String cif_dbref = c.toPDB();
    assertEquals("DBRef is not equal", pdb_dbref, cif_dbref);

    PDBHeader h1 = pdbStructure.getPDBHeader();
    PDBHeader h2 = cifStructure.getPDBHeader();

    if (!h1.toPDB().toUpperCase().equals(h2.toPDB().toUpperCase())) {
        System.err.println(h1.toPDB());
        System.err.println(h2.toPDB());
        assertEquals(h1.toPDB(), h2.toPDB());
    }
    assertEquals("the PDBHeader.toPDB representation is not equivalent",
            h1.toPDB().toUpperCase(),
            h2.toPDB().toUpperCase());
}