Search in sources :

Example 46 with StructureDataInterface

use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.

the class StructureAligner method getAllVsAllAlignments.

/**
 * Calculates all vs. all structural alignments of protein chains using the
 * specified alignment algorithm. The input structures must contain single
 * protein chains.
 *
 * @param targets structures containing single protein chains
 * @param alignmentAlgorithm name of the algorithm
 * @return dataset with alignment metrics
 */
public static Dataset<Row> getAllVsAllAlignments(JavaPairRDD<String, StructureDataInterface> targets, String alignmentAlgorithm) {
    SparkSession session = SparkSession.builder().getOrCreate();
    JavaSparkContext sc = new JavaSparkContext(session.sparkContext());
    // create a list of chainName/ C Alpha coordinates
    List<Tuple2<String, Point3d[]>> chains = targets.mapValues(s -> new ColumnarStructureX(s, true).getcAlphaCoordinates()).collect();
    // create an RDD of all pair indices (0,1), (0,2), ..., (1,2), (1,3), ...
    JavaRDD<Tuple2<Integer, Integer>> pairs = getPairs(sc, chains.size());
    // calculate structural alignments for all pairs.
    // broadcast (copy) chains to all worker nodes for efficient processing.
    // for each pair there can be zero or more solutions, therefore we flatmap the pairs.
    JavaRDD<Row> rows = pairs.flatMap(new StructuralAlignmentMapper(sc.broadcast(chains), alignmentAlgorithm));
    // convert rows to a dataset
    return session.createDataFrame(rows, getSchema());
}
Also used : IntStream(java.util.stream.IntStream) DataTypes(org.apache.spark.sql.types.DataTypes) StructField(org.apache.spark.sql.types.StructField) StructType(org.apache.spark.sql.types.StructType) Iterator(java.util.Iterator) Dataset(org.apache.spark.sql.Dataset) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) ColumnarStructureX(edu.sdsc.mmtf.spark.utils.ColumnarStructureX) Row(org.apache.spark.sql.Row) Tuple2(scala.Tuple2) Collectors(java.util.stream.Collectors) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) List(java.util.List) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) Point3d(javax.vecmath.Point3d) JavaRDD(org.apache.spark.api.java.JavaRDD) FlatMapFunction(org.apache.spark.api.java.function.FlatMapFunction) SparkSession(org.apache.spark.sql.SparkSession) SparkSession(org.apache.spark.sql.SparkSession) Tuple2(scala.Tuple2) Point3d(javax.vecmath.Point3d) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Row(org.apache.spark.sql.Row) ColumnarStructureX(edu.sdsc.mmtf.spark.utils.ColumnarStructureX)

Example 47 with StructureDataInterface

use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.

the class MergeMmtf method addEntityInfo.

private static void addEntityInfo(StructureDataInterface[] structures, AdapterToStructureData complex) {
    int currentOffset = 0;
    int offset = 0;
    for (StructureDataInterface structure : structures) {
        for (int i = 0; i < structure.getNumEntities(); i++) {
            int[] indices = structure.getEntityChainIndexList(i).clone();
            // System.out.println("offset: " + offset);
            for (int j = 0; j < indices.length; j++) {
                indices[j] += offset;
                currentOffset = Math.max(currentOffset, indices[j]);
            }
            complex.setEntityInfo(indices, structure.getEntitySequence(i), structure.getEntityDescription(i), structure.getEntityType(i));
        }
        offset = currentOffset + 1;
    }
}
Also used : StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface)

Example 48 with StructureDataInterface

use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.

the class MergeMmtf method initStructure.

private static void initStructure(String structureId, StructureDataInterface[] structures, AdapterToStructureData complex) {
    int nBonds = 0;
    int nAtoms = 0;
    int nGroups = 0;
    int nChains = 0;
    int nModels = 1;
    float resolution = -1;
    float rFree = -1;
    float rWork = -1;
    String title = "";
    for (StructureDataInterface s : structures) {
        nBonds += s.getNumBonds();
        nAtoms += s.getNumAtoms();
        nGroups += s.getNumGroups();
        nChains += s.getNumChains();
        resolution = Math.max(resolution, s.getResolution());
        rFree = Math.max(rFree, s.getRfree());
        rWork = Math.max(rFree, s.getRwork());
        title += s.getTitle();
    }
    String[] experimentalMethods = { "THEORETICAL MODEL" };
    complex.setMmtfProducer("mmtf-spark");
    complex.initStructure(nBonds, nAtoms, nGroups, nChains, nModels, structureId);
    complex.setHeaderInfo(rFree, rWork, resolution, title, "20180101", "20180101", experimentalMethods);
    complex.setModelInfo(0, nChains);
}
Also used : StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface)

