Search in sources :

Example 66 with StructureDataInterface

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

the class StructureToPolymerSequences method call.

@Override
public Iterator<Tuple2<String, String>> call(Tuple2<String, StructureDataInterface> t) throws Exception {
    StructureDataInterface structure = t._2;
    List<Tuple2<String, String>> sequences = new ArrayList<>();
    Set<String> seqSet = new HashSet<>();
    // precalculate indices
    int[] chainToEntityIndex = getChainToEntityIndex(structure);
    for (int i = 0; i < structure.getChainsPerModel()[0]; i++) {
        boolean polymer = structure.getEntityType(chainToEntityIndex[i]).equals("polymer");
        if (polymer) {
            String key = t._1;
            // remove any previous chain id information
            if (key.contains(".")) {
                key = key.substring(0, key.indexOf("."));
            }
            key += ".";
            if (useChainIdInsteadOfChainName) {
                key += structure.getChainIds()[i];
            } else {
                key += structure.getChainNames()[i];
            }
            if (removeDuplicates) {
                if (seqSet.contains(structure.getEntitySequence(chainToEntityIndex[i]))) {
                    continue;
                }
                seqSet.add(structure.getEntitySequence(chainToEntityIndex[i]));
            }
            sequences.add(new Tuple2<String, String>(key, structure.getEntitySequence(chainToEntityIndex[i])));
        }
    }
    return sequences.iterator();
}
Also used : Tuple2(scala.Tuple2) ArrayList(java.util.ArrayList) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) HashSet(java.util.HashSet)

Example 67 with StructureDataInterface

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

the class StructureToProteinDimers method getCBetaAtomsDistanceBoxes.

private static List<DistanceBox<Integer>> getCBetaAtomsDistanceBoxes(List<StructureDataInterface> chains, double cutoffDistance) {
    List<DistanceBox<Integer>> distanceBoxes = new ArrayList<DistanceBox<Integer>>();
    for (int i = 0; i < chains.size(); i++) {
        StructureDataInterface tmp = chains.get(i);
        DistanceBox<Integer> newBox = new DistanceBox<Integer>(cutoffDistance);
        int groupIndex = 0;
        int atomIndex = 0;
        for (int k = 0; k < tmp.getGroupsPerChain()[0]; k++) {
            int groupType = tmp.getGroupTypeIndices()[groupIndex];
            for (int m = 0; m < tmp.getNumAtomsInGroup(groupType); m++) {
                String atomName = tmp.getGroupAtomNames(groupType)[m];
                if (atomName.equals("CB")) {
                    double xCoord = tmp.getxCoords()[atomIndex];
                    double yCoord = tmp.getyCoords()[atomIndex];
                    double zCoord = tmp.getzCoords()[atomIndex];
                    Point3d newPoint = new Point3d(xCoord, yCoord, zCoord);
                    newBox.addPoint(newPoint, atomIndex);
                }
                atomIndex++;
            }
            groupIndex++;
        }
        distanceBoxes.add(newBox);
    }
    return distanceBoxes;
}
Also used : Point3d(javax.vecmath.Point3d) ArrayList(java.util.ArrayList) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) DistanceBox(org.biojava.nbio.structure.symmetry.geometry.DistanceBox)

Example 68 with StructureDataInterface

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

the class MapToProteinDimers method main.

public static void main(String[] args) {
    SparkConf conf = new SparkConf().setMaster("local[*]").setAppName(MapToProteinDimers.class.getSimpleName());
    JavaSparkContext sc = new JavaSparkContext(conf);
    // single protein chain 5IBZ
    List<String> pdbIds = Arrays.asList("5IBZ");
    JavaPairRDD<String, StructureDataInterface> pdb = MmtfReader.downloadFullMmtfFiles(pdbIds, sc);
    // if distance between C-beta atoms is less than the cutoff distance, two chains are considered in contact
    double cutoffDistance = 8;
    // minimum number of contacts to qualify as an interaction
    int minContacts = 20;
    pdb = // convert to bioassembly (homotetramer with D2 symmetry)
    pdb.flatMapToPair(new StructureToBioassembly()).flatMapToPair(// find all dimers with in bioassembly
    new StructureToProteinDimers(cutoffDistance, minContacts));
    System.out.println("Number of dimers in 5IBZ bioassembly: " + pdb.count());
    sc.close();
}
Also used : StructureToBioassembly(edu.sdsc.mmtf.spark.mappers.StructureToBioassembly) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) SparkConf(org.apache.spark.SparkConf) StructureToProteinDimers(edu.sdsc.mmtf.spark.mappers.StructureToProteinDimers)

Example 69 with StructureDataInterface

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

the class WriteMmtfFullUncompressed method main.

