Search in sources :

Example 1 with Family

use of model.Family 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 Family

use of model.Family 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)

Example 3 with Family

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

the class Coverage method getIncorrectMonomers.

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

Example 4 with Family

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

the class Coverage method calculateCorrectIncorrectNotFound.

public void calculateCorrectIncorrectNotFound(FamilyDB families) {
    this.corrects = new HashMap<>();
    this.incorrects = new HashMap<>();
    this.notFound = new HashMap<>();
    List<Monomer> realMonos = new ArrayList<>();
    for (Monomer m : this.co.getGraph().nodes) realMonos.add(m);
    for (Match match : this.usedMatches) {
        Residue r = match.getResidue();
        // For each is correct ?
        boolean correct = false;
        Family fam = null;
        try {
            fam = families.getObject(r.getMonoName());
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
        for (Monomer m : fam.getMonomers()) {
            if (realMonos.contains(m)) {
                correct = true;
                realMonos.remove(m);
                break;
            }
        }
        if (correct) {
            int nb = this.corrects.containsKey(r) ? this.corrects.get(r) : 0;
            this.corrects.put(r, nb + 1);
        } else {
            int nb = this.incorrects.containsKey(r) ? this.incorrects.get(r) : 0;
            this.incorrects.put(r, nb + 1);
        }
    }
    for (Monomer m : realMonos) {
        String name = null;
        try {
            Family fam = families.getObject(m.getName());
            name = fam.getShortName();
        } catch (NullPointerException e) {
            name = m.getName();
        }
        int nb = this.notFound.containsKey(name) ? this.notFound.get(name) : 0;
        this.notFound.put(name, nb + 1);
    }
}
Also used : Residue(model.Residue) ArrayList(java.util.ArrayList) Family(model.Family) Monomer(model.Monomer)

Example 5 with Family

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

the class ChainLearning method learn.

/**
 * Learn Sequences from families using the learning base.
 * @param families families to index.
 */
public void learn(FamilyDB families) {
    this.chains.clear();
    this.finalChains.clear();
    this.db = new ChainsDB();
    List<Residue> roots = new ArrayList<>();
    for (Family family : families.getObjects()) {
        for (Residue root : family.getRoots()) {
            roots.add(root);
        }
    }
    // --- Roots ---
    // Init for size 1
    ResidueMappings residueIndex_1 = new ResidueMappings();
    this.initLearn(roots, residueIndex_1);
    // Markovian recursive
    ResidueMappings previous = null;
    ResidueMappings current = residueIndex_1;
    for (int size = 2; size <= this.markovianSize; size++) {
        previous = current;
        current = this.learnMarkovianNext(previous);
    }
    // Greedy recursive
    for (Residue root : current.keySet()) {
        MappedChain bestMarkov = this.getBest(current.get(root));
        MappedChain greedyMB = this.learnGreedy(bestMarkov);
        this.chains.put(greedyMB.getChain().getSmiles(), greedyMB.getChain());
        this.finalChains.put(greedyMB.getChemObject().getId(), greedyMB.getChain());
    }
    // Create index structures all over families.
    for (Family fam : families.getObjects()) {
        FamilyChainsDB fc = new FamilyChainsDB(fam);
        this.db.addObject(fam.getName(), fc);
        this.addAddsToSons(fc, fam);
    }
}
Also used : Residue(model.Residue) ArrayList(java.util.ArrayList) Family(model.Family)

Aggregations

Family (model.Family)14 Residue (model.Residue)11 Monomer (model.Monomer)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 FamilyDB (db.FamilyDB)3 Rule (model.Rule)3 IAtom (org.openscience.cdk.interfaces.IAtom)3 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)2 File (java.io.File)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 BondAdd (algorithms.isomorphism.chains.BondAdd)1 Chain (algorithms.isomorphism.chains.Chain)1 ChainAdd (algorithms.isomorphism.chains.ChainAdd)1 Extension (algorithms.isomorphism.chains.Extension)1 FamilyChainsDB (algorithms.isomorphism.chains.FamilyChainsDB)1 HydrogenAdd (algorithms.isomorphism.chains.HydrogenAdd)1 Coverage (algorithms.utils.Coverage)1 Match (algorithms.utils.Match)1