use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class DeepenMatcher method transform.
/**
* Transformation of mappings from tmp molecule to entire molecule.
*/
public static Match transform(Match match, IMolecule sub, IMolecule entire) {
Match transformed = new Match(match.getResidue());
// Atoms & Hydrogens
for (int idx : match.getAtoms()) {
IAtom a = sub.getAtom(idx);
int realIdx = entire.getAtomNumber(a);
transformed.addAtom(realIdx);
transformed.addHydrogens(realIdx, match.getHydrogensFrom(idx));
}
// Bonds
for (int idx : match.getBonds()) {
IBond b = sub.getBond(idx);
transformed.addBond(entire.getBondNumber(b));
}
return transformed;
}
use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class CoveragesJsonLoader method objectFromJson.
@Override
protected Coverage objectFromJson(JSONObject obj) {
// TODO : Create new parser with the files created by the new output functions
System.err.println("From classe '" + CoveragesJsonLoader.class.getName() + "' method 'objectFromJson':");
System.err.println("This is deprecated ! You will have some problems with recent json files !");
ChemicalObject co = null;
try {
co = this.db.getObject("" + ((Number) obj.get("peptide")).intValue());
} catch (NullPointerException e) {
System.err.println(e.getMessage());
System.err.println("Maybe coverage json and molecule json don't match");
System.exit(2);
}
Coverage cov = new Coverage(co);
JSONArray array = (JSONArray) obj.get("matches");
for (Object o : array) {
JSONObject jso = (JSONObject) o;
Residue res = null;
try {
res = this.residues.getObject("" + ((Number) jso.get("residue")).intValue());
} catch (NullPointerException e) {
e.printStackTrace();
}
JSONObject jMatch = (JSONObject) jso.get("match");
Match match = new Match(res);
JSONArray atoms = (JSONArray) jMatch.get("atoms");
for (Object atObj : atoms) {
JSONObject atom = (JSONObject) atObj;
int idx = ((Number) atom.get("a")).intValue();
match.addAtom(idx);
match.addHydrogens(idx, ((Number) atom.get("h")).intValue());
}
JSONArray bonds = (JSONArray) jMatch.get("bonds");
for (Object boObj : bonds) {
int bond = ((Number) boObj).intValue();
match.addBond(bond);
}
cov.addMatch(match);
}
cov.calculateGreedyCoverage();
return cov;
}
use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class DeepenMatcher method calculateCoveredAtoms.
/**
* Create an ordered list of covered atoms indexes
*/
public static List<Integer> calculateCoveredAtoms(Coverage coverage) {
List<Integer> covered = new ArrayList<>();
for (Match match : coverage.getUsedMatches()) covered.addAll(match.getAtoms());
Collections.sort(covered);
return covered;
}
use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class Modulation method recursiveModulation.
private boolean recursiveModulation(Coverage cov, HashSet<Match> banned, HashSet<Integer> unmovable, int depth) {
if (depth == 0 || (System.currentTimeMillis() - this.startTime) / 1000 > maxTime)
return false;
List<Match> matchsOnUncoveredAtoms = this.getMatchOnUncoveredAtoms(cov, banned, unmovable);
int idx = 0;
for (Match match : matchsOnUncoveredAtoms) {
if (idx++ >= 50)
break;
Set<Match> removed = null;
try {
removed = this.removeNReplaceMatches(match, cov, banned, unmovable);
} catch (ImpossibleToReplace e) {
continue;
}
if (cov.getCoverageRatio() == 1.0) {
this.best = cov;
return true;
}
if (this.recursiveModulation(cov, banned, unmovable, depth - 1))
return true;
else {
if (best.getCoverageRatio() < cov.getCoverageRatio())
this.best = cov.clone();
for (int atomIdx : match.getAtoms()) unmovable.remove(atomIdx);
banned.removeAll(removed);
this.rollBack(cov, match, removed);
}
}
return false;
}
use of algorithms.utils.Match in project Smiles2Monomers by yoann-dufresne.
the class Modulation method removeNReplaceMatches.
/**
* Remove matching incompatible with match and place it
* @param match
* @param cov
* @param banned
* @param unmovable
* @return
*/
private Set<Match> removeNReplaceMatches(Match match, Coverage cov, HashSet<Match> banned, HashSet<Integer> unmovable) throws ImpossibleToReplace {
HashSet<Match> removed = new HashSet<>();
// banned.add(match);
unmovable.addAll(match.getAtoms());
for (int idx : match.getAtoms()) {
for (Match candidate : this.usedIndex.get(idx)) if (!banned.contains(candidate)) {
removed.add(candidate);
banned.add(candidate);
}
}
for (Match toRemove : removed) {
cov.removeUsedMatch(toRemove);
for (int idx : toRemove.getAtoms()) this.usedIndex.get(idx).remove(toRemove);
}
cov.addUsedMatch(match);
for (int idx : match.getAtoms()) this.usedIndex.get(idx).add(match);
return removed;
}
Aggregations