Search in sources :

Example 1 with ChainsDB

use of algorithms.isomorphism.chains.ChainsDB in project Smiles2Monomers by yoann-dufresne.

the class ChainLearningTests method saveTest.

/**/
@Test
public void saveTest() {
    String line = null;
    String expected = "[{\"roots\":{\"86\":\"C,0,C,1,2,-1,-1;C,0,N,1,1,0,-1;C,0,C,0,1,-1,0;C,1,O,0,0,3,-1\",\"87\":\"C,0,O,2,0,-1,-1;C,0,C,1,2,-1,0;C,0,C,0,1,-1,2;C,0,N,1,1,2,-1;C,1,O,0,0,3,-1\"},\"family\":\"D-Ser\",\"extensions\":{\"79\":[{\"idx2\":-1,\"idx1\":3,\"from\":\"85\",\"type\":\"extension\",\"ext\":\"C,0,O,0,1\"}],\"78\":[{\"idx2\":-1,\"idx1\":3,\"from\":\"84\",\"type\":\"extension\",\"ext\":\"C,0,O,0,1\"}],\"77\":[{\"num\":1,\"idx\":1,\"from\":\"84\",\"type\":\"hydrogen\"}],\"82\":[{\"idx2\":-1,\"idx1\":3,\"from\":\"87\",\"type\":\"extension\",\"ext\":\"C,0,O,0,1\"}],\"83\":[{\"idx2\":-1,\"idx1\":3,\"from\":\"86\",\"type\":\"extension\",\"ext\":\"C,0,O,0,1\"}],\"80\":[{\"idx2\":-1,\"idx1\":3,\"from\":\"81\",\"type\":\"extension\",\"ext\":\"C,0,O,0,1\"}],\"81\":[{\"num\":1,\"idx\":1,\"from\":\"87\",\"type\":\"hydrogen\"}],\"86\":[],\"87\":[],\"84\":[{\"num\":1,\"idx\":4,\"from\":\"87\",\"type\":\"hydrogen\"}],\"85\":[{\"num\":1,\"idx\":2,\"from\":\"86\",\"type\":\"hydrogen\"}]}},{\"roots\":{\"95\":\"C,0,N,2,1,-1,-1;C,0,C,1,2,-1,0;C,0,N,1,1,2,-1;C,0,C,0,1,-1,2;C,1,O,0,0,4,-1\"},\"family\":\"Dpr\",\"extensions\":{\"95\":[],\"94\":[{\"idx2\":-1,\"idx1\":4,\"from\":\"95\",\"type\":\"extension\",\"ext\":\"C,0,O,0,1\"}],\"93\":[{\"num\":1,\"idx\":3,\"from\":\"95\",\"type\":\"hydrogen\"}],\"92\":[{\"num\":1,\"idx\":1,\"from\":\"95\",\"type\":\"hydrogen\"}],\"91\":[{\"idx2\":-1,\"idx1\":4,\"from\":\"93\",\"type\":\"extension\",\"ext\":\"C,0,O,0,1\"}],\"90\":[{\"idx2\":-1,\"idx1\":4,\"from\":\"92\",\"type\":\"extension\",\"ext\":\"C,0,O,0,1\"}],\"89\":[{\"num\":1,\"idx\":1,\"from\":\"93\",\"type\":\"hydrogen\"}]}}]";
    // Computing
    ChainLearning learning = new ChainLearning(this.learningBase);
    learning.setMarkovianSize(3);
    learning.learn(this.families);
    ChainsDB db = learning.getDb();
    FamilyChainIO io = new FamilyChainIO(this.families);
    io.saveFile(db, "data_tests/chains.json");
    try {
        BufferedReader br = new BufferedReader(new FileReader(new File("data_tests/chains.json")));
        line = br.readLine();
        br.close();
    } catch (IOException e) {
        fail(e.getMessage());
    }
    Assert.assertTrue(line.equals(expected));
}
Also used : FamilyChainIO(io.loaders.json.FamilyChainIO) ChainsDB(algorithms.isomorphism.chains.ChainsDB) FamilyChainsDB(algorithms.isomorphism.chains.FamilyChainsDB) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) ChainLearning(algorithms.isomorphism.chains.ChainLearning) File(java.io.File) Test(org.junit.Test)

Example 2 with ChainsDB

use of algorithms.isomorphism.chains.ChainsDB 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)

Example 3 with ChainsDB

use of algorithms.isomorphism.chains.ChainsDB in project Smiles2Monomers by yoann-dufresne.

the class ChainLearningTests method loadTest.

/**/
@Test
public void loadTest() {
    // Computing
    ChainLearning learning = new ChainLearning(this.learningBase);
    learning.setMarkovianSize(3);
    learning.learn(this.families);
    ChainsDB db = learning.getDb();
    FamilyChainIO io = new FamilyChainIO(this.families);
    io.saveFile(db, "data_tests/chains.json");
    ChainsDB loaded = io.loadFile("data_tests/chains.json");
    if (loaded.getObjects().size() != db.getObjects().size())
        fail("Not the same number of objects");
    FamilyChainsDB fc = db.getObjects().get(0);
    FamilyChainsDB fcLoaded = loaded.getObjects().get(0);
    if (fc.getRootChains().size() != fcLoaded.getRootChains().size())
        fail("Root chain number different");
    for (Residue res : fc.getFamily().getResidues()) {
        if (fc.getAdds(res).size() != fcLoaded.getAdds(res).size())
            fail("Adds of " + res.getName() + "are not correctly loaded");
    }
    Assert.assertTrue(true);
}
Also used : FamilyChainIO(io.loaders.json.FamilyChainIO) FamilyChainsDB(algorithms.isomorphism.chains.FamilyChainsDB) Residue(model.Residue) ChainsDB(algorithms.isomorphism.chains.ChainsDB) FamilyChainsDB(algorithms.isomorphism.chains.FamilyChainsDB) ChainLearning(algorithms.isomorphism.chains.ChainLearning) Test(org.junit.Test)

Example 4 with ChainsDB

use of algorithms.isomorphism.chains.ChainsDB 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

ChainsDB (algorithms.isomorphism.chains.ChainsDB)4 ChainLearning (algorithms.isomorphism.chains.ChainLearning)3 FamilyChainIO (io.loaders.json.FamilyChainIO)3 MonomericSpliting (algorithms.MonomericSpliting)2 FamilyChainsDB (algorithms.isomorphism.chains.FamilyChainsDB)2 FamilyDB (db.FamilyDB)2 MonomersDB (db.MonomersDB)2 PolymersDB (db.PolymersDB)2 RulesDB (db.RulesDB)2 MonomersJsonLoader (io.loaders.json.MonomersJsonLoader)2 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)2 File (java.io.File)2 Test (org.junit.Test)2 ResidueCreator (algorithms.ResidueCreator)1 Coverage (algorithms.utils.Coverage)1 Coverages2HTML (io.html.Coverages2HTML)1 ImagesGeneration (io.imgs.ImagesGeneration)1 ColorsMap (io.imgs.PictureCoverageGenerator.ColorsMap)1 CoveragesJsonLoader (io.loaders.json.CoveragesJsonLoader)1 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)1