use of model.Family in project Smiles2Monomers by yoann-dufresne.
the class ResidueJsonLoader method objectFromJson.
@Override
protected Family objectFromJson(JSONObject obj) {
Residue res = new Residue((String) obj.get("mono"), (String) obj.get("smarts"), true);
res.setIdx(((Number) obj.get("id")).intValue());
JSONArray array = (JSONArray) obj.get("links");
for (Object o : array) {
JSONObject jso = (JSONObject) o;
String name = (String) jso.get("name");
Rule rule = null;
try {
rule = this.rules.getObject(name);
} catch (NullPointerException e) {
System.err.println("Unknown link " + name);
}
int idx = ((Number) jso.get("atom")).intValue();
IAtom ia = res.getMolecule().getAtom(idx);
res.addLink(ia, rule);
}
// Family construction
Family fam = new Family();
try {
for (String name : ((String) obj.get("family")).split("€")) {
Monomer m = this.monos.getObject(name);
fam.addMonomer(m);
}
} catch (NullPointerException e) {
System.err.println("Unloaded residue " + res.getMonoName());
}
fam.addResidue(res);
for (Object jso : (JSONArray) obj.get("depandances")) {
int idx = ((Number) jso).intValue();
fam.addDependance(idx, new Integer(res.getId()));
}
return fam;
}
use of model.Family in project Smiles2Monomers by yoann-dufresne.
the class ResiduesInfosGeneration method main.
public static void main(String[] args) {
MonomersDB monoDB = new MonomersJsonLoader().loadFile("data/monomers.json");
RulesDB rules = RulesJsonLoader.loader.loadFile("data/rules.json");
ResidueJsonLoader rjl = new ResidueJsonLoader(rules, monoDB);
FamilyDB families = rjl.loadFile("data/residues.json");
StringBuffer sb = new StringBuffer();
for (Family fam : families.getFamilies()) {
sb.append(fam.getName() + "\n");
sb.append("Norine link : http://bioinfo.lifl.fr/norine/res_amino.jsp?code=" + fam.getMonomers().get(0).getCode() + "\n");
sb.append("Num of residues : " + fam.getResidues().size() + "\n");
sb.append("Root residues (with max links) :" + "\n");
for (Residue res : fam.getRoots()) sb.append("\t" + res.getName() + " : " + res.getAtomicLinks().size() + "\n");
sb.append("\n");
}
File out = new File("results/infosMonos.txt");
try {
FileWriter fw = new FileWriter(out);
fw.write(sb.toString());
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of model.Family 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.Family 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.Family in project Smiles2Monomers by yoann-dufresne.
the class ChainLearning method learn.
/**
* Learn Sequences from families using the learning base.
* @param families families to index.
*/
public void learn(FamilyDB families) {
this.chains.clear();
this.finalChains.clear();
this.db = new ChainsDB();
List<Residue> roots = new ArrayList<>();
for (Family family : families.getObjects()) {
for (Residue root : family.getRoots()) {
roots.add(root);
}
}
// --- Roots ---
// Init for size 1
ResidueMappings residueIndex_1 = new ResidueMappings();
this.initLearn(roots, residueIndex_1);
// Markovian recursive
ResidueMappings previous = null;
ResidueMappings current = residueIndex_1;
for (int size = 2; size <= this.markovianSize; size++) {
previous = current;
current = this.learnMarkovianNext(previous);
}
// Greedy recursive
for (Residue root : current.keySet()) {
MappedChain bestMarkov = this.getBest(current.get(root));
MappedChain greedyMB = this.learnGreedy(bestMarkov);
this.chains.put(greedyMB.getChain().getSmiles(), greedyMB.getChain());
this.finalChains.put(greedyMB.getChemObject().getId(), greedyMB.getChain());
}
// Create index structures all over families.
for (Family fam : families.getObjects()) {
FamilyChainsDB fc = new FamilyChainsDB(fam);
this.db.addObject(fam.getName(), fc);
this.addAddsToSons(fc, fam);
}
}
Aggregations