Search in sources :

Example 11 with Residue

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

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

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

the class Coverage method addMatch.

public void addMatch(Match match) {
    this.matches.add(match);
    Residue res = match.getResidue();
    this.residues.addObject(res.getSmiles(), res);
}
Also used : Residue(model.Residue)

Example 14 with Residue

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

the class ResidueCreator method getResiduesWithRule.

/*
	 * Search Residues for one monomer and one rule.
	 */
private Set<Residue> getResiduesWithRule(Residue res, Rule rule) {
    Set<Residue> residues = new HashSet<>();
    IMolecule ruleMol = null;
    try {
        ruleMol = SmilesConverter.conv.transform(rule.getFormula(), false, false, true);
    } catch (InvalidSmilesException e) {
        System.err.println("Impossible to parse " + rule.getName() + " rule");
        return residues;
    }
    boolean status = false;
    try {
        status = UniversalIsomorphismTester.isSubgraph(res.getMolecule(), ruleMol);
    } catch (CDKException e) {
        e.printStackTrace();
    }
    // If rule is found
    if (status) {
        List<List<RMap>> matches = null;
        try {
            matches = UniversalIsomorphismTester.getSubgraphAtomsMaps(res.getMolecule(), ruleMol);
        } catch (CDKException e) {
            e.printStackTrace();
        }
        if (!"".equals(rule.getExclusion()))
            for (String exclusion : rule.getExclusion()) this.removeExclusions(matches, exclusion, res.getMolecule());
        for (List<RMap> match : matches) {
            Set<Residue> residuesByMatch = this.createResidue(match, rule, res);
            residues.addAll(residuesByMatch);
        }
    }
    return residues;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) CDKException(org.openscience.cdk.exception.CDKException) ArrayList(java.util.ArrayList) List(java.util.List) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) RMap(org.openscience.cdk.isomorphism.mcss.RMap) HashSet(java.util.HashSet)

Example 15 with Residue

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

the class ResidueCreator method residuesFromMonomers.

/*
	 * Create residues from a monomer according to the rules database.
	 */
private Set<Residue> residuesFromMonomers(Family family) {
    Monomer mono = family.getMonomers().get(0);
    Set<Residue> residues = new HashSet<>();
    RulesDB rules = new RulesDB();
    rules.addDB(this.dbAlone);
    // List of residues in witch we search other residues.
    Set<Residue> searchResidues = new HashSet<>();
    IMolecule m = null;
    try {
        m = mono.getMolecule().clone();
        AtomContainerManipulator.convertImplicitToExplicitHydrogens(m);
    } catch (CloneNotSupportedException e1) {
        e1.printStackTrace();
    }
    searchResidues.add(new Residue(mono.getCode(), this.sg.createSMILES(m), true));
    boolean firstTime = true;
    while (searchResidues.size() != 0) {
        Set<Residue> nextLevelResidues = new HashSet<>();
        for (Residue res : searchResidues) {
            res.setExplicitHydrogens(true);
            Set<Residue> newResidues = new HashSet<>();
            for (Rule rule : rules.getObjects()) {
                Set<Residue> ruleResidues = this.getResiduesWithRule(res, rule);
                newResidues.addAll(ruleResidues);
                for (Residue r : ruleResidues) nextLevelResidues.add(r);
            }
            for (Residue newRes : newResidues) {
                family.addResidue(newRes);
                if (family.containsMonomer(res.getMonoName()) && res.getAtomicLinks().size() > 0)
                    family.addDependance(newRes, res);
            }
            res.setExplicitHydrogens(false);
        }
        searchResidues = nextLevelResidues;
        residues.addAll(searchResidues);
        if (firstTime) {
            firstTime = false;
            rules.addDB(this.dbNotAlone);
        }
    }
    if (residues.size() == 0) {
        String smiles = this.sg.createSMILES(m);
        Residue res = Residue.constructResidue(mono.getName(), smiles);
        family.addResidue(res);
        residues.add(res);
    }
    if (this.verbose) {
        System.out.println("Nb residues of " + mono.getCode() + " : " + residues.size());
        for (Residue res : residues) System.out.println("  " + res.getSmiles());
        System.out.println();
    }
    return residues;
}
Also used : RulesDB(db.RulesDB) IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) Rule(model.Rule) Monomer(model.Monomer) HashSet(java.util.HashSet)

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