Search in sources :

Example 1 with Link

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

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

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

the class IsomorphismFamilyMatcher method matchFamilly.

@Override
public Coverage matchFamilly(Family family) {
    // Initialization
    Coverage cov = new Coverage(co);
    IMolecule mol = co.getMolecule();
    Set<Residue> markSet = new HashSet<>();
    Stack<Residue> searchSet = new Stack<>();
    searchSet.addAll(family.getRoots());
    // For all the nodes in the search group.
    while (!searchSet.isEmpty()) {
        Residue currentRes = searchSet.pop();
        // Search the current residue in mol.
        try {
            this.sqt.setSmarts(currentRes.getSmiles());
        } catch (CDKException e) {
            e.printStackTrace();
        }
        boolean isMatching = false;
        try {
            long time = System.currentTimeMillis();
            isMatching = this.sqt.matches(mol);
            if (verbose)
                System.out.println("    Search for " + currentRes.getName() + " in " + (System.currentTimeMillis() - time));
        } catch (CDKException e) {
            e.printStackTrace();
        }
        // If there is at least one occurrence.
        if (isMatching) {
            // Add matches to the coverage
            List<Match> matches = new ArrayList<>();
            for (List<Integer> lMatch : sqt.getMatchingAtoms()) {
                Match match = new Match(currentRes);
                for (int i : lMatch) match.addAtom(i);
                matches.add(match);
            }
            // Change to compare.
            cov.addListMatches(currentRes, matches);
            // Mark current residue to possibly add children.
            markSet.add(currentRes);
            // Add children with all parents marked
            Set<Residue> children = family.getChildrenOf(currentRes);
            for (Residue child : children) {
                boolean canBeAdded = true;
                for (Link dependance : family.getDepandances()) if (dependance.getTo().equals(child))
                    if (!markSet.contains(dependance.getFrom())) {
                        canBeAdded = false;
                        break;
                    }
                if (canBeAdded)
                    searchSet.add(child);
            }
        }
    }
    return cov;
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) ArrayList(java.util.ArrayList) Coverage(algorithms.utils.Coverage) Stack(java.util.Stack) Match(algorithms.utils.Match) IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) Link(model.Family.Link) HashSet(java.util.HashSet)

Aggregations

Link (model.Family.Link)3 Residue (model.Residue)3 Coverage (algorithms.utils.Coverage)1 Match (algorithms.utils.Match)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1 Family (model.Family)1 Monomer (model.Monomer)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 CDKException (org.openscience.cdk.exception.CDKException)1 IMolecule (org.openscience.cdk.interfaces.IMolecule)1