use of model.Residue 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.Residue in project Smiles2Monomers by yoann-dufresne.
the class HTMLColoredCoverageVue method calculateColorsof.
private Map<String, List<Color>> calculateColorsof(Set<String> set) {
Map<String, List<Color>> colors = new HashMap<>();
for (String name : set) {
List<Color> c = colors.containsKey(name) ? colors.get(name) : new ArrayList<Color>();
for (Residue res : this.colors.keySet()) {
if (this.families.areInSameFamily(name, res.getMonoName())) {
c.addAll(this.colors.get(res));
}
}
colors.put(name, c);
}
return colors;
}
use of model.Residue in project Smiles2Monomers by yoann-dufresne.
the class PictureCoverageGenerator method createPNG.
public ColorsMap createPNG(Coverage coverage, File outfile) {
ColorsMap coverageColors = new ColorsMap();
AtomColorer ac = this.cag.getColorer();
IMolecule mol = coverage.getMolecule(false);
List<Color> colors = ColorsGenerator.HsbColorsGeneration(coverage.nbMatchesForCoverage());
int i = 0;
for (Match match : coverage.getUsedMatches()) {
Residue res = match.getResidue();
List<Color> matchesColor = coverageColors.containsKey(res) ? coverageColors.get(res) : new ArrayList<Color>();
for (int idx : match.getAtoms()) {
if (!"H".equals(coverage.getMolecule(true).getAtom(idx).getSymbol()))
ac.setColor(mol.getAtom(idx), colors.get(i));
}
matchesColor.add(colors.get(i));
coverageColors.put(res, matchesColor);
i++;
}
this.createPNG(mol, outfile);
ac.resetColors();
return coverageColors;
}
use of model.Residue in project Smiles2Monomers by yoann-dufresne.
the class CoveragesJsonLoader method getJSONGraph.
@SuppressWarnings("unchecked")
private JSONObject getJSONGraph(Coverage cov) {
ContractedGraph cg = new ContractedGraph(cov);
MonomerGraph mg = cg.toMonomerGraph(families);
JSONObject graph = new JSONObject();
// Monomers
JSONArray monos = new JSONArray();
for (Monomer mono : mg.nodes) if (mono != null)
monos.add(mono.getName());
else
monos.add("?");
graph.put("monos", monos);
// Residues (equivalent to monomers)
JSONArray residues = new JSONArray();
for (Residue res : mg.residues) if (res != null)
residues.add(res.getId());
else
residues.add("?");
graph.put("residues", residues);
// Links
JSONArray links = new JSONArray();
for (MonomerLinks ml : mg.links) {
JSONObject link = new JSONObject();
JSONArray idxs = new JSONArray();
idxs.add(ml.mono1);
idxs.add(ml.mono2);
link.put("idxs", idxs);
JSONArray type = new JSONArray();
type.add(ml.label1);
type.add(ml.label2);
link.put("types", type);
links.add(link);
}
graph.put("links", links);
return graph;
}
use of model.Residue 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();
}
}
Aggregations