Search in sources :

Example 6 with MonomersDB

use of db.MonomersDB in project Smiles2Monomers by yoann-dufresne.

the class Json2HTML method main.

public static void main(String[] args) {
    if (args.length < 6) {
        System.err.println("Command line :\n\tjava main.AtomicToMonomeric <monomersFile> <peptidesFile> <rulesFile> <residuesFile> <coveragesFile> <outType> [outFile]  [-v]");
        System.err.println("  outType can be \"-zip\" or \"-html\"");
        System.exit(42);
    }
    String monoDBname = args[0];
    String pepDBname = args[1];
    String rulesDBname = args[2];
    String residuesDBname = args[3];
    String covsFile = args[4];
    boolean zip = args[5].equals("-zip") ? true : false;
    String outFile = null;
    if (zip && args.length < 7) {
        System.err.println("Command line :\n\tjava main.AtomicToMonomeric <monomersFile> <peptidesFile> <rulesFile> <residuesFile> <coveragesFile> <outType> [outFile]  [-v]");
        System.err.println("  outType can be \"-zip\" or \"-html\"");
        System.exit(42);
    } else if (zip && args.length >= 7)
        outFile = args[6];
    // Loading databases
    System.out.println("--- Loading ---");
    // Maybe loading can be faster for the learning base, using serialized molecules instead of CDK SMILES parsing method.
    long loadingTime = System.currentTimeMillis();
    MonomersDB monoDB = new MonomersJsonLoader(false).loadFile(monoDBname);
    MonomersSerialization ms = new MonomersSerialization();
    ms.deserialize(monoDB, "data/serials/monos.serial");
    PolymersJsonLoader pcl = new PolymersJsonLoader(monoDB, true);
    PolymersDB pepDB = pcl.loadFile(pepDBname);
    RulesDB rules = RulesJsonLoader.loader.loadFile(rulesDBname);
    ResidueJsonLoader rjl = new ResidueJsonLoader(rules, monoDB);
    FamilyDB families = rjl.loadFile(residuesDBname);
    loadingTime = (System.currentTimeMillis() - loadingTime) / 1000;
    System.out.println("--- Json to HTML ---");
    long creationTime = System.currentTimeMillis();
    CoveragesJsonLoader cl = new CoveragesJsonLoader(pepDB, families);
    CoveragesDB covs = cl.loadFile(covsFile);
    List<Coverage> covsList = covs.getObjects();
    Collections.sort(covsList);
    // Common generations
    File imgs = new File("tmp_imgs_" + covsFile.substring(covsFile.lastIndexOf("/") + 1, covsFile.lastIndexOf(".")));
    if (!imgs.exists())
        imgs.mkdir();
    ImagesGeneration ig = new ImagesGeneration();
    Map<Coverage, ColorsMap> allColors = ig.generate(imgs, monoDB, covsList);
    if (!zip) {
        // HTML
        File resultDir = null;
        if (covsFile.contains("/"))
            resultDir = new File(covsFile.substring(0, covsFile.lastIndexOf("/")));
        else
            resultDir = new File(".");
        if (!resultDir.exists())
            resultDir.mkdir();
        Coverages2HTML c2h = new Coverages2HTML(covsList, monoDB, families);
        File htmlFile = new File(resultDir.getPath() + "/test.html");
        c2h.createResults(htmlFile, imgs, allColors);
    } else {
        // Zip File
        OutputZiper oz = new OutputZiper(outFile);
        oz.createZip(imgs.getPath(), covsFile, pepDBname, monoDBname, residuesDBname, allColors);
    }
    ig.cleanTmp(imgs);
    creationTime = (System.currentTimeMillis() - creationTime) / 1000;
    System.out.println();
    System.out.println("Total time to load datas : " + loadingTime + "s");
    System.out.println("Total time to create HTML : " + creationTime + "s");
    System.out.println();
    System.out.println("--- Program ended ---");
}
Also used : MonomersJsonLoader(io.loaders.json.MonomersJsonLoader) MonomersDB(db.MonomersDB) Coverage(algorithms.utils.Coverage) FamilyDB(db.FamilyDB) MonomersSerialization(io.loaders.serialization.MonomersSerialization) RulesDB(db.RulesDB) ImagesGeneration(io.imgs.ImagesGeneration) CoveragesDB(db.CoveragesDB) PolymersDB(db.PolymersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) OutputZiper(io.zip.OutputZiper) CoveragesJsonLoader(io.loaders.json.CoveragesJsonLoader) Coverages2HTML(io.html.Coverages2HTML) ResidueJsonLoader(io.loaders.json.ResidueJsonLoader) File(java.io.File) ColorsMap(io.imgs.PictureCoverageGenerator.ColorsMap)

Example 7 with MonomersDB

use of db.MonomersDB in project Smiles2Monomers by yoann-dufresne.

the class PlanarityTest method main.

