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