Search in sources :

Example 6 with ChainLearning

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

the class ChainLearningTests method generateSize3Test.

@Test
public void generateSize3Test() {
    // Computing
    ChainLearning learning = new ChainLearning(this.learningBase);
    learning.setMarkovianSize(3);
    learning.learn(this.families);
    FrequencesIndex frequences = learning.getFrequence();
    ChainsIndex chains = learning.getAllChains();
    // Verification
    for (String pattern : chains.keySet()) {
        Chain chain = chains.get(pattern);
        if (chain.getSize() != 3)
            continue;
        if (!this.size3Frequencies.containsKey(pattern) || this.size3Frequencies.get(pattern) != frequences.get(pattern) || !this.size3Blocs.get(pattern).equals(chain.getSerial())) {
            System.out.println(pattern);
            System.out.println(chain.getSerial());
            fail(pattern + " : " + frequences.get(pattern) + " -> " + this.size3Blocs.get(pattern));
        }
    }
    Assert.assertTrue(frequences.size() == 19);
}
Also used : Chain(algorithms.isomorphism.chains.Chain) FrequencesIndex(algorithms.isomorphism.chains.ChainLearning.FrequencesIndex) ChainLearning(algorithms.isomorphism.chains.ChainLearning) ChainsIndex(algorithms.isomorphism.chains.ChainLearning.ChainsIndex) Test(org.junit.Test)

Example 7 with ChainLearning

use of algorithms.isomorphism.chains.ChainLearning 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 8 with ChainLearning

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

ChainLearning (algorithms.isomorphism.chains.ChainLearning)8 Test (org.junit.Test)6 Chain (algorithms.isomorphism.chains.Chain)3 ChainsIndex (algorithms.isomorphism.chains.ChainLearning.ChainsIndex)3 ChainsDB (algorithms.isomorphism.chains.ChainsDB)3 FamilyChainIO (io.loaders.json.FamilyChainIO)3 ResidueCreator (algorithms.ResidueCreator)2 FrequencesIndex (algorithms.isomorphism.chains.ChainLearning.FrequencesIndex)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 Residue (model.Residue)2 MonomericSpliting (algorithms.MonomericSpliting)1 ResidueJsonLoader (io.loaders.json.ResidueJsonLoader)1 MonomersSerialization (io.loaders.serialization.MonomersSerialization)1