Search in sources :

Example 11 with Pisces

use of edu.sdsc.mmtf.spark.webfilters.Pisces in project mm-dev by sbl-sdsc.

the class DemoQueryVsAll method main.

public static void main(String[] args) throws IOException {
    String path = MmtfReader.getMmtfReducedPath();
    SparkConf conf = new SparkConf().setMaster("local[*]").setAppName(DemoQueryVsAll.class.getSimpleName());
    JavaSparkContext sc = new JavaSparkContext(conf);
    long start = System.nanoTime();
    // download query structure
    List<String> queryId = Arrays.asList("2W47");
    JavaPairRDD<String, StructureDataInterface> query = MmtfReader.downloadFullMmtfFiles(queryId, sc).flatMapToPair(new StructureToPolymerChains());
    // use a 1 % sample of the PDB and then filter by the Pisces
    // non-redundant set
    // at 20% sequence identity and a resolution better than 1.6 A.
    double fraction = 1.0;
    long seed = 123;
    JavaPairRDD<String, StructureDataInterface> target = MmtfReader.readSequenceFile(path, fraction, seed, sc).flatMapToPair(new StructureToPolymerChains()).filter(new Pisces(20, 1.6)).sample(false, 0.08, seed);
    // specialized algorithms
    // String alignmentAlgorithm = CeMain.algorithmName;
    // String alignmentAlgorithm = CeCPMain.algorithmName;
    // String alignmentAlgorithm = FatCatFlexible.algorithmName;
    // two standard algorithms
    // String alignmentAlgorithm = CeMain.algorithmName;
    String alignmentAlgorithm = FatCatRigid.algorithmName;
    // String alignmentAlgorithm = ExhaustiveAligner.alignmentAlgorithm;
    // calculate alignments
    Dataset<Row> alignments = StructureAligner.getQueryVsAllAlignments(query, target, alignmentAlgorithm).cache();
    // show results
    int count = (int) alignments.count();
    alignments.sort(col("tm").desc()).show(count);
    System.out.println("Pairs: " + count);
    long end = System.nanoTime();
    System.out.println("Time per alignment: " + TimeUnit.NANOSECONDS.toMillis((end - start) / count) + " msec.");
    System.out.println("Time: " + TimeUnit.NANOSECONDS.toSeconds(end - start) + " sec.");
    sc.close();
}
Also used : StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) Pisces(edu.sdsc.mmtf.spark.webfilters.Pisces) StructureToPolymerChains(edu.sdsc.mmtf.spark.mappers.StructureToPolymerChains) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Row(org.apache.spark.sql.Row) SparkConf(org.apache.spark.SparkConf)

Example 12 with Pisces

use of edu.sdsc.mmtf.spark.webfilters.Pisces in project mm-dev by sbl-sdsc.

the class CathClassificationDataset method getSequenceData.

private static Dataset<Row> getSequenceData(String[] args) throws IOException {
    SparkSession spark = SparkSession.builder().master("local[*]").getOrCreate();
    JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
    JavaRDD<Row> pdb = MmtfReader.readSequenceFile(args[0], sc).flatMapToPair(new StructureToPolymerChains()).filter(new Pisces(40, 2.0)).map(t -> RowFactory.create(t._1, t._2.getEntitySequence(0)));
    // Generate the schema
    StructType schema = new StructType(new StructField[] { new StructField("structureChainId", DataTypes.StringType, false, Metadata.empty()), new StructField("sequence", DataTypes.StringType, false, Metadata.empty()) });
    // Apply the schema to the RDD
    return spark.createDataFrame(pdb, schema);
}
Also used : SparkSession(org.apache.spark.sql.SparkSession) StructField(org.apache.spark.sql.types.StructField) StructType(org.apache.spark.sql.types.StructType) Pisces(edu.sdsc.mmtf.spark.webfilters.Pisces) StructureToPolymerChains(edu.sdsc.mmtf.spark.mappers.StructureToPolymerChains) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Row(org.apache.spark.sql.Row)

Example 13 with Pisces

use of edu.sdsc.mmtf.spark.webfilters.Pisces in project mmtf-spark by sbl-sdsc.

the class Metalnteractions method main.