public static void main(String[] args) throws FileNotFoundException {
    String path = MmtfReader.getMmtfFullPath();
    long start = System.nanoTime();
    // instantiate Spark. Each Spark application needs these two lines of code.
    SparkConf conf = new SparkConf().setMaster("local[*]").setAppName(WriteMmtfFullUncompressed.class.getSimpleName());
    JavaSparkContext sc = new JavaSparkContext(conf);
    // read all PDB entries from a local Hadoop sequence file
    JavaPairRDD<String, StructureDataInterface> pdb = MmtfReader.readSequenceFile(path, sc);
    System.out.println("# structures: " + pdb.count());
    // write an uncompressed Hadoop sequence file
    boolean compressed = false;
    MmtfWriter.writeSequenceFile(path + "_uncompressed", sc, pdb, compressed);
    // close Spark
    sc.close();
    long end = System.nanoTime();
    System.out.println((end - start) / 1E9 + " sec.");
}
Also used : JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) SparkConf(org.apache.spark.SparkConf)

Example 70 with StructureDataInterface

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

the class StructureToBioassembly method call.

@Override
public Iterator<Tuple2<String, StructureDataInterface>> call(Tuple2<String, StructureDataInterface> t) throws Exception {
    StructureDataInterface structure = t._2;
    // Map<Integer, Integer> atomMap = new HashMap<>();
    List<Tuple2<String, StructureDataInterface>> resList = new ArrayList<>();
    // for each of them, create one structure.
    for (int i = 0; i < structure.getNumBioassemblies(); i++) {
        // initiate the bioassembly structure.
        AdapterToStructureData bioAssembly = new AdapterToStructureData();
        // set the structureID.
        String structureId = structure.getStructureId() + "-BioAssembly" + structure.getBioassemblyName(i);
        int totAtoms = 0, totBonds = 0, totGroups = 0, totChains = 0, totModels = 0;
        int numTrans = structure.getNumTransInBioassembly(i);
        totModels = structure.getNumModels();
        int[][] bioChainList = new int[numTrans][];
        double[][] transMatrix = new double[numTrans][];
        // calculate the total data we will use to initialize the structure.
        for (int ii = 0; ii < numTrans; ii++) {
            bioChainList[ii] = structure.getChainIndexListForTransform(i, ii);
            transMatrix[ii] = structure.getMatrixForTransform(i, ii);
            for (int j = 0; j < totModels; j++) {
                totChains += bioChainList[ii].length;
                // System.out.println(bioChainList[ii].length);
                for (int k = 0, groupCounter = 0; k < structure.getChainsPerModel()[j]; k++) {
                    boolean adding = false;
                    for (int currChain : bioChainList[ii]) {
                        if (currChain == k)
                            adding = true;
                    }
                    if (adding) {
                        // System.out.println("adding groups");
                        totGroups += structure.getGroupsPerChain()[k];
                    }
                    for (int h = 0; h < structure.getGroupsPerChain()[k]; h++, groupCounter++) {
                        if (adding) {
                            int groupIndex = structure.getGroupTypeIndices()[groupCounter];
                            totAtoms += structure.getNumAtomsInGroup(groupIndex);
                            totBonds += structure.getGroupBondOrders(groupIndex).length;
                        }
                    }
                }
            }
        }
        // init
        // System.out.println("Initializing the structure with\n"
        // + " totModel = " + totModels + ", totChains = " + totChains + ", totGroups = " + totGroups + ", totAtoms = "
        // + totAtoms + ", totBonds = " + totBonds + ", name : " + structureId);
        bioAssembly.initStructure(totBonds, totAtoms, totGroups, totChains, totModels, structureId);
        DecoderUtils.addXtalographicInfo(structure, bioAssembly);
        DecoderUtils.addHeaderInfo(structure, bioAssembly);
        /*
			 * Now we have bioChainList and transMatrix.
			 * bioChainList[i] is the ith trans' list of chains it has.  
			 * transMatrix[i] is the matrix that is going to be applied on those chains.
			 */
        // initialize the indices.
        int modelIndex = 0;
        int chainIndex = 0;
        int groupIndex = 0;
        int atomIndex = 0;
        int chainCounter = 0;
        // loop through models
        for (int ii = 0; ii < structure.getNumModels(); ii++) {
            // precalculate indices
            int numChainsPerModel = structure.getChainsPerModel()[modelIndex] * numTrans;
            bioAssembly.setModelInfo(modelIndex, numChainsPerModel);
            int[] chainToEntityIndex = getChainToEntityIndex(structure);
            // loop through chains
            for (int j = 0; j < structure.getChainsPerModel()[modelIndex]; j++) {
                // loop through each trans
                int currGroupIndex = groupIndex;
                int currAtomIndex = atomIndex;
                for (int k = 0; k < numTrans; k++) {
                    // get the currChainList that needs to be added
                    int[] currChainList = bioChainList[k];
                    double[] currMatrix = transMatrix[k];
                    boolean addThisChain = false;
                    for (int currChain : currChainList) {
                        if (currChain == j)
                            addThisChain = true;
                    }
                    groupIndex = currGroupIndex;
                    atomIndex = currAtomIndex;
                    float[] xCoords = structure.getxCoords();
                    float[] yCoords = structure.getyCoords();
                    float[] zCoords = structure.getzCoords();
                    float[] floatMatrix = Floats.toArray(Doubles.asList(currMatrix));
                    Matrix4f m = new Matrix4f(floatMatrix);
                    if (addThisChain) {
                        int entityToChainIndex = chainToEntityIndex[chainIndex];
                        // System.out.println("adding chain : " + chainIndex);
                        // TODO
                        // not sure
                        bioAssembly.setEntityInfo(new int[] { chainCounter }, structure.getEntitySequence(entityToChainIndex), structure.getEntityDescription(entityToChainIndex), structure.getEntityType(entityToChainIndex));
                        bioAssembly.setChainInfo(structure.getChainIds()[chainIndex], structure.getChainNames()[chainIndex], structure.getGroupsPerChain()[chainIndex]);
                        chainCounter++;
                    }
                    // loop through the groups in the chain
                    for (int jj = 0; jj < structure.getGroupsPerChain()[chainIndex]; jj++) {
                        int currgroup = structure.getGroupTypeIndices()[groupIndex];
                        if (addThisChain) {
                            bioAssembly.setGroupInfo(structure.getGroupName(currgroup), structure.getGroupIds()[groupIndex], structure.getInsCodes()[groupIndex], structure.getGroupChemCompType(currgroup), structure.getNumAtomsInGroup(currgroup), structure.getGroupBondOrders(currgroup).length, structure.getGroupSingleLetterCode(currgroup), structure.getGroupSequenceIndices()[groupIndex], structure.getSecStructList()[groupIndex]);
                        }
                        for (int kk = 0; kk < structure.getNumAtomsInGroup(currgroup); kk++) {
                            // System.out.println("currgroup : " + currgroup + " curratom : " + kk);
                            if (addThisChain) {
                                Point3f p1 = new Point3f(xCoords[atomIndex], yCoords[atomIndex], zCoords[atomIndex]);
                                m.transform(p1);
                                // System.out.println(kk + " " + currgroup);
                                bioAssembly.setAtomInfo(structure.getGroupAtomNames(currgroup)[kk], structure.getAtomIds()[atomIndex], structure.getAltLocIds()[atomIndex], p1.x, p1.y, p1.z, structure.getOccupancies()[atomIndex], structure.getbFactors()[atomIndex], structure.getGroupElementNames(currgroup)[kk], structure.getGroupAtomCharges(currgroup)[kk]);
                            }
                            // inc the atomIndex
                            atomIndex++;
                        }
                        if (addThisChain) {
                            for (int l = 0; l < structure.getGroupBondOrders(currgroup).length; l++) {
                                // System.out.println(structure.getGroupBondOrders(currgroup).length + " " + l);
                                int bondIndOne = structure.getGroupBondIndices(currgroup)[l * 2];
                                int bondIndTwo = structure.getGroupBondIndices(currgroup)[l * 2 + 1];
                                int bondOrder = structure.getGroupBondOrders(currgroup)[l];
                                bioAssembly.setGroupBond(bondIndOne, bondIndTwo, bondOrder);
                            }
                        }
                        // inc the groupIndex
                        groupIndex++;
                    }
                    if (addThisChain) {
                    // Add inter-group bond info
                    // for(int l = 0;  l < structure.getInterGroupBondOrders().length; l++){
                    // int bondIndOne = structure.getInterGroupBondIndices()[l*2];
                    // int bondIndTwo = structure.getInterGroupBondIndices()[l*2+1];
                    // int bondOrder = structure.getInterGroupBondOrders()[l];
                    // Integer indexOne = atomMap.get(bondIndOne);
                    // if (indexOne != null) {
                    // Integer indexTwo = atomMap.get(bondIndTwo);
                    // if (indexTwo != null) {
                    // bioAssembly.setInterGroupBond(indexOne, indexTwo, bondOrder);
                    // }
                    // }
                    }
                }
                // inc the chainIndex
                chainIndex++;
            }
            // inc the modelIndex
            modelIndex++;
        }
        bioAssembly.finalizeStructure();
        resList.add(new Tuple2<String, StructureDataInterface>(structureId, bioAssembly));
    }
    return resList.iterator();
}
Also used : ArrayList(java.util.ArrayList) StructureDataInterface(org.rcsb.mmtf.api.StructureDataInterface) AdapterToStructureData(org.rcsb.mmtf.encoder.AdapterToStructureData) Matrix4f(javax.vecmath.Matrix4f) Point3f(javax.vecmath.Point3f) Tuple2(scala.Tuple2)

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