Search in sources :

Example 1 with ResidueCreator

use of algorithms.ResidueCreator in project Smiles2Monomers by yoann-dufresne.

the class ResidueCreatorTests method setUp.

@Before
public void setUp() throws Exception {
    if (this.fam != null)
        return;
    this.monos = new MonomersDB();
    Monomer mono = new Monomer("bOH-Tyr", "bOH-Tyr", "c1cc(ccc1C(C(C(=O)O)N)O)O");
    monos.addObject(mono.getId(), mono);
    mono = new Monomer("Tyr", "Tyr", "c1cc(ccc1CC(C(=O)O)N)O");
    monos.addObject(mono.getId(), mono);
    this.rules = RulesJsonLoader.loader.loadFile("data_tests/rules.json");
    this.creator = new ResidueCreator(this.rules);
    this.families = this.creator.createResidues(this.monos);
    this.fam = null;
    try {
        this.fam = this.families.getObject("Tyr");
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    this.residues = this.fam.getResidues();
}
Also used : MonomersDB(db.MonomersDB) ResidueCreator(algorithms.ResidueCreator) Monomer(model.Monomer) Before(org.junit.Before)

Example 2 with ResidueCreator

use of algorithms.ResidueCreator in project Smiles2Monomers by yoann-dufresne.

the class PreComputation method main.

public static void main(String[] args) {
    // ----------------- Parameters ---------------------------
    String rulesDBName = "data/rules.json";
    String monosDBName = "data/monomers.json";
    String jsonPolymers = "data/learning.json";
    String serialFolder = "data/serials/";
    String jsonResidues = "data/residues.json";
    String jsonChains = "data/chains.json";
    int markovianSize = 3;
    // Parsing
    for (int idx = 0; idx < args.length; idx++) {
        if (args[idx].startsWith("-")) {
            switch(args[idx]) {
                case "-rul":
                    rulesDBName = args[idx + 1];
                    break;
                case "-mono":
                    monosDBName = args[idx + 1];
                    break;
                case "-poly":
                    jsonPolymers = args[idx + 1];
                    break;
                case "-res":
                    jsonResidues = args[idx + 1];
                    break;
                case "-cha":
                    jsonChains = args[idx + 1];
                    break;
                case "-serial":
                    serialFolder = args[idx + 1];
                    break;
                case "-markovian":
                    markovianSize = new Integer(args[idx + 1]);
                    break;
                default:
                    System.err.println("Wrong option " + args[idx]);
                    System.exit(1);
                    break;
            }
            idx++;
        } else {
            System.err.println("Wrong parameter " + args[idx]);
            System.exit(1);
        }
    }
    // File existence
    File file = new File(rulesDBName);
    if (!file.exists()) {
        System.err.println("No file at " + rulesDBName);
        System.exit(1);
    }
    file = new File(monosDBName);
    if (!file.exists()) {
        System.err.println("No file at " + monosDBName);
        System.exit(1);
    }
    file = new File(jsonPolymers);
    if (!file.exists()) {
        System.err.println("No file at " + jsonPolymers);
        System.exit(1);
    }
    // ------------------- Loadings ------------------------
    System.out.println("--- Loading ---");
    RulesDB rules = RulesJsonLoader.loader.loadFile(rulesDBName);
    MonomersDB monos = new MonomersJsonLoader(true).loadFile(monosDBName);
    PolymersJsonLoader pjl = new PolymersJsonLoader(monos, false);
    PolymersDB learningBase = pjl.loadFile(jsonPolymers);
    // ----------------- Serializations --------------------
    System.out.println("--- Data serialisation ---");
    File folder = new File(serialFolder);
    if (!folder.exists())
        folder.mkdir();
    MonomersSerialization ms = new MonomersSerialization();
    ms.serialize(monos, serialFolder + "monos.serial");
    // ----------------- residues --------------------------
    ResidueCreator rc = new ResidueCreator(rules);
    rc.setVerbose(false);
    System.out.println("--- Residues creation ---");
    FamilyDB families = rc.createResidues(monos);
    System.out.println("--- Saving residues ---");
    ResidueJsonLoader rjl = new ResidueJsonLoader(rules, monos);
    rjl.saveFile(families, jsonResidues);
    // ----------------- chains ----------------------------
    System.out.println("--- Learning chains ---");
    // Adapt residue structures
    for (Residue res : families.getResidues().getObjects()) res.explicitToImplicitHydrogens();
    ChainLearning learning = new ChainLearning(learningBase);
    learning.setMarkovianSize(markovianSize);
    learning.learn(families);
    // --- Save ---
    System.out.println("--- Saving chains ---");
    FamilyChainIO fcio = new FamilyChainIO(families);
    fcio.saveFile(learning.getDb(), jsonChains);
    System.out.println("--- Ended ---");
}
Also used : MonomersJsonLoader(io.loaders.json.MonomersJsonLoader) MonomersDB(db.MonomersDB) ResidueCreator(algorithms.ResidueCreator) FamilyDB(db.FamilyDB) ChainLearning(algorithms.isomorphism.chains.ChainLearning) MonomersSerialization(io.loaders.serialization.MonomersSerialization) RulesDB(db.RulesDB) FamilyChainIO(io.loaders.json.FamilyChainIO) Residue(model.Residue) PolymersDB(db.PolymersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) ResidueJsonLoader(io.loaders.json.ResidueJsonLoader) File(java.io.File)

Example 3 with ResidueCreator

use of algorithms.ResidueCreator 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);
}
Also used : RulesDB(db.RulesDB) MonomericSpliting(algorithms.MonomericSpliting) MonomersJsonLoader(io.loaders.json.MonomersJsonLoader) PolymersDB(db.PolymersDB) MonomersDB(db.MonomersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) ChainsDB(algorithms.isomorphism.chains.ChainsDB) Polymer(model.Polymer) ResidueCreator(algorithms.ResidueCreator) FamilyDB(db.FamilyDB) ChainLearning(algorithms.isomorphism.chains.ChainLearning) Before(org.junit.Before)

Aggregations

ResidueCreator (algorithms.ResidueCreator)3 MonomersDB (db.MonomersDB)3 ChainLearning (algorithms.isomorphism.chains.ChainLearning)2 FamilyDB (db.FamilyDB)2 PolymersDB (db.PolymersDB)2 RulesDB (db.RulesDB)2 MonomersJsonLoader (io.loaders.json.MonomersJsonLoader)2 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)2 Before (org.junit.Before)2 MonomericSpliting (algorithms.MonomericSpliting)1 ChainsDB (algorithms.isomorphism.chains.ChainsDB)1 FamilyChainIO (io.loaders.json.FamilyChainIO)1 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)1 MonomersSerialization (io.loaders.serialization.MonomersSerialization)1 File (java.io.File)1 Monomer (model.Monomer)1 Polymer (model.Polymer)1 Residue (model.Residue)1