public static void main(String[] args) throws IOException {
    String path = MmtfReader.getMmtfFullPath();
    SparkConf conf = new SparkConf().setMaster("local[*]").setAppName(Metalnteractions.class.getSimpleName());
    JavaSparkContext sc = new JavaSparkContext(conf);
    // input parameters
    int sequenceIdentityCutoff = 30;
    double resolution = 2.5;
    int minInteractions = 4;
    int maxInteractions = 6;
    double distanceCutoff = 3.0;
    // chemical component codes of metals in different oxidation states
    String[] metals = { "V", "CR", "MN", "MN3", "FE", "FE2", "CO", "3CO", "NI", "3NI", "CU", "CU1", "CU3", "ZN", "MO", "4MO", "6MO" };
    // read PDB and create a non-redundant PISCES subset
    JavaPairRDD<String, StructureDataInterface> pdb = MmtfReader.readSequenceFile(path, sc).filter(new Pisces(sequenceIdentityCutoff, resolution));
    // Setup criteria for metal interactions
    InteractionFilter filter = new InteractionFilter();
    filter.setDistanceCutoff(distanceCutoff);
    filter.setMinInteractions(minInteractions);
    filter.setMaxInteractions(maxInteractions);
    filter.setQueryGroups(true, metals);
    // exclude non-polar interactions
    filter.setTargetElements(false, "H", "C", "P");
    // tabulate interactions in a dataframe
    Dataset<Row> interactions = GroupInteractionExtractor.getInteractions(pdb, filter).cache();
    System.out.println("Metal interactions: " + interactions.count());
    // select interacting atoms and orientational order parameters (q4 - q6)
    // see {@link CoordinationGeometry}
    interactions = interactions.select("pdbId", "q4", "q5", "q6", "element0", "groupNum0", "chain0", "element1", "groupNum1", "chain1", "distance1", "element2", "groupNum2", "chain2", "distance2", "element3", "groupNum3", "chain3", "distance3", "element4", "groupNum4", "chain4", "distance4", "element5", "groupNum5", "chain5", "distance5", "element6", "groupNum6", "chain6", "distance6").cache();
    // show some example interactions
    interactions.dropDuplicates("pdbId").show(10);
    System.out.println("Unique interactions by metal:");
    interactions.groupBy("element0").count().sort("count").show();
    sc.close();
}
Also used : StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) InteractionFilter(edu.sdsc.mmtf.spark.interactions.InteractionFilter) Pisces(edu.sdsc.mmtf.spark.webfilters.Pisces) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Row(org.apache.spark.sql.Row) SparkConf(org.apache.spark.SparkConf)

Example 14 with Pisces

use of edu.sdsc.mmtf.spark.webfilters.Pisces in project mmtf-spark by sbl-sdsc.

the class PdbSequenceToWord2Vec method main.

public static void main(String[] args) throws IOException {
    String path = MmtfReader.getMmtfReducedPath();
    if (args.length != 1) {
        System.err.println("Usage: " + PdbSequenceToWord2Vec.class.getSimpleName() + " <outputFileName>");
        System.exit(1);
    }
    long start = System.nanoTime();
    SparkConf conf = new SparkConf().setMaster("local[*]").setAppName(SecondaryStructureWord2VecEncoder.class.getSimpleName());
    JavaSparkContext sc = new JavaSparkContext(conf);
    // read MMTF Hadoop sequence file and create a non-redundant Pisces
    // subset set (<=40% seq. identity) of L-protein chains
    int sequenceIdentity = 40;
    double resolution = 3.0;
    JavaPairRDD<String, StructureDataInterface> pdb = MmtfReader.readSequenceFile(path, sc).flatMapToPair(new StructureToPolymerChains()).filter(new Pisces(sequenceIdentity, resolution));
    Dataset<Row> data = PolymerSequenceExtractor.getDataset(pdb);
    data.show(10, false);
    // length of polymer sequence segment (number of residues)
    int segmentLength = 11;
    // add Word2Vec encoded feature vector
    ProteinSequenceEncoder encoder = new ProteinSequenceEncoder(data);
    // size of n-grams
    int n = 2;
    int windowSize = (segmentLength - 1) / 2;
    // dimension of vector
    int vectorSize = 50;
    data = encoder.overlappingNgramWord2VecEncode(n, windowSize, vectorSize);
    encoder.getWord2VecModel().save(args[0]);
    long end = System.nanoTime();
    System.out.println(TimeUnit.NANOSECONDS.toSeconds(end - start) + " sec.");
}
Also used : ProteinSequenceEncoder(edu.sdsc.mmtf.spark.ml.ProteinSequenceEncoder) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) Pisces(edu.sdsc.mmtf.spark.webfilters.Pisces) StructureToPolymerChains(edu.sdsc.mmtf.spark.mappers.StructureToPolymerChains) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Row(org.apache.spark.sql.Row) SparkConf(org.apache.spark.SparkConf)