Example 49 with StructureDataInterface

use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.

the class MergeMmtf method MergeStructures.

public static StructureDataInterface MergeStructures(String structureId, StructureDataInterface... structures) {
    for (StructureDataInterface s : structures) {
        if (s.getNumModels() != 1) {
            throw new IllegalArgumentException("ERROR: Cannot merge structures with more than one model");
        }
    }
    AdapterToStructureData complex = new AdapterToStructureData();
    initStructure(structureId, structures, complex);
    addEntityInfo(structures, complex);
    for (StructureDataInterface structure : structures) {
        addStructure(structure, complex);
    }
    complex.finalizeStructure();
    return complex;
}
Also used : AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface)

Example 50 with StructureDataInterface

use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.

the class D3RLigandProteinMerger method main.

public static void main(String[] args) throws IOException {
    long start = System.nanoTime();
    // instantiate Spark
    SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("D3RLigandProteinMerger");
    JavaSparkContext sc = new JavaSparkContext(conf);
    // String path = "/Users/peter/Downloads/Pose_prediction/417-1-hciq4/";
    String path = "/Users/peter/Downloads/Pose_prediction/";
    JavaPairRDD<String, StructureDataInterface> ligands = Molmporter.importMolFiles(path, sc);
    ligands = ligands.mapToPair(t -> new Tuple2<String, StructureDataInterface>(removeExtension(t._1), t._2));
    JavaPairRDD<String, StructureDataInterface> proteins = MmtfImporter.importPdbFiles(path, sc);
    proteins = proteins.mapToPair(t -> new Tuple2<String, StructureDataInterface>(removeExtension(t._1), t._2));
    JavaPairRDD<String, Tuple2<StructureDataInterface, StructureDataInterface>> pairs = proteins.join(ligands);
    JavaPairRDD<String, StructureDataInterface> complexes = pairs.mapToPair(t -> new Tuple2<String, StructureDataInterface>(t._1, MergeMmtf.MergeStructures(t._1, t._2._1, t._2._2)));
    complexes.foreach(t -> TraverseStructureHierarchy.printChainInfo(t._2));
    // System.out.println("Complexes: " + complexes.count());
    // complexes.keys().foreach(k -> System.out.println(k));
    // TraverseStructureHierarchy.printChainInfo(complexes.first()._2);
    sc.close();
    long end = System.nanoTime();
    System.out.println("Time: " + (end - start) / 1E9 + " sec.");
}
Also used : MmtfImporter(edu.sdsc.mmtf.spark.io.MmtfImporter) Arrays(java.util.Arrays) SparkConf(org.apache.spark.SparkConf) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Set(java.util.Set) IOException(java.io.IOException) Tuple2(scala.Tuple2) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) File(java.io.File) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TraverseStructureHierarchy(edu.sdsc.mmtf.spark.io.demos.TraverseStructureHierarchy) List(java.util.List) MergeMmtf(edu.sdsc.mm.dev.io.MergeMmtf) Molmporter(edu.sdsc.mm.dev.io.Molmporter) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) SynchronizedSortedBag(org.apache.commons.collections.bag.SynchronizedSortedBag) Path(java.nio.file.Path) Files(org.spark_project.guava.io.Files) JavaRDD(org.apache.spark.api.java.JavaRDD) Tuple2(scala.Tuple2) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) SparkConf(org.apache.spark.SparkConf)

Aggregations

StructureDataInterface (org.rcsb.mmtf.api.StructureDataInterface)102 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)60 SparkConf (org.apache.spark.SparkConf)58 Row (org.apache.spark.sql.Row)27 StructureToPolymerChains (edu.sdsc.mmtf.spark.mappers.StructureToPolymerChains)22 Test (org.junit.Test)20 Pisces (edu.sdsc.mmtf.spark.webfilters.Pisces)19 ArrayList (java.util.ArrayList)12 ProteinSequenceEncoder (edu.sdsc.mmtf.spark.ml.ProteinSequenceEncoder)10 ColumnarStructure (edu.sdsc.mmtf.spark.utils.ColumnarStructure)10 Tuple2 (scala.Tuple2)9 Path (java.nio.file.Path)7 HashSet (java.util.HashSet)7 AdapterToStructureData (org.rcsb.mmtf.encoder.AdapterToStructureData)7 JavaPairRDD (org.apache.spark.api.java.JavaPairRDD)6 ContainsLProteinChain (edu.sdsc.mmtf.spark.filters.ContainsLProteinChain)5 List (java.util.List)5 Resolution (edu.sdsc.mmtf.spark.filters.Resolution)4 MmtfReader (edu.sdsc.mmtf.spark.io.MmtfReader)4 File (java.io.File)4