Search in sources :

Example 81 with StructureDataInterface

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

the class PolymerComposition method call.

@Override
public Boolean call(Tuple2<String, StructureDataInterface> t) throws Exception {
    StructureDataInterface structure = t._2;
    boolean containsPolymer = false;
    boolean globalMatch = false;
    // only check first model
    int numChains = structure.getChainsPerModel()[0];
    for (int i = 0, groupCounter = 0; i < numChains; i++) {
        boolean match = true;
        String chainType = EncoderUtils.getTypeFromChainId(structure, i);
        boolean polymer = chainType.equals("polymer");
        if (polymer) {
            containsPolymer = true;
        } else {
            match = false;
        }
        for (int j = 0; j < structure.getGroupsPerChain()[i]; j++, groupCounter++) {
            if (match && polymer) {
                int groupIndex = structure.getGroupTypeIndices()[groupCounter];
                String name = structure.getGroupName(groupIndex);
                match = residues.contains(name);
            }
        }
        if (polymer && match && !exclusive) {
            return true;
        }
        if (polymer && !match && exclusive) {
            return false;
        }
        if (match) {
            globalMatch = true;
        }
    }
    return globalMatch && containsPolymer;
}
Also used : StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface)

Example 82 with StructureDataInterface

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

the class ContainsPolymerChainType method call.

@Override
public Boolean call(Tuple2<String, StructureDataInterface> t) throws Exception {
    StructureDataInterface structure = t._2;
    boolean containsPolymer = false;
    boolean globalMatch = false;
    // only check first model
    int numChains = structure.getChainsPerModel()[0];
    for (int i = 0, groupCounter = 0; i < numChains; i++) {
        boolean match = true;
        String chainType = EncoderUtils.getTypeFromChainId(structure, i);
        boolean polymer = chainType.equals("polymer");
        if (polymer) {
            containsPolymer = true;
        } else {
            match = false;
        }
        for (int j = 0; j < structure.getGroupsPerChain()[i]; j++, groupCounter++) {
            if (match && polymer) {
                int groupIndex = structure.getGroupTypeIndices()[groupCounter];
                String type = structure.getGroupChemCompType(groupIndex);
                match = entityTypes.contains(type);
            }
        }
        if (polymer && match && !exclusive) {
            return true;
        }
        if (polymer && !match && exclusive) {
            return false;
        }
        if (match) {
            globalMatch = true;
        }
    }
    return globalMatch && containsPolymer;
}
Also used : StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface)

Example 83 with StructureDataInterface

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

the class MmtfImporterTest method test3.

@Test
public void test3() throws IOException {
    Path p = Paths.get("./src/main/resources/files/test");
    JavaPairRDD<String, StructureDataInterface> pdb = MmtfImporter.importPdbFiles(p.toString(), sc);
    assertTrue(pdb.count() == 1);
    pdb = pdb.flatMapToPair(new StructureToPolymerChains());
    assertEquals(8, pdb.count());
}
Also used : Path(java.nio.file.Path) StructureToPolymerChains(edu.sdsc.mmtf.spark.mappers.StructureToPolymerChains) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) Test(org.junit.Test)

Example 84 with StructureDataInterface

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

the class MmtfImporterTest method test4.

@Test
public void test4() throws IOException {
    Path p = Paths.get("./src/main/resources/files/test");
    JavaPairRDD<String, StructureDataInterface> pdb = MmtfImporter.importMmcifFiles(p.toString(), sc);
    assertTrue(pdb.count() == 1);
    pdb = pdb.flatMapToPair(new StructureToPolymerChains());
    assertEquals(8, pdb.count());
}
Also used : Path(java.nio.file.Path) StructureToPolymerChains(edu.sdsc.mmtf.spark.mappers.StructureToPolymerChains) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) Test(org.junit.Test)

Example 85 with StructureDataInterface

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

the class MmtfImporterTest method test2.

@Test
public void test2() throws IOException {
    Path p = Paths.get("./src/main/resources/files/");
    JavaPairRDD<String, StructureDataInterface> pdb = MmtfImporter.importMmcifFiles(p.toString(), sc);
    assertEquals(2, pdb.count());
}
Also used : Path(java.nio.file.Path) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) Test(org.junit.Test)

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