Example 15 with Pisces

use of edu.sdsc.mmtf.spark.webfilters.Pisces in project mmtf-spark by sbl-sdsc.

the class SecondaryStructureBlosum62Encoder method main.

/**
 * @param args args[0] outputFilePath, args[1] outputFormat (json|parquet)
 * @throws IOException
 * @throws StructureException
 */
public static void main(String[] args) throws IOException {
    String path = MmtfReader.getMmtfReducedPath();
    if (args.length != 2) {
        System.err.println("Usage: " + SecondaryStructureBlosum62Encoder.class.getSimpleName() + " <outputFilePath> + <fileFormat>");
        System.exit(1);
    }
    long start = System.nanoTime();
    SparkConf conf = new SparkConf().setMaster("local[*]").setAppName(SecondaryStructureBlosum62Encoder.class.getSimpleName());
    JavaSparkContext sc = new JavaSparkContext(conf);
    // read MMTF Hadoop sequence file and create a non-redundant Pisces
    // subset set (<=20% seq. identity) of L-protein chains
    int sequenceIdentity = 20;
    double resolution = 3.0;
    JavaPairRDD<String, StructureDataInterface> pdb = MmtfReader.readSequenceFile(path, sc).flatMapToPair(new StructureToPolymerChains()).filter(new Pisces(sequenceIdentity, resolution));
    int segmentLength = 11;
    Dataset<Row> data = SecondaryStructureSegmentExtractor.getDataset(pdb, segmentLength).cache();
    System.out.println("original data     : " + data.count());
    data = data.dropDuplicates("labelQ3", "sequence").cache();
    System.out.println("- duplicate Q3/seq: " + data.count());
    data = data.dropDuplicates("sequence").cache();
    System.out.println("- duplicate seq   : " + data.count());
    // add a property encoded feature vector
    ProteinSequenceEncoder encoder = new ProteinSequenceEncoder(data);
    data = encoder.blosum62Encode();
    data.printSchema();
    data.show(25, false);
    if (args[1].equals("json")) {
        // coalesce data into a single file
        data = data.coalesce(1);
    }
    data.write().mode("overwrite").format(args[1]).save(args[0]);
    long end = System.nanoTime();
    System.out.println(TimeUnit.NANOSECONDS.toSeconds(end - start) + " sec.");
}
Also used : ProteinSequenceEncoder(edu.sdsc.mmtf.spark.ml.ProteinSequenceEncoder) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) Pisces(edu.sdsc.mmtf.spark.webfilters.Pisces) StructureToPolymerChains(edu.sdsc.mmtf.spark.mappers.StructureToPolymerChains) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Row(org.apache.spark.sql.Row) SparkConf(org.apache.spark.SparkConf)

Aggregations

Pisces (edu.sdsc.mmtf.spark.webfilters.Pisces)20 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)20 SparkConf (org.apache.spark.SparkConf)19 StructureDataInterface (org.rcsb.mmtf.api.StructureDataInterface)19 Row (org.apache.spark.sql.Row)18 StructureToPolymerChains (edu.sdsc.mmtf.spark.mappers.StructureToPolymerChains)15 ProteinSequenceEncoder (edu.sdsc.mmtf.spark.ml.ProteinSequenceEncoder)10 GroupInteractionExtractor (edu.sdsc.mmtf.spark.datasets.GroupInteractionExtractor)3 CustomReportDemo (edu.sdsc.mmtf.spark.datasets.demos.CustomReportDemo)1 InteractionFilter (edu.sdsc.mmtf.spark.interactions.InteractionFilter)1 StructureToBioJava (edu.sdsc.mmtf.spark.mappers.StructureToBioJava)1 StructureToBioassembly2 (edu.sdsc.mmtf.spark.mappers.StructureToBioassembly2)1 SparkSession (org.apache.spark.sql.SparkSession)1 StructField (org.apache.spark.sql.types.StructField)1 StructType (org.apache.spark.sql.types.StructType)1 Structure (org.biojava.nbio.structure.Structure)1