Search in sources :

Example 1 with Structure

use of org.biojava.nbio.structure.Structure in project jstructure by JonStargaryen.

the class SecondaryStructureAnnotatorTest method getDSSPAnnotatedStructure.

private String getDSSPAnnotatedStructure(String id) throws IOException, StructureException {
    // load structure
    Structure protein = new PDBFileReader().getStructureById(id);
    // assign states
    new SecStrucCalc().calculate(protein, true);
    // return complete DSSP annotation string from BioJava
    return protein.getChains().stream().flatMap(chain -> chain.getAtomGroups(GroupType.AMINOACID).stream()).map(aminoAcid -> aminoAcid.getProperty(Group.SEC_STRUC)).map(SecStrucState.class::cast).map(SecStrucState::getType).map(type -> String.valueOf(type.type)).collect(Collectors.joining());
}
Also used : PDBFileReader(org.biojava.nbio.structure.io.PDBFileReader) AbstractFeatureProvider(de.bioforscher.jstructure.model.feature.AbstractFeatureProvider) ProteinParser(de.bioforscher.jstructure.parser.ProteinParser) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StructureException(org.biojava.nbio.structure.StructureException) SecStrucState(org.biojava.nbio.structure.secstruc.SecStrucState) Group(org.biojava.nbio.structure.Group) Structure(org.biojava.nbio.structure.Structure) SecStrucCalc(org.biojava.nbio.structure.secstruc.SecStrucCalc) Protein(de.bioforscher.jstructure.model.structure.Protein) Assert(org.junit.Assert) GroupType(org.biojava.nbio.structure.GroupType) PDBFileReader(org.biojava.nbio.structure.io.PDBFileReader) FeatureProviderRegistry(de.bioforscher.jstructure.model.feature.FeatureProviderRegistry) Before(org.junit.Before) SecStrucCalc(org.biojava.nbio.structure.secstruc.SecStrucCalc) SecStrucState(org.biojava.nbio.structure.secstruc.SecStrucState) Structure(org.biojava.nbio.structure.Structure)

Example 2 with Structure

use of org.biojava.nbio.structure.Structure 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)

Example 3 with Structure

use of org.biojava.nbio.structure.Structure in project jstructure by JonStargaryen.

the class SecondaryStructureAnnotatorTest method getSecondaryStructureAnnotation.

private String getSecondaryStructureAnnotation(String id) {
    // load structure
    Protein protein = ProteinParser.source(id).parse();
    // assign states
    featureProvider.process(protein);
    // return complete DSSP annotation string from jstructrue
    return protein.aminoAcids().map(residue -> residue.getFeatureContainer().getFeature(SecondaryStructure.class)).map(SecondaryStructure::getSecondaryStructure).map(SecondaryStructureElement::getOneLetterRepresentation).map(character -> character.equals("c") ? " " : character).collect(Collectors.joining());
}
Also used : AbstractFeatureProvider(de.bioforscher.jstructure.model.feature.AbstractFeatureProvider) ProteinParser(de.bioforscher.jstructure.parser.ProteinParser) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StructureException(org.biojava.nbio.structure.StructureException) SecStrucState(org.biojava.nbio.structure.secstruc.SecStrucState) Group(org.biojava.nbio.structure.Group) Structure(org.biojava.nbio.structure.Structure) SecStrucCalc(org.biojava.nbio.structure.secstruc.SecStrucCalc) Protein(de.bioforscher.jstructure.model.structure.Protein) Assert(org.junit.Assert) GroupType(org.biojava.nbio.structure.GroupType) PDBFileReader(org.biojava.nbio.structure.io.PDBFileReader) FeatureProviderRegistry(de.bioforscher.jstructure.model.feature.FeatureProviderRegistry) Before(org.junit.Before) Protein(de.bioforscher.jstructure.model.structure.Protein)

Example 4 with Structure

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

the class MmtfImporter method importMmcifFiles.

/**
 * Reads uncompressed and compressed mmCIF files recursively from a given
 * directory path. This methods reads files with the .cif or .cif.gz
 * extension.
 *
 * @param path
 *            Path to .cif files
 * @param sc
 *            Spark context
 * @return structure data as keyword/value pairs
 */
