Search in sources :

Example 1 with ContractedGraph

use of model.graph.ContractedGraph in project Smiles2Monomers by yoann-dufresne.

the class CoveragesJsonLoader method getJSONGraph.

@SuppressWarnings("unchecked")
private JSONObject getJSONGraph(Coverage cov) {
    ContractedGraph cg = new ContractedGraph(cov);
    MonomerGraph mg = cg.toMonomerGraph(families);
    JSONObject graph = new JSONObject();
    // Monomers
    JSONArray monos = new JSONArray();
    for (Monomer mono : mg.nodes) if (mono != null)
        monos.add(mono.getName());
    else
        monos.add("?");
    graph.put("monos", monos);
    // Residues (equivalent to monomers)
    JSONArray residues = new JSONArray();
    for (Residue res : mg.residues) if (res != null)
        residues.add(res.getId());
    else
        residues.add("?");
    graph.put("residues", residues);
    // Links
    JSONArray links = new JSONArray();
    for (MonomerLinks ml : mg.links) {
        JSONObject link = new JSONObject();
        JSONArray idxs = new JSONArray();
        idxs.add(ml.mono1);
        idxs.add(ml.mono2);
        link.put("idxs", idxs);
        JSONArray type = new JSONArray();
        type.add(ml.label1);
        type.add(ml.label2);
        link.put("types", type);
        links.add(link);
    }
    graph.put("links", links);
    return graph;
}
Also used : MonomerLinks(model.graph.MonomerGraph.MonomerLinks) JSONObject(org.json.simple.JSONObject) Residue(model.Residue) ContractedGraph(model.graph.ContractedGraph) JSONArray(org.json.simple.JSONArray) MonomerGraph(model.graph.MonomerGraph) Monomer(model.Monomer)

Example 2 with ContractedGraph

use of model.graph.ContractedGraph in project Smiles2Monomers by yoann-dufresne.

the class RemoveByDistance method remove.

@Override
public void remove(Coverage cov, ContractedGraph cg) {
    ContractedGraph clone = cg.clone();
    this.removeRecur(cov, clone, 0);
}
Also used : ContractedGraph(model.graph.ContractedGraph)

Example 3 with ContractedGraph

use of model.graph.ContractedGraph in project Smiles2Monomers by yoann-dufresne.

the class MonomericSpliting method computeCoverage.

/**
 * Calculate an object Coverage with all matches from families.
 * @param pep Peptide to match
 */
public void computeCoverage(Polymer pep) {
    this.coverage = new Coverage(pep);
    this.matcher.setChemicalObject(pep);
    Isomorphism.setMappingStorage(true);
    // Step 1 : Strict Matching
    if (verbose) {
        System.out.println("+Strict matching");
        System.out.println("++Search residues");
    }
    this.matchAllFamilies(MatchingType.STRONG);
    double ratio = this.coverage.getCoverageRatio();
    if (ratio < 1.0) {
        if (verbose)
            System.out.println("++Modulation");
        this.coverage = this.modulation.modulate(this.coverage);
    }
    Coverage save = this.coverage.clone();
    // conditions to go to light matching
    if (!this.allowLightMatchs || ratio == 1.0) {
        Isomorphism.setMappingStorage(false);
        return;
    }
    // TODO : Why if/else ?
    if (this.condition == null)
        this.condition = new ExtendsNTimes(this.retry);
    else
        this.condition.init();
    this.remover.init();
    // Successive matchings
    int depth = 0;
    while (this.coverage.getCoverageRatio() < 1.0 && this.condition.toContinue(this.coverage)) {
        depth++;
        // Contract the atomic graph to monomeric graph
        ContractedGraph contracted = new ContractedGraph(this.coverage);
        // Remove monomers from the current solution to try with other matching strategy
        this.remover.remove(this.coverage, contracted);
        // Create a masked molecule to only search on free polymer areas
        Molecule mol = DeepenMatcher.mask(this.coverage);
        this.coverage.setCurrentMaskedMol(mol);
        OtherChemicalObject tmp = new OtherChemicalObject(mol);
        this.matcher.setChemicalObject(tmp);
        if (verbose) {
            System.out.println("+Light matching, depth " + depth);
            System.out.println("++Search residues");
        }
        // Compute for all families with ligth matching
        this.matchAllFamilies(MatchingType.LIGHT);
        // Re-compute coverage
        this.coverage.calculateGreedyCoverage();
        if (this.coverage.getCoverageRatio() < 1.0) {
            if (verbose)
                System.out.println("++Modulation");
            this.coverage = this.modulation.modulate(this.coverage);
        }
        if (this.coverage.getCoverageRatio() > save.getCoverageRatio())
            save = this.coverage.clone();
        this.remover.nextLevel();
    }
    Isomorphism.setMappingStorage(false);
    if (save.getCoverageRatio() > this.coverage.getCoverageRatio())
        this.coverage = save;
}
Also used : Molecule(org.openscience.cdk.Molecule) ExtendsNTimes(algorithms.isomorphism.conditions.ExtendsNTimes) ContractedGraph(model.graph.ContractedGraph) Coverage(algorithms.utils.Coverage) OtherChemicalObject(model.OtherChemicalObject)

Aggregations

ContractedGraph (model.graph.ContractedGraph)3 ExtendsNTimes (algorithms.isomorphism.conditions.ExtendsNTimes)1 Coverage (algorithms.utils.Coverage)1 Monomer (model.Monomer)1 OtherChemicalObject (model.OtherChemicalObject)1 Residue (model.Residue)1 MonomerGraph (model.graph.MonomerGraph)1 MonomerLinks (model.graph.MonomerGraph.MonomerLinks)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Molecule (org.openscience.cdk.Molecule)1