use of model.graph.ContractedGraph 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.graph.ContractedGraph in project Smiles2Monomers by yoann-dufresne.
the class RemoveByDistance method remove.
@Override
public void remove(Coverage cov, ContractedGraph cg) {
ContractedGraph clone = cg.clone();
this.removeRecur(cov, clone, 0);
}
use of model.graph.ContractedGraph in project Smiles2Monomers by yoann-dufresne.
the class MonomericSpliting method computeCoverage.
/**
* Calculate an object Coverage with all matches from families.
* @param pep Peptide to match
*/
public void computeCoverage(Polymer pep) {
this.coverage = new Coverage(pep);
this.matcher.setChemicalObject(pep);
Isomorphism.setMappingStorage(true);
// Step 1 : Strict Matching
if (verbose) {
System.out.println("+Strict matching");
System.out.println("++Search residues");
}
this.matchAllFamilies(MatchingType.STRONG);
double ratio = this.coverage.getCoverageRatio();
if (ratio < 1.0) {
if (verbose)
System.out.println("++Modulation");
this.coverage = this.modulation.modulate(this.coverage);
}
Coverage save = this.coverage.clone();
// conditions to go to light matching
if (!this.allowLightMatchs || ratio == 1.0) {
Isomorphism.setMappingStorage(false);
return;
}
// TODO : Why if/else ?
if (this.condition == null)
this.condition = new ExtendsNTimes(this.retry);
else
this.condition.init();
this.remover.init();
// Successive matchings
int depth = 0;
while (this.coverage.getCoverageRatio() < 1.0 && this.condition.toContinue(this.coverage)) {
depth++;
// Contract the atomic graph to monomeric graph
ContractedGraph contracted = new ContractedGraph(this.coverage);
// Remove monomers from the current solution to try with other matching strategy
this.remover.remove(this.coverage, contracted);
// Create a masked molecule to only search on free polymer areas
Molecule mol = DeepenMatcher.mask(this.coverage);
this.coverage.setCurrentMaskedMol(mol);
OtherChemicalObject tmp = new OtherChemicalObject(mol);
this.matcher.setChemicalObject(tmp);
if (verbose) {
System.out.println("+Light matching, depth " + depth);
System.out.println("++Search residues");
}
// Compute for all families with ligth matching
this.matchAllFamilies(MatchingType.LIGHT);
// Re-compute coverage
this.coverage.calculateGreedyCoverage();
if (this.coverage.getCoverageRatio() < 1.0) {
if (verbose)
System.out.println("++Modulation");
this.coverage = this.modulation.modulate(this.coverage);
}
if (this.coverage.getCoverageRatio() > save.getCoverageRatio())
save = this.coverage.clone();
this.remover.nextLevel();
}
Isomorphism.setMappingStorage(false);
if (save.getCoverageRatio() > this.coverage.getCoverageRatio())
this.coverage = save;
}
Aggregations