Search in sources :

Example 1 with EntityInfo

use of org.biojava.nbio.structure.EntityInfo in project mmtf-spark by sbl-sdsc.

the class MmtfImporter method toStructureDataInterface.

/**
 * Parses PDB-formatted input stream and return structure data.
 *
 * @param inputStream PDB-formatted input stream
 * @param structureId id to be assigned to the structure
 * @return structure data
 * @throws IOException
 */
private static AdapterToStructureData toStructureDataInterface(InputStream inputStream, String structureId) throws IOException {
    // standardize PDB formatting
    InputStream pdbIs = standardizePdbInputStream(inputStream);
    // parse PDB and generate BioJava Structure object
    PDBFileParser parser = new PDBFileParser();
    parser.getFileParsingParameters().setCreateAtomBonds(true);
    Structure struct = parser.parsePDBFile(pdbIs);
    struct.setPDBCode(structureId);
    // where the entity info is null when there is only one polymer chain.
    for (EntityInfo info : struct.getEntityInfos()) {
        if (info.getType() == null) {
            for (String chainId : info.getChainIds()) {
                Chain c = struct.getChain(chainId);
                if (c.getAtomSequence().length() > 0) {
                    info.setType(EntityType.POLYMER);
                }
            }
        }
    }
    pdbIs.close();
    // convert to MMTF
    AdapterToStructureData writerToEncoder = new AdapterToStructureData();
    // TODO get version number
    writerToEncoder.setMmtfProducer("mmtf-spark 0.2.0");
    new MmtfStructureWriter(struct, writerToEncoder);
    return writerToEncoder;
}
Also used : Chain(org.biojava.nbio.structure.Chain) AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EntityInfo(org.biojava.nbio.structure.EntityInfo) PDBFileParser(org.biojava.nbio.structure.io.PDBFileParser) Structure(org.biojava.nbio.structure.Structure) MmtfStructureWriter(org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Chain (org.biojava.nbio.structure.Chain)1 EntityInfo (org.biojava.nbio.structure.EntityInfo)1 Structure (org.biojava.nbio.structure.Structure)1 PDBFileParser (org.biojava.nbio.structure.io.PDBFileParser)1 MmtfStructureWriter (org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter)1 AdapterToStructureData (org.rcsb.mmtf.encoder.AdapterToStructureData)1