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;
}
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);
}
}
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;
}
Aggregations