public static JavaPairRDD<String, StructureDataInterface> importMmcifFiles(String path, JavaSparkContext sc) {
    FileParsingParameters params = new FileParsingParameters();
    params.setCreateAtomBonds(true);
    return sc.parallelize(getFiles(path)).mapToPair(new PairFunction<File, String, StructureDataInterface>() {

        private static final long serialVersionUID = -7815663658405168429L;

        public Tuple2<String, StructureDataInterface> call(File f) throws Exception {
            InputStream is = null;
            String path = f.getName();
            // TODO debugging
            System.out.println(path);
            if (path.endsWith(".cif") || path.endsWith((".cif.gz"))) {
                try {
                    is = new FileInputStream(f);
                    if (path.endsWith(".cif.gz")) {
                        is = new GZIPInputStream(is);
                    }
                    // parse .cif file
                    MMCIFFileReader mmcifReader = new MMCIFFileReader();
                    mmcifReader.setFileParsingParameters(params);
                    Structure struc = mmcifReader.getStructure(is);
                    is.close();
                    // convert to mmtf
                    AdapterToStructureData writerToEncoder = new AdapterToStructureData();
                    new MmtfStructureWriter(struc, writerToEncoder);
                    return new Tuple2<String, StructureDataInterface>(path.substring(0, path.indexOf(".cif")), writerToEncoder);
                } catch (Exception e) {
                    System.out.println("WARNING: cannot parse: " + path + ". Skipping this entry!");
                    return null;
                }
            } else {
                return null;
            }
        }
    }).filter(t -> t != null);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MMCIFFileReader(org.biojava.nbio.structure.io.MMCIFFileReader) FileParsingParameters(org.biojava.nbio.structure.io.FileParsingParameters) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) GZIPInputStream(java.util.zip.GZIPInputStream) AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) Tuple2(scala.Tuple2) PairFunction(org.apache.spark.api.java.function.PairFunction) Structure(org.biojava.nbio.structure.Structure) MmtfStructureWriter(org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter) File(java.io.File)

Example 5 with Structure

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

the class MmtfImporter method getFromMmcifUrl.

/**
 * Reads a mmCIF file from a URL.
 *
 * @param url URL for mmCIF file
 * @return
 * @throws IOException
 */
private static AdapterToStructureData getFromMmcifUrl(String url, String structureId) throws IOException {
    FileParsingParameters params = new FileParsingParameters();
    params.setCreateAtomBonds(true);
    URL u = new URL(url);
    InputStream is = null;
    try {
        is = u.openStream();
    } catch (IOException e) {
        return null;
    }
    try {
        if (url.endsWith(".gz")) {
            is = new GZIPInputStream(is);
        }
    } catch (Exception e) {
        return null;
    }
    try {
        // parse .cif file
        MMCIFFileReader mmcifReader = new MMCIFFileReader();
        mmcifReader.setFileParsingParameters(params);
        Structure struc = mmcifReader.getStructure(is);
        is.close();
        // convert to mmtf
        AdapterToStructureData writerToEncoder = new AdapterToStructureData();
        new MmtfStructureWriter(struc, writerToEncoder);
        return writerToEncoder;
    } catch (Exception e) {
        System.out.println("WARNING: cannot parse: " + url + ". Skipping this entry!");
        return null;
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MMCIFFileReader(org.biojava.nbio.structure.io.MMCIFFileReader) FileParsingParameters(org.biojava.nbio.structure.io.FileParsingParameters) IOException(java.io.IOException) Structure(org.biojava.nbio.structure.Structure) MmtfStructureWriter(org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter) URL(java.net.URL) IOException(java.io.IOException)

Aggregations

Structure (org.biojava.nbio.structure.Structure)8 IOException (java.io.IOException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 MmtfStructureWriter (org.biojava.nbio.structure.io.mmtf.MmtfStructureWriter)3 SecStrucCalc (org.biojava.nbio.structure.secstruc.SecStrucCalc)3 AdapterToStructureData (org.rcsb.mmtf.encoder.AdapterToStructureData)3 AbstractFeatureProvider (de.bioforscher.jstructure.model.feature.AbstractFeatureProvider)2 FeatureProviderRegistry (de.bioforscher.jstructure.model.feature.FeatureProviderRegistry)2 Protein (de.bioforscher.jstructure.model.structure.Protein)2 ProteinParser (de.bioforscher.jstructure.parser.ProteinParser)2 Collectors (java.util.stream.Collectors)2 Group (org.biojava.nbio.structure.Group)2 GroupType (org.biojava.nbio.structure.GroupType)2 StructureException (org.biojava.nbio.structure.StructureException)2 FileParsingParameters (org.biojava.nbio.structure.io.FileParsingParameters)2 MMCIFFileReader (org.biojava.nbio.structure.io.MMCIFFileReader)2 PDBFileReader (org.biojava.nbio.structure.io.PDBFileReader)2