use of model.Family in project Smiles2Monomers by yoann-dufresne.
the class FamilyDB method init.
public void init(MonomersDB monoDB) {
Map<String, List<Monomer>> clusters = new HashMap<>();
for (Monomer mono : monoDB.getObjects()) {
String smiles = null;
try {
smiles = SmilesConverter.conv.toCanonicalSmiles(mono.getSmiles());
} catch (InvalidSmilesException e) {
System.err.println("Impossible to parse " + mono.getName() + " id:" + mono.getId());
System.err.println(mono.getSmiles());
continue;
}
List<Monomer> cluster = clusters.containsKey(smiles) ? clusters.get(smiles) : new ArrayList<Monomer>();
cluster.add(mono);
clusters.put(smiles, cluster);
}
for (String smiles : clusters.keySet()) {
Family family = new Family();
for (Monomer mono : clusters.get(smiles)) {
family.addMonomer(mono);
this.addObject(mono.getCode(), family);
}
}
}
use of model.Family in project Smiles2Monomers by yoann-dufresne.
the class ResidueCreatorTests method linksLoadingTest.
@Test
public void linksLoadingTest() {
ResidueJsonLoader rjl = new ResidueJsonLoader(this.rules, this.monos);
rjl.saveFile(this.families, "tmp.json");
Residue.resetResidues();
FamilyDB loaded = rjl.loadFile("tmp.json");
new File("tmp.json").delete();
Family famTyr = null;
try {
famTyr = loaded.getObject("Tyr");
} catch (NullPointerException e) {
e.printStackTrace();
}
Residue tyrN = null;
for (Residue res : famTyr.getResidues()) if ("Tyr_pepN".equals(res.getName())) {
tyrN = res;
break;
}
Entry<IAtom, Rule> entry = tyrN.getAtomicLinks().entrySet().iterator().next();
IAtom a = entry.getKey();
Assert.assertEquals(a.getSymbol(), "N");
}
use of model.Family in project Smiles2Monomers by yoann-dufresne.
the class FamilyChainIO method objectFromJson.
@Override
protected FamilyChainsDB objectFromJson(JSONObject jso) {
// FC creation
String famName = (String) jso.get("family");
if (famName.contains("€"))
famName = famName.split("€")[0];
Family fam = this.families.getObject(famName);
FamilyChainsDB fc = new FamilyChainsDB(fam);
// Roots
JSONObject jsonRoots = (JSONObject) jso.get("roots");
for (Object objIdx : jsonRoots.keySet()) {
String idx = (String) objIdx;
fc.addRootChain(this.residues.getObject(idx), new Chain((String) jsonRoots.get(objIdx)));
}
// Adds
JSONObject jsonAdds = (JSONObject) jso.get("extensions");
for (Object objIdx : jsonAdds.keySet()) {
String idx = (String) objIdx;
Residue current = this.residues.getObject(idx);
JSONArray jsonAddsList = (JSONArray) jsonAdds.get(objIdx);
for (Object obj : jsonAddsList) {
JSONObject add = (JSONObject) obj;
Residue from = this.residues.getObject((String) add.get("from"));
ChainAdd ca = null;
// TODO : Change it for better usage of genericity.
switch((String) add.get("type")) {
case "hydrogen":
ca = new HydrogenAdd(from, ((Number) add.get("idx")).intValue(), ((Number) add.get("num")).intValue());
break;
case "extension":
ca = new BondAdd(from, new Extension((String) add.get("ext")), ((Number) add.get("idx1")).intValue(), ((Number) add.get("idx2")).intValue());
break;
default:
break;
}
fc.addAnAdd(current, ca);
}
}
return fc;
}
use of model.Family in project Smiles2Monomers by yoann-dufresne.
the class Coverage method getCorrectMonomers.
public Map<String, Integer> getCorrectMonomers(FamilyDB families) {
this.calculateCorrectIncorrectNotFound(families);
Map<String, Integer> corrects = new HashMap<>();
for (Residue res : this.corrects.keySet()) {
Family fam = families.getObject(res.getMonoName());
String name = fam.getShortName();
int val = corrects.containsKey(name) ? corrects.get(name) : 0;
corrects.put(name, val + this.corrects.get(res));
}
return corrects;
}
use of model.Family in project Smiles2Monomers by yoann-dufresne.
the class ContractedGraph method toMonomerGraph.
/**
* Transform this contracted graph into a classical monomer graph.
* @param fams The family database needed to always refer the same monomer of a family.
* @return The monomer graph
*/
public MonomerGraph toMonomerGraph(FamilyDB fams) {
// Transformation to a monomer graph
List<Vertex> verticiesOrder = new ArrayList<>();
List<Monomer> monos = new ArrayList<>();
List<Residue> residues = new ArrayList<>();
for (Object o : this.vertexSet()) {
Vertex v = (Vertex) o;
verticiesOrder.add(v);
Residue res = v.res;
if (res != null) {
Family fam = null;
try {
fam = fams.getObject(res.getMonoName());
} catch (NullPointerException e) {
e.printStackTrace();
}
monos.add(fam.getPrincipalMonomer());
residues.add(res);
} else {
monos.add(null);
residues.add(null);
}
}
Monomer[] array = new Monomer[monos.size()];
for (int i = 0; i < monos.size(); i++) array[i] = monos.get(i);
Residue[] resArray = new Residue[monos.size()];
for (int i = 0; i < monos.size(); i++) resArray[i] = residues.get(i);
MonomerGraph monoGraph = new MonomerGraph(array, resArray);
for (Object o : this.edgeSet()) {
LabeledEdge e = (LabeledEdge) o;
int mono1 = verticiesOrder.indexOf((Vertex) e.getSource());
int mono2 = verticiesOrder.indexOf((Vertex) e.getTarget());
monoGraph.createLink(mono1, mono2, e.sourceLabel, e.targetLabel);
}
return monoGraph;
}
Aggregations