Search in sources :

Example 1 with MolTreeWidth

use of nl.uu.cs.treewidth.MolTreeWidth 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)

Aggregations

MonomersDB (db.MonomersDB)1 PolymersDB (db.PolymersDB)1 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Polymer (model.Polymer)1 MolTreeWidth (nl.uu.cs.treewidth.MolTreeWidth)1 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)1