Search in sources :

Example 26 with Residue

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

the class CoveragesJsonLoader method objectFromJson.

@Override
protected Coverage objectFromJson(JSONObject obj) {
    // TODO : Create new parser with the files created by the new output functions
    System.err.println("From classe '" + CoveragesJsonLoader.class.getName() + "' method 'objectFromJson':");
    System.err.println("This is deprecated ! You will have some problems with recent json files !");
    ChemicalObject co = null;
    try {
        co = this.db.getObject("" + ((Number) obj.get("peptide")).intValue());
    } catch (NullPointerException e) {
        System.err.println(e.getMessage());
        System.err.println("Maybe coverage json and molecule json don't match");
        System.exit(2);
    }
    Coverage cov = new Coverage(co);
    JSONArray array = (JSONArray) obj.get("matches");
    for (Object o : array) {
        JSONObject jso = (JSONObject) o;
        Residue res = null;
        try {
            res = this.residues.getObject("" + ((Number) jso.get("residue")).intValue());
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
        JSONObject jMatch = (JSONObject) jso.get("match");
        Match match = new Match(res);
        JSONArray atoms = (JSONArray) jMatch.get("atoms");
        for (Object atObj : atoms) {
            JSONObject atom = (JSONObject) atObj;
            int idx = ((Number) atom.get("a")).intValue();
            match.addAtom(idx);
            match.addHydrogens(idx, ((Number) atom.get("h")).intValue());
        }
        JSONArray bonds = (JSONArray) jMatch.get("bonds");
        for (Object boObj : bonds) {
            int bond = ((Number) boObj).intValue();
            match.addBond(bond);
        }
        cov.addMatch(match);
    }
    cov.calculateGreedyCoverage();
    return cov;
}
Also used : JSONObject(org.json.simple.JSONObject) Residue(model.Residue) JSONArray(org.json.simple.JSONArray) ChemicalObject(model.ChemicalObject) Coverage(algorithms.utils.Coverage) JSONObject(org.json.simple.JSONObject) ChemicalObject(model.ChemicalObject) Match(algorithms.utils.Match)

Example 27 with Residue

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

the class FamilyDB method addObject.

@Override
public void addObject(String id, Family f) {
    Family prev = null;
    for (Monomer m : f.getMonomers()) if (this.database.containsKey(m.getId())) {
        prev = this.database.get(m.getId());
        break;
    }
    if (prev == null) {
        for (Monomer m : f.getMonomers()) {
            super.addObject(m.getId(), f);
            this.uniqFamilies.add(f);
        }
    } else {
        for (Monomer m : f.getMonomers()) {
            prev.addMonomer(m);
            this.database.put(m.getId(), prev);
        }
        for (Residue res : f.getResidues()) prev.addResidue(res);
        for (Link l : f.getDepandances()) prev.addDependance(l);
    }
}
Also used : Residue(model.Residue) Family(model.Family) Monomer(model.Monomer) Link(model.Family.Link)

Example 28 with Residue

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

the class ResiduesDB method getAlphabeticResidues.

public List<Residue> getAlphabeticResidues() {
    List<Residue> residues = new ArrayList<>(this.database.values());
    Collections.sort(residues);
    this.databaseByIdx.clear();
    for (Residue res : residues) {
        // res.setIdx(residues.indexOf(res)+1);
        this.databaseByIdx.put(residues.indexOf(res) + 1, res);
    }
    return residues;
}
Also used : Residue(model.Residue) ArrayList(java.util.ArrayList)

Example 29 with Residue

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

the class FamilyChainsDB method toJSON.

@SuppressWarnings("unchecked")
public JSONObject toJSON() {
    JSONObject jso = new JSONObject();
    // Id
    jso.put("family", this.family.getJsonName());
    // Roots
    JSONObject roots = new JSONObject();
    for (Residue res : this.rootChains.keySet()) {
        roots.put(res.getId(), this.rootChains.get(res).getSerial());
    }
    jso.put("roots", roots);
    // Extensions
    JSONObject exts = new JSONObject();
    for (Residue res : this.adds.keySet()) {
        JSONArray adds = new JSONArray();
        for (ChainAdd add : this.adds.get(res)) {
            adds.add(add.toJSON());
        }
        exts.put(res.getId(), adds);
    }
    jso.put("extensions", exts);
    return jso;
}
Also used : JSONObject(org.json.simple.JSONObject) Residue(model.Residue) JSONArray(org.json.simple.JSONArray)

Example 30 with Residue

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

the class ChainsFamilyMatching method addToCoverage.

private void addToCoverage(Family family, MappedChain mc, Residue res) {
    Match match = new Match(res);
    match.addAtoms(mc.getAtomsMapping());
    match.addBonds(mc.getBondsMapping());
    match.addHydrogens(mc.getHydrogensMapping());
    for (int idx = 0; idx < mc.getMatchings().size(); idx++) {
        match.addQuality(mc.getBondsMapping().get(idx), mc.getMatchings().get(idx));
    }
    // Compute external bonds by aligning chain on residue
    // 1- Retrieve the chain on root residue
    int current = 200;
    List<MappedChain> onResidue = null;
    Residue rootMol = null;
    for (Residue root : family.getRoots()) {
        List<MappedChain> mcs = Isomorphism.searchAChain(mc.getChain(), root, MatchingType.EXACT);
        if (mcs.size() > 0 && current > mcs.size()) {
            current = mcs.size();
            onResidue = mcs;
            rootMol = root;
        }
    }
    // 2- Look for atoms of interest
    MappedChain resMapping = onResidue.get(0);
    for (IAtom ia : rootMol.getAtomicLinks().keySet()) {
        Rule r = rootMol.getAtomicLinks().get(ia);
        int resMolIdx = rootMol.getMolecule().getAtomNumber(ia);
        int chainIdx = resMapping.getAtomsMapping().indexOf(resMolIdx);
        match.addExtLink(mc.getAtomsMapping().get(chainIdx), r);
    }
    // Add the match
    if (!this.coverage.getMatches().contains(match))
        this.coverage.addMatch(match);
}
Also used : MappedChain(algorithms.isomorphism.chains.MappedChain) Residue(model.Residue) Rule(model.Rule) IAtom(org.openscience.cdk.interfaces.IAtom) Match(algorithms.utils.Match)

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