use of algorithms.utils.Match 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 algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class CoveragesJsonLoader method getJSONMatches.
@SuppressWarnings("unchecked")
private JSONObject getJSONMatches(Coverage cov) {
JSONObject graph = new JSONObject();
JSONArray atoms = new JSONArray();
graph.put("atoms", atoms);
JSONArray bonds = new JSONArray();
graph.put("bonds", bonds);
Set<IBond> usedBonds = new HashSet<IBond>();
int matchId = 0;
for (Match match : cov.getUsedMatches()) {
// Atoms
for (int a : match.getAtoms()) {
JSONObject atom = new JSONObject();
// CDK informations
atom.put("cdk_idx", a);
// Atom informations
IAtom ia = cov.getChemicalObject().getMolecule().getAtom(a);
atom.put("name", ia.getSymbol());
atom.put("hydrogens", match.getHydrogensFrom(a));
// Residue informations
atom.put("res", match.getResidue().getId());
atom.put("matchIdx", matchId);
atoms.add(atom);
}
// Bonds
for (int b : match.getBonds()) {
IBond ib = cov.getChemicalObject().getMolecule().getBond(b);
usedBonds.add(ib);
JSONObject bond = new JSONObject();
// CDK informations
bond.put("cdk_idx", b);
// atoms linked
JSONArray linkedAtoms = new JSONArray();
for (IAtom a : ib.atoms()) {
linkedAtoms.add(cov.getChemicalObject().getMolecule().getAtomNumber(a));
}
bond.put("arity", ib.getOrder().numeric());
bond.put("atoms", linkedAtoms);
bond.put("res", match.getResidue().getId());
bonds.add(bond);
}
matchId++;
}
IMolecule mol = cov.getChemicalObject().getMolecule();
for (IBond ib : mol.bonds()) {
if (!usedBonds.contains(ib)) {
JSONObject bond = new JSONObject();
// CDK informations
bond.put("cdk_idx", mol.getBondNumber(ib));
// atoms linked
JSONArray linkedAtoms = new JSONArray();
for (IAtom a : ib.atoms()) {
linkedAtoms.add(mol.getAtomNumber(a));
}
bond.put("arity", ib.getOrder().numeric());
bond.put("atoms", linkedAtoms);
bonds.add(bond);
}
}
return graph;
}
use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class ContractedGraph method initCoveredVerticies.
// Create nodes with covered atoms contracted
private void initCoveredVerticies(Coverage cov) {
HashSet<Match> matches = cov.getUsedMatches();
for (Match match : matches) {
Vertex v = new Vertex();
v.id = match.getId();
v.res = match.getResidue();
v.vertices.addAll(match.getAtoms());
for (int id : match.getAtoms()) {
this.verticiesOfatoms.put(id, v);
if (match.getExtLinks().containsKey(id)) {
v.kind.put(id, match.getExtLinks().get(id));
}
}
this.addVertex(v);
}
}
use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class Modulation method getMatchOnUncoveredAtoms.
/**
* Get ordered matches from uncovered parts.
* The order depends on number on covering atoms and size of the matches
* @param cov
* @param contract
* @param banned
* @return
*/
private List<Match> getMatchOnUncoveredAtoms(Coverage cov, Set<Match> banned, Set<Integer> unmovable) {
List<Match> matches = new ArrayList<>();
Set<Integer> uncovered = new HashSet<>();
for (int atomIdx : this.usedIndex.keySet()) {
if (this.usedIndex.get(atomIdx).size() == 0)
uncovered.add(atomIdx);
}
Map<Match, Integer> uncoveredByMatch = new HashMap<>();
for (int idx : uncovered) {
for (Match match : this.index.get(idx)) {
if (banned.contains(match) || !Collections.disjoint(match.getAtoms(), unmovable))
continue;
int val = uncoveredByMatch.containsKey(match) ? uncoveredByMatch.get(match) : 0;
uncoveredByMatch.put(match, val + 1);
if (val == 0)
matches.add(match);
}
}
Collections.sort(matches, new ModulationComparator(uncoveredByMatch));
return matches;
}
use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class Modulation method indexCoverage.
/**
* Read a coverage and extract for each position all the possible matchings
* @param cov
* @return
*/
private void indexCoverage(Coverage cov) {
this.index = new HashMap<>();
this.usedIndex = new HashMap<>();
IMolecule mol = cov.getChemicalObject().getMolecule();
for (IAtom a : mol.atoms()) {
this.index.put(mol.getAtomNumber(a), new HashSet<Match>());
this.usedIndex.put(mol.getAtomNumber(a), new HashSet<Match>());
}
// Global index
for (Match match : cov.getMatches()) for (int i : match.getAtoms()) this.index.get(i).add(match);
// Used index
for (Match match : cov.getUsedMatches()) for (int i : match.getAtoms()) this.usedIndex.get(i).add(match);
}
Aggregations