use of model.Residue 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 model.Residue in project Smiles2Monomers by yoann-dufresne.
the class FamilyDB method addObject.
@Override
public void addObject(String id, Family f) {
Family prev = null;
for (Monomer m : f.getMonomers()) if (this.database.containsKey(m.getId())) {
prev = this.database.get(m.getId());
break;
}
if (prev == null) {
for (Monomer m : f.getMonomers()) {
super.addObject(m.getId(), f);
this.uniqFamilies.add(f);
}
} else {
for (Monomer m : f.getMonomers()) {
prev.addMonomer(m);
this.database.put(m.getId(), prev);
}
for (Residue res : f.getResidues()) prev.addResidue(res);
for (Link l : f.getDepandances()) prev.addDependance(l);
}
}
use of model.Residue in project Smiles2Monomers by yoann-dufresne.
the class ResiduesDB method getAlphabeticResidues.
public List<Residue> getAlphabeticResidues() {
List<Residue> residues = new ArrayList<>(this.database.values());
Collections.sort(residues);
this.databaseByIdx.clear();
for (Residue res : residues) {
// res.setIdx(residues.indexOf(res)+1);
this.databaseByIdx.put(residues.indexOf(res) + 1, res);
}
return residues;
}
use of model.Residue in project Smiles2Monomers by yoann-dufresne.
the class FamilyChainsDB method toJSON.
@SuppressWarnings("unchecked")
public JSONObject toJSON() {
JSONObject jso = new JSONObject();
// Id
jso.put("family", this.family.getJsonName());
// Roots
JSONObject roots = new JSONObject();
for (Residue res : this.rootChains.keySet()) {
roots.put(res.getId(), this.rootChains.get(res).getSerial());
}
jso.put("roots", roots);
// Extensions
JSONObject exts = new JSONObject();
for (Residue res : this.adds.keySet()) {
JSONArray adds = new JSONArray();
for (ChainAdd add : this.adds.get(res)) {
adds.add(add.toJSON());
}
exts.put(res.getId(), adds);
}
jso.put("extensions", exts);
return jso;
}
use of model.Residue in project Smiles2Monomers by yoann-dufresne.
the class ChainsFamilyMatching method addToCoverage.
private void addToCoverage(Family family, MappedChain mc, Residue res) {
Match match = new Match(res);
match.addAtoms(mc.getAtomsMapping());
match.addBonds(mc.getBondsMapping());
match.addHydrogens(mc.getHydrogensMapping());
for (int idx = 0; idx < mc.getMatchings().size(); idx++) {
match.addQuality(mc.getBondsMapping().get(idx), mc.getMatchings().get(idx));
}
// Compute external bonds by aligning chain on residue
// 1- Retrieve the chain on root residue
int current = 200;
List<MappedChain> onResidue = null;
Residue rootMol = null;
for (Residue root : family.getRoots()) {
List<MappedChain> mcs = Isomorphism.searchAChain(mc.getChain(), root, MatchingType.EXACT);
if (mcs.size() > 0 && current > mcs.size()) {
current = mcs.size();
onResidue = mcs;
rootMol = root;
}
}
// 2- Look for atoms of interest
MappedChain resMapping = onResidue.get(0);
for (IAtom ia : rootMol.getAtomicLinks().keySet()) {
Rule r = rootMol.getAtomicLinks().get(ia);
int resMolIdx = rootMol.getMolecule().getAtomNumber(ia);
int chainIdx = resMapping.getAtomsMapping().indexOf(resMolIdx);
match.addExtLink(mc.getAtomsMapping().get(chainIdx), r);
}
// Add the match
if (!this.coverage.getMatches().contains(match))
this.coverage.addMatch(match);
}
Aggregations