Search in sources :

Example 1 with PolymersDB

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

the class ChainLearningTests method setUp.

@Before
public void setUp() throws Exception {
    // Loading test monomers
    MonomersDB premonos = new MonomersJsonLoader().loadFile("data_tests/monos.json");
    // Creation of a subset of monos
    this.monos = new MonomersDB();
    this.monos.addObject("Dpr", premonos.getObject("Dpr"));
    this.monos.addObject("D-Ser", premonos.getObject("D-Ser"));
    // Loading test rules
    RulesDB rules = RulesJsonLoader.loader.loadFile("data_tests/rules.json");
    // Loading test residues
    ResidueJsonLoader rjl = new ResidueJsonLoader(rules, this.monos);
    this.families = rjl.loadFile("data_tests/res.json");
    // Loading test polymers
    PolymersJsonLoader pjl = new PolymersJsonLoader(premonos);
    PolymersDB base = pjl.loadFile("data_tests/peps.json");
    // Creation of learning base with only 1 polymer.
    this.learningBase = new PolymersDB();
    this.learningBase.addObject("AM-toxin II", base.getObject("306"));
    // Construct reference
    this.constructReference();
}
Also used : RulesDB(db.RulesDB) MonomersJsonLoader(io.loaders.json.MonomersJsonLoader) PolymersDB(db.PolymersDB) MonomersDB(db.MonomersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) ResidueJsonLoader(io.loaders.json.ResidueJsonLoader) Before(org.junit.Before)

Example 2 with PolymersDB

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

the class OverlapData method main.

public static void main(String[] args) {
    // Norine Loading
    MonomersJsonLoader monosLoader = new MonomersJsonLoader();
    MonomersDB norMonos = monosLoader.loadFile("data/monomers.json");
    PolymersJsonLoader loader = new PolymersJsonLoader(norMonos);
    PolymersDB norine = loader.loadFile("data/peptides_clean.json");
    // CCD Loading
    MonomersDB ccdMonos = monosLoader.loadFile("data/pdbe_monos_min.json");
    loader = new PolymersJsonLoader(ccdMonos);
    PolymersDB ccd = loader.loadFile("data/pdbe_polys_clean.json");
    // Norine smiles generation
    HashMap<String, Polymer> polymers = new HashMap<>();
    for (Polymer poly : norine.getObjects()) {
        String smiles = null;
        try {
            smiles = SmilesConverter.conv.toCanonicalSmiles(poly.getSmiles());
        } catch (InvalidSmilesException e) {
            e.printStackTrace();
            continue;
        }
        polymers.put(smiles, poly);
    }
    // Test overlapping peptides
    int overlap = 0;
    for (Polymer poly : ccd.getObjects()) {
        String smiles = null;
        try {
            smiles = SmilesConverter.conv.toCanonicalSmiles(poly.getSmiles());
        } catch (InvalidSmilesException e) {
            e.printStackTrace();
            continue;
        }
        if (polymers.containsKey(smiles)) {
            System.out.println(polymers.get(smiles).getName());
            overlap++;
        }
    }
    System.out.println("Total peptides overlapping : " + overlap);
    // Norine smiles generation
    HashMap<String, Monomer> monomers = new HashMap<>();
    for (Monomer mono : norMonos.getObjects()) {
        String smiles = null;
        try {
            smiles = SmilesConverter.conv.toCanonicalSmiles(mono.getSmiles());
        } catch (InvalidSmilesException e) {
            e.printStackTrace();
            continue;
        }
        monomers.put(smiles, mono);
    }
    // Test overlapping peptides
    overlap = 0;
    for (Monomer mono : ccdMonos.getObjects()) {
        String smiles = null;
        try {
            smiles = SmilesConverter.conv.toCanonicalSmiles(mono.getSmiles());
        } catch (InvalidSmilesException e) {
            e.printStackTrace();
            continue;
        }
        if (monomers.containsKey(smiles)) {
            System.out.println(monomers.get(smiles).getName());
            overlap++;
        }
    }
    System.out.println("Total monomers overlapping : " + overlap + "/" + ccdMonos.size());
}
Also used : MonomersJsonLoader(io.loaders.json.MonomersJsonLoader) HashMap(java.util.HashMap) PolymersDB(db.PolymersDB) MonomersDB(db.MonomersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) Polymer(model.Polymer) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) Monomer(model.Monomer)

Example 3 with PolymersDB

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

the class PolymersToCanonicalSmiles method modify.

public static void modify(String pepFile) {
    // Loading
    PolymersJsonLoader pjl = new PolymersJsonLoader(new MonomersDB());
    PolymersDB db = pjl.loadFile(pepFile);
    // transform all smiles
    for (Polymer pep : db.getObjects()) {
        IMolecule mol = pep.getMolecule();
        String smiles = SmilesConverter.conv.mol2Smiles(mol);
        pep.setSmiles(smiles);
    }
    // Saving
    pjl.saveFile(db, pepFile);
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) PolymersDB(db.PolymersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) MonomersDB(db.MonomersDB) Polymer(model.Polymer)

Example 4 with PolymersDB

use of db.PolymersDB 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 5 with PolymersDB

use of db.PolymersDB 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)

Aggregations

MonomersDB (db.MonomersDB)9 PolymersDB (db.PolymersDB)9 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)9 MonomersJsonLoader (io.loaders.json.MonomersJsonLoader)6 RulesDB (db.RulesDB)5 Polymer (model.Polymer)5 FamilyDB (db.FamilyDB)4 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)4 File (java.io.File)4 MonomersSerialization (io.loaders.serialization.MonomersSerialization)3 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)3 MonomericSpliting (algorithms.MonomericSpliting)2 ResidueCreator (algorithms.ResidueCreator)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 CoveragesJsonLoader (io.loaders.json.CoveragesJsonLoader)2