use of model.Residue 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.Residue 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.Residue in project Smiles2Monomers by yoann-dufresne.
the class OutputZiper method createSupplementaries.
@SuppressWarnings("unchecked")
private void createSupplementaries(String path, Map<Coverage, ColorsMap> allColors) {
File sup = new File(path);
if (sup.exists())
sup.delete();
JSONArray array = new JSONArray();
for (Coverage cov : allColors.keySet()) {
JSONObject jso = new JSONObject();
jso.put("id", cov.getId());
jso.put("ratio", cov.getCoverageRatio());
ColorsMap cm = allColors.get(cov);
JSONArray colorsArray = new JSONArray();
jso.put("colors", colorsArray);
for (Residue res : cm.keySet()) {
JSONObject resObj = new JSONObject();
JSONArray resColors = new JSONArray();
for (Color col : cm.get(res)) {
resColors.add(Integer.toHexString(col.getRGB()));
}
resObj.put(res.getId(), resColors);
colorsArray.add(resObj);
}
array.add(jso);
}
try {
FileWriter fw = new FileWriter(sup);
fw.write(array.toJSONString());
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of model.Residue 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.Residue 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