Search in sources :

Example 21 with Residue

use of model.Residue in project Smiles2Monomers by yoann-dufresne.

the class FamilyChainIO method objectFromJson.

@Override
protected FamilyChainsDB objectFromJson(JSONObject jso) {
    // FC creation
    String famName = (String) jso.get("family");
    if (famName.contains("€"))
        famName = famName.split("€")[0];
    Family fam = this.families.getObject(famName);
    FamilyChainsDB fc = new FamilyChainsDB(fam);
    // Roots
    JSONObject jsonRoots = (JSONObject) jso.get("roots");
    for (Object objIdx : jsonRoots.keySet()) {
        String idx = (String) objIdx;
        fc.addRootChain(this.residues.getObject(idx), new Chain((String) jsonRoots.get(objIdx)));
    }
    // Adds
    JSONObject jsonAdds = (JSONObject) jso.get("extensions");
    for (Object objIdx : jsonAdds.keySet()) {
        String idx = (String) objIdx;
        Residue current = this.residues.getObject(idx);
        JSONArray jsonAddsList = (JSONArray) jsonAdds.get(objIdx);
        for (Object obj : jsonAddsList) {
            JSONObject add = (JSONObject) obj;
            Residue from = this.residues.getObject((String) add.get("from"));
            ChainAdd ca = null;
            // TODO : Change it for better usage of genericity.
            switch((String) add.get("type")) {
                case "hydrogen":
                    ca = new HydrogenAdd(from, ((Number) add.get("idx")).intValue(), ((Number) add.get("num")).intValue());
                    break;
                case "extension":
                    ca = new BondAdd(from, new Extension((String) add.get("ext")), ((Number) add.get("idx1")).intValue(), ((Number) add.get("idx2")).intValue());
                    break;
                default:
                    break;
            }
            fc.addAnAdd(current, ca);
        }
    }
    return fc;
}
Also used : Chain(algorithms.isomorphism.chains.Chain) HydrogenAdd(algorithms.isomorphism.chains.HydrogenAdd) JSONArray(org.json.simple.JSONArray) Extension(algorithms.isomorphism.chains.Extension) FamilyChainsDB(algorithms.isomorphism.chains.FamilyChainsDB) JSONObject(org.json.simple.JSONObject) Residue(model.Residue) ChainAdd(algorithms.isomorphism.chains.ChainAdd) Family(model.Family) JSONObject(org.json.simple.JSONObject) BondAdd(algorithms.isomorphism.chains.BondAdd)

Example 22 with Residue

use of model.Residue in project Smiles2Monomers by yoann-dufresne.

the class ResidueJsonLoader method getArrayOfElements.

@SuppressWarnings("unchecked")
@Override
protected JSONArray getArrayOfElements(Family obj) {
    JSONArray array = new JSONArray();
    for (Residue res : obj.getResidues()) {
        JSONObject jso = new JSONObject();
        jso.put("name", res.getName());
        jso.put("id", new Integer(res.getId()));
        jso.put("mono", res.getMonoName());
        List<String> names = obj.getMonoNames();
        Collections.sort(names);
        String familyName = "";
        for (int idx = 0; idx < names.size(); idx++) {
            if (idx > 0)
                familyName += '€';
            familyName += names.get(idx);
        }
        jso.put("family", familyName);
        JSONArray links = new JSONArray();
        String smiles = this.fillLinksJSO(links, res);
        jso.put("smarts", smiles);
        jso.put("links", links);
        JSONArray depandances = new JSONArray();
        for (Link link : obj.getDepandances()) if (link.getTo().intValue() == new Integer(res.getId()).intValue())
            depandances.add(new Integer(link.getFrom()));
        jso.put("depandances", depandances);
        array.add(jso);
    }
    return array;
}
Also used : JSONObject(org.json.simple.JSONObject) Residue(model.Residue) JSONArray(org.json.simple.JSONArray) Link(model.Family.Link)

Example 23 with Residue

use of model.Residue in project Smiles2Monomers by yoann-dufresne.

the class OutputZiper method createSupplementaries.

