Search in sources :

Example 1 with Residue

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

the class ResidueJsonLoader method objectFromJson.

@Override
protected Family objectFromJson(JSONObject obj) {
    Residue res = new Residue((String) obj.get("mono"), (String) obj.get("smarts"), true);
    res.setIdx(((Number) obj.get("id")).intValue());
    JSONArray array = (JSONArray) obj.get("links");
    for (Object o : array) {
        JSONObject jso = (JSONObject) o;
        String name = (String) jso.get("name");
        Rule rule = null;
        try {
            rule = this.rules.getObject(name);
        } catch (NullPointerException e) {
            System.err.println("Unknown link " + name);
        }
        int idx = ((Number) jso.get("atom")).intValue();
        IAtom ia = res.getMolecule().getAtom(idx);
        res.addLink(ia, rule);
    }
    // Family construction
    Family fam = new Family();
    try {
        for (String name : ((String) obj.get("family")).split("€")) {
            Monomer m = this.monos.getObject(name);
            fam.addMonomer(m);
        }
    } catch (NullPointerException e) {
        System.err.println("Unloaded residue " + res.getMonoName());
    }
    fam.addResidue(res);
    for (Object jso : (JSONArray) obj.get("depandances")) {
        int idx = ((Number) jso).intValue();
        fam.addDependance(idx, new Integer(res.getId()));
    }
    return fam;
}
Also used : JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) Residue(model.Residue) Family(model.Family) JSONObject(org.json.simple.JSONObject) Rule(model.Rule) Monomer(model.Monomer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with Residue

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

the class HTMLColoredCoverageVue method calculateColorsof.

private Map<String, List<Color>> calculateColorsof(Set<String> set) {
    Map<String, List<Color>> colors = new HashMap<>();
    for (String name : set) {
        List<Color> c = colors.containsKey(name) ? colors.get(name) : new ArrayList<Color>();
        for (Residue res : this.colors.keySet()) {
            if (this.families.areInSameFamily(name, res.getMonoName())) {
                c.addAll(this.colors.get(res));
            }
        }
        colors.put(name, c);
    }
    return colors;
}
Also used : HashMap(java.util.HashMap) Residue(model.Residue) Color(java.awt.Color) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Residue

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

the class PictureCoverageGenerator method createPNG.

public ColorsMap createPNG(Coverage coverage, File outfile) {
    ColorsMap coverageColors = new ColorsMap();
    AtomColorer ac = this.cag.getColorer();
    IMolecule mol = coverage.getMolecule(false);
    List<Color> colors = ColorsGenerator.HsbColorsGeneration(coverage.nbMatchesForCoverage());
    int i = 0;
    for (Match match : coverage.getUsedMatches()) {
        Residue res = match.getResidue();
        List<Color> matchesColor = coverageColors.containsKey(res) ? coverageColors.get(res) : new ArrayList<Color>();
        for (int idx : match.getAtoms()) {
            if (!"H".equals(coverage.getMolecule(true).getAtom(idx).getSymbol()))
                ac.setColor(mol.getAtom(idx), colors.get(i));
        }
        matchesColor.add(colors.get(i));
        coverageColors.put(res, matchesColor);
        i++;
    }
    this.createPNG(mol, outfile);
    ac.resetColors();
    return coverageColors;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) Color(java.awt.Color) AtomColorer(io.imgs.coloration.ColoredAtomGenerator.AtomColorer) Match(algorithms.utils.Match)

Example 4 with Residue

use of model.Residue 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 5 with Residue

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

the class ResiduesInfosGeneration method main.

public static void main(String[] args) {
    MonomersDB monoDB = new MonomersJsonLoader().loadFile("data/monomers.json");
    RulesDB rules = RulesJsonLoader.loader.loadFile("data/rules.json");
    ResidueJsonLoader rjl = new ResidueJsonLoader(rules, monoDB);
    FamilyDB families = rjl.loadFile("data/residues.json");
    StringBuffer sb = new StringBuffer();
    for (Family fam : families.getFamilies()) {
        sb.append(fam.getName() + "\n");
        sb.append("Norine link : http://bioinfo.lifl.fr/norine/res_amino.jsp?code=" + fam.getMonomers().get(0).getCode() + "\n");
        sb.append("Num of residues : " + fam.getResidues().size() + "\n");
        sb.append("Root residues (with max links) :" + "\n");
        for (Residue res : fam.getRoots()) sb.append("\t" + res.getName() + " : " + res.getAtomicLinks().size() + "\n");
        sb.append("\n");
    }
    File out = new File("results/infosMonos.txt");
    try {
        FileWriter fw = new FileWriter(out);
        fw.write(sb.toString());
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : RulesDB(db.RulesDB) MonomersJsonLoader(io.loaders.json.MonomersJsonLoader) Residue(model.Residue) MonomersDB(db.MonomersDB) FileWriter(java.io.FileWriter) Family(model.Family) FamilyDB(db.FamilyDB) IOException(java.io.IOException) ResidueJsonLoader(io.loaders.json.ResidueJsonLoader) File(java.io.File)

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