use of model.Polymer in project Smiles2Monomers by yoann-dufresne.
the class PolymersJsonLoader method objectFromJson.
@SuppressWarnings("unchecked")
@Override
protected Polymer objectFromJson(JSONObject obj) {
if ("".equals((String) obj.get("smiles"))) {
System.err.println("No smiles for " + ((String) obj.get("name")));
return null;
} else if (((String) obj.get("smiles")).contains(".")) {
System.err.println("The smiles for " + ((String) obj.get("name")) + " contains character '.'");
System.err.println("The '.' means that the smiles is composed of more than one molecule.");
System.err.println("Please split the smiles in two distinct smiles.");
return null;
}
// --- Parse the graph ---
JSONArray verticies;
JSONArray edges;
if (obj.containsKey("graph")) {
JSONObject graph = (JSONObject) obj.get("graph");
// Parse the s2m graph format
verticies = (JSONArray) graph.get("V");
edges = (JSONArray) graph.get("E");
} else if (obj.containsKey("structure")) {
verticies = new JSONArray();
edges = new JSONArray();
// Parse the Norine graph format
String text = (String) ((JSONObject) obj.get("structure")).get("graph");
String[] split = text.split("@");
// The verticies
verticies = new JSONArray();
for (String val : split[0].split(",")) verticies.add(val);
// The edges
edges = new JSONArray();
for (int idx = 1; idx < split.length; idx++) {
String[] links = split[idx].split(",");
for (String val : links) {
int link_to = new Integer(val);
if (idx - 1 < link_to) {
JSONArray edge = new JSONArray();
edge.add(idx - 1);
edge.add(link_to);
edges.add(edge);
}
}
}
} else {
verticies = new JSONArray();
edges = new JSONArray();
}
// --- Parse the monomer list ---
Monomer[] monomers = new Monomer[verticies.size()];
for (int i = 0; i < monomers.length; i++) {
String name = (String) verticies.get(i);
try {
monomers[i] = this.monos.contains(name) ? this.monos.getObject(name) : new Monomer(name, "", "");
} catch (NullPointerException e) {
e.printStackTrace();
}
}
// Create the graph in memory
MonomerGraph g = new MonomerGraph(monomers);
for (Object o : edges) {
JSONArray link = (JSONArray) o;
g.createLink(((Number) link.get(0)).intValue(), ((Number) link.get(1)).intValue());
}
int id = 0;
if (obj.get("id") instanceof String) {
String sid = (String) obj.get("id");
id = sid.startsWith("NOR") ? new Integer(sid.substring(3)) : sid.hashCode();
} else
id = ((Number) obj.get("id")).intValue();
Polymer pep = new Polymer(id, (String) obj.get("name"), (String) obj.get("smiles"), monomers);
pep.setGraph(g);
return pep;
}
use of model.Polymer in project Smiles2Monomers by yoann-dufresne.
the class ContractedGraphTests method setUp.
@Before
public void setUp() throws Exception {
MonomersDB monos = new MonomersJsonLoader().loadFile("data_tests/monos.json");
PolymersDB peps = new PolymersJsonLoader(monos).loadFile("data_tests/peps.json");
RulesDB rules = RulesJsonLoader.loader.loadFile("data_tests/rules.json");
ResidueCreator rc = new ResidueCreator(rules);
FamilyDB families = rc.createResidues(monos);
ChainLearning cl = new ChainLearning(peps);
cl.setMarkovianSize(3);
cl.learn(families);
ChainsDB chains = cl.getDb();
MonomericSpliting ms = new MonomericSpliting(families, chains, 2, 2, 3);
Polymer pol = peps.getObject("633");
ms.computeCoverage(pol);
this.coverage = ms.getCoverage();
this.coverage.calculateGreedyCoverage();
this.contractedGraph = new ContractedGraph(coverage);
}
Aggregations