public static void main(String[] args) {
    String pepDBname = "datas/peptides.csv";
    // Loading databases
    PolymersJsonLoader pcl = new PolymersJsonLoader(new MonomersDB());
    PolymersDB pepDB = pcl.loadFile(pepDBname);
    // Tools
    Planarity pt = new Planarity();
    for (Polymer pep : pepDB.getObjects()) {
        System.out.println(pep.getName() + " : ");
        IMolecule mol = null;
        try {
            mol = SmilesConverter.conv.transform(pep.getSmiles());
        } catch (InvalidSmilesException e) {
            System.err.println("Impossible to parse " + pep.getName() + " id:" + pep.getId());
            continue;
        }
        SimpleGraph g = MoleculeGraphs.getMoleculeGraph(mol);
        System.out.println("planar : " + pt.isPlanar(g) + "\n");
    }
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) PolymersDB(db.PolymersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) MonomersDB(db.MonomersDB) SimpleGraph(org._3pq.jgrapht.graph.SimpleGraph) Polymer(model.Polymer) Planarity(algorithms.Planarity) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException)

Example 8 with MonomersDB

use of db.MonomersDB in project Smiles2Monomers by yoann-dufresne.

the class PolymersTreeWidths method main.

public static void main(String[] args) {
    if (args.length < 1) {
        System.err.println("Command line : java main.PeptidesTreeWidths <peptidesFile> [outfile]");
        System.exit(-1);
    }
    // Parse arguments
    String pepDBname = args[0];
    BufferedWriter bw = null;
    if (args.length > 1) {
        File out = new File(args[1]);
        if (out.exists())
            out.delete();
        try {
            bw = new BufferedWriter(new FileWriter(out));
            bw.write("peptide;treewidth\n");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // Loading databases
    MonomersDB monoDB = new MonomersDB();
    PolymersJsonLoader pcl = new PolymersJsonLoader(monoDB);
    PolymersDB pepDB = pcl.loadFile(pepDBname);
    // Tools for treewidth
    MolTreeWidth mtw = new MolTreeWidth();
    for (Polymer pep : pepDB.getObjects()) {
        int tw;
        try {
            tw = mtw.calculateTreeWidth(SmilesConverter.conv.transform(pep.getSmiles()));
        } catch (InvalidSmilesException e) {
            System.err.println("Impossible to parse " + pep.getName() + " id:" + pep.getId());
            continue;
        }
        if (args.length > 1) {
            try {
                bw.write(pep.getName() + ";" + tw + "\n");
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println(pep.getName() + " : " + tw);
        }
    }
    if (args.length > 1) {
        try {
            bw.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : PolymersDB(db.PolymersDB) MolTreeWidth(nl.uu.cs.treewidth.MolTreeWidth) FileWriter(java.io.FileWriter) MonomersDB(db.MonomersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) Polymer(model.Polymer) IOException(java.io.IOException) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 9 with MonomersDB

use of db.MonomersDB 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 10 with MonomersDB

use of db.MonomersDB in project Smiles2Monomers by yoann-dufresne.

the class ProcessPolymers method main.

public static void main(String[] args) {
    // ----------------- Parameters ---------------------------
    String monoDBname = "data/monomers.json";
    String pepDBname = "data/polymers.json";
    String rulesDBname = "data/rules.json";
    String residuesDBname = "data/residues.json";
    String chainsDBFile = "data/chains.json";
    String outfile = "results/coverages.json";
    String outfolderName = "results/";
    String imgsFoldername = "images/";
    boolean html = false;
    boolean zip = false;
    String serialFolder = "data/serials/";
    boolean lightMatch = true;
    boolean verbose = false;
    int removeDistance = 2;
    int retryCount = 2;
    int modulationDepth = 2;
    // Parsing
    loop: for (int idx = 0; idx < args.length; idx++) {
        if (args[idx].startsWith("-")) {
            switch(args[idx]) {
                case "-rul":
                    rulesDBname = args[idx + 1];
                    break;
                case "-mono":
                    monoDBname = args[idx + 1];
                    break;
                case "-poly":
                    pepDBname = args[idx + 1];
                    break;
                case "-res":
                    residuesDBname = args[idx + 1];
                    break;
                case "-cha":
                    chainsDBFile = args[idx + 1];
                    break;
                case "-serial":
                    serialFolder = args[idx + 1];
                    break;
                case "-outfile":
                    outfile = args[idx + 1];
                    break;
                case "-outfolder":
                    outfolderName = args[idx + 1];
                    break;
                case "-imgs":
                    imgsFoldername = args[idx + 1];
                    break;
                case "-strict":
                    lightMatch = false;
                    continue loop;
                case "-v":
                    verbose = true;
                    continue loop;
                case "-html":
                    html = true;
                    continue loop;
                case "-zip":
                    zip = true;
                    continue loop;
                default:
                    System.err.println("Wrong option " + args[idx]);
                    System.exit(1);
                    break;
            }
            idx++;
        } else {
            System.err.println("Wrong parameter " + args[idx]);
            System.exit(1);
        }
    }
    // ------------------- Loadings ------------------------
    System.out.println("--- Loading ---");
    // Maybe loading can be faster for the learning base, using serialized molecules instead of CDK SMILES parsing method.
    long loadingTime = System.currentTimeMillis();
    MonomersDB monoDB = new MonomersJsonLoader(false).loadFile(monoDBname);
    MonomersSerialization ms = new MonomersSerialization();
    ms.deserialize(monoDB, serialFolder + "monos.serial");
    boolean d2 = html || zip;
    PolymersJsonLoader pjl = new PolymersJsonLoader(monoDB, d2);
    PolymersDB polDB = pjl.loadFile(pepDBname);
    RulesDB rulesDB = RulesJsonLoader.loader.loadFile(rulesDBname);
    ResidueJsonLoader rjl = new ResidueJsonLoader(rulesDB, monoDB);
    // Need optimizations
    FamilyDB families = rjl.loadFile(residuesDBname);
    FamilyChainIO fcio = new FamilyChainIO(families);
    ChainsDB chains = fcio.loadFile(chainsDBFile);
    loadingTime = System.currentTimeMillis() - loadingTime;
    System.out.println("Loading time : " + (loadingTime / 1000) + "s");
    // ------------------- Spliting ------------------------
    System.out.println("--- Monomers search ---");
    long searchTime = System.currentTimeMillis();
    MonomericSpliting.setVerbose(verbose);
    MonomericSpliting split = new MonomericSpliting(families, chains, removeDistance, retryCount, modulationDepth);
    split.setAllowLightMatchs(lightMatch);
    Coverage[] covs = split.computeCoverages(polDB);
    searchTime = System.currentTimeMillis() - searchTime;
    System.out.println("Search time : " + (searchTime / 1000) + "s");
    // ------------------- Output ------------------------
    System.out.println("--- Output creations ---");
    long outputTime = System.currentTimeMillis();
    // Creation of the out directory
    File outfolder = new File(outfolderName);
    if (!outfolder.exists())
        outfolder.mkdir();
    CoveragesJsonLoader cjl = new CoveragesJsonLoader(polDB, families);
    cjl.saveFile(covs, outfile);
    // Images generation
    if (html || zip) {
        File imgsFolder = new File(imgsFoldername);
        if (!imgsFolder.exists())
            imgsFolder.mkdir();
        ImagesGeneration ig = new ImagesGeneration();
        ig.generateMonomerImages(imgsFolder, monoDB);
        Map<Coverage, ColorsMap> colors = ig.generatePeptidesImages(imgsFolder, covs);
        if (html) {
            // HTML
            Coverages2HTML c2h = new Coverages2HTML(covs, monoDB, families);
            File htmlFile = new File(outfolderName + "/s2m.html");
            c2h.createResults(htmlFile, imgsFolder, colors);
        }
        if (zip) {
            // Zip File
            OutputZiper oz = new OutputZiper(outfolderName + "/s2m.zip");
            oz.createZip(imgsFolder.getPath(), outfile, pepDBname, monoDBname, residuesDBname, colors);
        }
    }
    outputTime = System.currentTimeMillis() - outputTime;
    System.out.println("Ouputing time : " + (outputTime / 1000) + "s");
    System.out.println("--- Ended ---");
}
Also used : MonomericSpliting(algorithms.MonomericSpliting) MonomersJsonLoader(io.loaders.json.MonomersJsonLoader) MonomersDB(db.MonomersDB) ChainsDB(algorithms.isomorphism.chains.ChainsDB) Coverage(algorithms.utils.Coverage) FamilyDB(db.FamilyDB) MonomersSerialization(io.loaders.serialization.MonomersSerialization) RulesDB(db.RulesDB) FamilyChainIO(io.loaders.json.FamilyChainIO) ImagesGeneration(io.imgs.ImagesGeneration) PolymersDB(db.PolymersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) OutputZiper(io.zip.OutputZiper) CoveragesJsonLoader(io.loaders.json.CoveragesJsonLoader) Coverages2HTML(io.html.Coverages2HTML) ResidueJsonLoader(io.loaders.json.ResidueJsonLoader) File(java.io.File) ColorsMap(io.imgs.PictureCoverageGenerator.ColorsMap)

Aggregations

MonomersDB (db.MonomersDB)12 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)10 PolymersDB (db.PolymersDB)9 MonomersJsonLoader (io.loaders.json.MonomersJsonLoader)7 RulesDB (db.RulesDB)6 FamilyDB (db.FamilyDB)5 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)5 File (java.io.File)5 Polymer (model.Polymer)5 Before (org.junit.Before)4 ResidueCreator (algorithms.ResidueCreator)3 MonomersSerialization (io.loaders.serialization.MonomersSerialization)3 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)3 MonomericSpliting (algorithms.MonomericSpliting)2 ChainLearning (algorithms.isomorphism.chains.ChainLearning)2 ChainsDB (algorithms.isomorphism.chains.ChainsDB)2 Coverage (algorithms.utils.Coverage)2 Coverages2HTML (io.html.Coverages2HTML)2 ImagesGeneration (io.imgs.ImagesGeneration)2 ColorsMap (io.imgs.PictureCoverageGenerator.ColorsMap)2