@SuppressWarnings("unchecked")
private void createSupplementaries(String path, Map<Coverage, ColorsMap> allColors) {
    File sup = new File(path);
    if (sup.exists())
        sup.delete();
    JSONArray array = new JSONArray();
    for (Coverage cov : allColors.keySet()) {
        JSONObject jso = new JSONObject();
        jso.put("id", cov.getId());
        jso.put("ratio", cov.getCoverageRatio());
        ColorsMap cm = allColors.get(cov);
        JSONArray colorsArray = new JSONArray();
        jso.put("colors", colorsArray);
        for (Residue res : cm.keySet()) {
            JSONObject resObj = new JSONObject();
            JSONArray resColors = new JSONArray();
            for (Color col : cm.get(res)) {
                resColors.add(Integer.toHexString(col.getRGB()));
            }
            resObj.put(res.getId(), resColors);
            colorsArray.add(resObj);
        }
        array.add(jso);
    }
    try {
        FileWriter fw = new FileWriter(sup);
        fw.write(array.toJSONString());
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.simple.JSONObject) Residue(model.Residue) Color(java.awt.Color) FileWriter(java.io.FileWriter) JSONArray(org.json.simple.JSONArray) Coverage(algorithms.utils.Coverage) IOException(java.io.IOException) File(java.io.File) ColorsMap(io.imgs.PictureCoverageGenerator.ColorsMap)

Example 24 with Residue

use of model.Residue in project Smiles2Monomers by yoann-dufresne.

the class Coverage method getCorrectMonomers.

public Map<String, Integer> getCorrectMonomers(FamilyDB families) {
    this.calculateCorrectIncorrectNotFound(families);
    Map<String, Integer> corrects = new HashMap<>();
    for (Residue res : this.corrects.keySet()) {
        Family fam = families.getObject(res.getMonoName());
        String name = fam.getShortName();
        int val = corrects.containsKey(name) ? corrects.get(name) : 0;
        corrects.put(name, val + this.corrects.get(res));
    }
    return corrects;
}
Also used : HashMap(java.util.HashMap) Residue(model.Residue) Family(model.Family)

Example 25 with Residue

use of model.Residue in project Smiles2Monomers by yoann-dufresne.

the class ContractedGraph method toMonomerGraph.

/**
 * Transform this contracted graph into a classical monomer graph.
 * @param fams The family database needed to always refer the same monomer of a family.
 * @return The monomer graph
 */
public MonomerGraph toMonomerGraph(FamilyDB fams) {
    // Transformation to a monomer graph
    List<Vertex> verticiesOrder = new ArrayList<>();
    List<Monomer> monos = new ArrayList<>();
    List<Residue> residues = new ArrayList<>();
    for (Object o : this.vertexSet()) {
        Vertex v = (Vertex) o;
        verticiesOrder.add(v);
        Residue res = v.res;
        if (res != null) {
            Family fam = null;
            try {
                fam = fams.getObject(res.getMonoName());
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            monos.add(fam.getPrincipalMonomer());
            residues.add(res);
        } else {
            monos.add(null);
            residues.add(null);
        }
    }
    Monomer[] array = new Monomer[monos.size()];
    for (int i = 0; i < monos.size(); i++) array[i] = monos.get(i);
    Residue[] resArray = new Residue[monos.size()];
    for (int i = 0; i < monos.size(); i++) resArray[i] = residues.get(i);
    MonomerGraph monoGraph = new MonomerGraph(array, resArray);
    for (Object o : this.edgeSet()) {
        LabeledEdge e = (LabeledEdge) o;
        int mono1 = verticiesOrder.indexOf((Vertex) e.getSource());
        int mono2 = verticiesOrder.indexOf((Vertex) e.getTarget());
        monoGraph.createLink(mono1, mono2, e.sourceLabel, e.targetLabel);
    }
    return monoGraph;
}
Also used : ArrayList(java.util.ArrayList) Residue(model.Residue) Family(model.Family) Monomer(model.Monomer)

Aggregations

Residue (model.Residue)35 Family (model.Family)11 ArrayList (java.util.ArrayList)10 IAtom (org.openscience.cdk.interfaces.IAtom)8 JSONArray (org.json.simple.JSONArray)7 JSONObject (org.json.simple.JSONObject)7 IMolecule (org.openscience.cdk.interfaces.IMolecule)7 Monomer (model.Monomer)6 Rule (model.Rule)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Coverage (algorithms.utils.Coverage)4 Match (algorithms.utils.Match)4 FamilyDB (db.FamilyDB)4 File (java.io.File)4 FamilyChainsDB (algorithms.isomorphism.chains.FamilyChainsDB)3 RulesDB (db.RulesDB)3 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)3 Color (java.awt.Color)3 Link (model.Family.Link)3