From: <km...@us...> - 2011-03-31 06:34:24
|
Revision: 2741 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2741&view=rev Author: kmpf Date: 2011-03-31 06:34:17 +0000 (Thu, 31 Mar 2011) Log Message: ----------- Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/TrainAndTestSet.java Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-03-29 16:09:59 UTC (rev 2740) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-03-31 06:34:17 UTC (rev 2741) @@ -1,6 +1,7 @@ package org.dllearner.examples.pdb; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; @@ -11,6 +12,15 @@ import java.util.Iterator; import java.util.Set; +import org.dllearner.cli.Start; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.kb.OWLFile; +import org.dllearner.reasoning.FastInstanceChecker; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -61,6 +71,8 @@ private static String saveDir = "../test/pdb/"; + private static HashMap<Resource, File> confFilePerResidue; + private static File confFileForAll; /** * @param args @@ -70,8 +82,9 @@ TrainAndTestSet sets; PdbRdfModel trainmodel = new PdbRdfModel(); - do{ - sets = new TrainAndTestSet(1); + //do{ + String pdbID = "3LQH"; + sets = new TrainAndTestSet(pdbID); trainmodel.add(getRdfModelForIds(sets.getTrainset())); /* * String[] id = {"200L"}; @@ -82,12 +95,12 @@ /* * as we have to handle several amino acid chains we need the first - * amino acid of every chain, they are returned as ResIterator + * amino acid of every chain, they are returned within a ResIterator */ ResIterator niter = getFirstAA(trainmodel); /* - * we add some distance Information to out model + * we add some distance Information to our model */ trainmodel = addDistanceInfo(trainmodel); @@ -96,7 +109,7 @@ * global positives ArrayList, and all others in the global negatives ArrayList */ createPositivesAndNegatives(niter, trainmodel); - } while(positives.size() > 100 && negatives.size() > 100); + //} while(positives.size() > 100 && negatives.size() > 100); /* * remove all triples that contain information about begin and end of helices @@ -108,21 +121,22 @@ Resource residue = ResourceFactory.createResource("http://bio2rdf.org/pdb:Residue"); trainmodel = removeStatementsWithObject(trainmodel, residue); - /* - * writes the conf-Files - */ + SimpleDateFormat df = new SimpleDateFormat("_yyyy_MM_dd_HH:mm"); + String date = df.format(new Date()); + String rdffile= "Helixtrainer" + date + ".rdf"; + String filename = saveDir + rdffile; - try { - SimpleDateFormat df = new SimpleDateFormat("_yyyy_MM_dd_HH:mm"); - String date = df.format(new Date()); - String rdffile= "Helixtrainer" + date + ".rdf"; - String filename = saveDir + rdffile; + /* + * creatConfFile() + * writes the conf-Files and saves there File-objects in: + * confFileForAll and confFilePerResidue + */ createConfFile(date, rdffile, trainmodel); PrintStream out = new PrintStream (new File(filename)); - // Output query results + // Output results trainmodel.write(out, "RDF/XML"); // Important - free up resources used running the query @@ -132,6 +146,39 @@ { System.err.println("OutputStream konnte nicht geschlossen werden!"); } + + /* + * load RDF file and perform learn algorithm for every .conf-file + */ + + Start start = null; + Iterator<Resource> aa = confFilePerResidue.keySet().iterator(); + while ( aa.hasNext() ){ + Resource nextRes = aa.next(); + /* + ComponentManager cm = ComponentManager.getInstance(); + KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); + cm.applyConfigEntry(ks, "url","file://" + filename ); + ReasonerComponent rc = cm.reasoner(FastInstanceChecker.class); + rc.init(); + */ + System.out.println(confFilePerResidue.get(nextRes).getAbsolutePath()); + try{ + start = new Start(confFilePerResidue.get(nextRes)); + } catch (ComponentInitException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (org.dllearner.confparser.ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + start.start(false); + Description d = start.getLearningAlgorithm().getCurrentlyBestDescription(); + System.out.println(d.toKBSyntaxString()); + } + } private static PdbRdfModel getRdfModelForIds(String[] pdbIDs) { @@ -239,7 +286,6 @@ " ?x2 pdb:isImmediatelyBefore ?x3 . " + " ?x3 pdb:isImmediatelyBefore ?x4 . " + " ?x4 pdb:isImmediatelyBefore ?x5 . }"; - System.out.println(queryString); Query query = QueryFactory.create(queryString); QueryExecution qe = QueryExecutionFactory.create(query, model); model.add(qe.execConstruct()); @@ -343,40 +389,67 @@ { // the file with all amino acids String pdbname = saveDir + "pdb" + date + ".conf"; - PrintStream out = new PrintStream (new File(pdbname)); + confFileForAll = new File(pdbname); + PrintStream out = new PrintStream (confFileForAll); // add import statements out.println("import(\"AA_properties.owl\");"); out.println("import(\"" + rdffile + "\");"); out.println(); + HashMap<Resource, File> resConfFiles = new HashMap<Resource, File>(30); + resConfFiles.put(ala, new File(saveDir + ala.getLocalName() + date + ".conf")); + resConfFiles.put(cys, new File(saveDir + cys.getLocalName() + date + ".conf")); + resConfFiles.put(asp, new File(saveDir + asp.getLocalName() + date + ".conf")); + resConfFiles.put(glu, new File(saveDir + glu.getLocalName() + date + ".conf")); + resConfFiles.put(phe, new File(saveDir + phe.getLocalName() + date + ".conf")); + resConfFiles.put(gly, new File(saveDir + gly.getLocalName() + date + ".conf")); + resConfFiles.put(his, new File(saveDir + his.getLocalName() + date + ".conf")); + resConfFiles.put(ile, new File(saveDir + ile.getLocalName() + date + ".conf")); + resConfFiles.put(lys, new File(saveDir + lys.getLocalName() + date + ".conf")); + resConfFiles.put(leu, new File(saveDir + leu.getLocalName() + date + ".conf")); + resConfFiles.put(met, new File(saveDir + met.getLocalName() + date + ".conf")); + resConfFiles.put(asn, new File(saveDir + asn.getLocalName() + date + ".conf")); + resConfFiles.put(pro, new File(saveDir + pro.getLocalName() + date + ".conf")); + resConfFiles.put(gln, new File(saveDir + gln.getLocalName() + date + ".conf")); + resConfFiles.put(arg, new File(saveDir + arg.getLocalName() + date + ".conf")); + resConfFiles.put(ser, new File(saveDir + ser.getLocalName() + date + ".conf")); + resConfFiles.put(thr, new File(saveDir + thr.getLocalName() + date + ".conf")); + resConfFiles.put(val, new File(saveDir + val.getLocalName() + date + ".conf")); + resConfFiles.put(trp, new File(saveDir + trp.getLocalName() + date + ".conf")); + resConfFiles.put(tyr, new File(saveDir + tyr.getLocalName() + date + ".conf")); + resConfFiles.put(sel, new File(saveDir + sel.getLocalName() + date + ".conf")); + confFilePerResidue = resConfFiles; + + + // put all amino acid resources and the their conf-files together HashMap<Resource, PrintStream> resprint = new HashMap<Resource, PrintStream>(30); - resprint.put(ala, new PrintStream(new File(saveDir + ala.getLocalName() + date + ".conf"))); - resprint.put(cys, new PrintStream(new File(saveDir + cys.getLocalName() + date + ".conf"))); - resprint.put(asp, new PrintStream(new File(saveDir + asp.getLocalName() + date + ".conf"))); - resprint.put(glu, new PrintStream(new File(saveDir + glu.getLocalName() + date + ".conf"))); - resprint.put(phe, new PrintStream(new File(saveDir + phe.getLocalName() + date + ".conf"))); - resprint.put(gly, new PrintStream(new File(saveDir + gly.getLocalName() + date + ".conf"))); - resprint.put(his, new PrintStream(new File(saveDir + his.getLocalName() + date + ".conf"))); - resprint.put(ile, new PrintStream(new File(saveDir + ile.getLocalName() + date + ".conf"))); - resprint.put(lys, new PrintStream(new File(saveDir + lys.getLocalName() + date + ".conf"))); - resprint.put(leu, new PrintStream(new File(saveDir + leu.getLocalName() + date + ".conf"))); - resprint.put(met, new PrintStream(new File(saveDir + met.getLocalName() + date + ".conf"))); - resprint.put(asn, new PrintStream(new File(saveDir + asn.getLocalName() + date + ".conf"))); - resprint.put(pro, new PrintStream(new File(saveDir + pro.getLocalName() + date + ".conf"))); - resprint.put(gln, new PrintStream(new File(saveDir + gln.getLocalName() + date + ".conf"))); - resprint.put(arg, new PrintStream(new File(saveDir + arg.getLocalName() + date + ".conf"))); - resprint.put(ser, new PrintStream(new File(saveDir + ser.getLocalName() + date + ".conf"))); - resprint.put(thr, new PrintStream(new File(saveDir + thr.getLocalName() + date + ".conf"))); - resprint.put(val, new PrintStream(new File(saveDir + val.getLocalName() + date + ".conf"))); - resprint.put(trp, new PrintStream(new File(saveDir + trp.getLocalName() + date + ".conf"))); - resprint.put(tyr, new PrintStream(new File(saveDir + tyr.getLocalName() + date + ".conf"))); - resprint.put(sel, new PrintStream(new File(saveDir + sel.getLocalName() + date + ".conf"))); + resprint.put(ala, new PrintStream(resConfFiles.get(ala))); + resprint.put(cys, new PrintStream(resConfFiles.get(cys))); + resprint.put(asp, new PrintStream(resConfFiles.get(asp))); + resprint.put(glu, new PrintStream(resConfFiles.get(glu))); + resprint.put(phe, new PrintStream(resConfFiles.get(phe))); + resprint.put(gly, new PrintStream(resConfFiles.get(gly))); + resprint.put(his, new PrintStream(resConfFiles.get(his))); + resprint.put(ile, new PrintStream(resConfFiles.get(ile))); + resprint.put(lys, new PrintStream(resConfFiles.get(lys))); + resprint.put(leu, new PrintStream(resConfFiles.get(leu))); + resprint.put(met, new PrintStream(resConfFiles.get(met))); + resprint.put(asn, new PrintStream(resConfFiles.get(asn))); + resprint.put(pro, new PrintStream(resConfFiles.get(pro))); + resprint.put(gln, new PrintStream(resConfFiles.get(gln))); + resprint.put(arg, new PrintStream(resConfFiles.get(arg))); + resprint.put(ser, new PrintStream(resConfFiles.get(ser))); + resprint.put(thr, new PrintStream(resConfFiles.get(thr))); + resprint.put(val, new PrintStream(resConfFiles.get(val))); + resprint.put(trp, new PrintStream(resConfFiles.get(trp))); + resprint.put(tyr, new PrintStream(resConfFiles.get(tyr))); + resprint.put(sel, new PrintStream(resConfFiles.get(sel))); Property type = ResourceFactory.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "type"); // add import statements to .conf files for amino acids - Iterator<Resource> keys = resprint.keySet().iterator(); + Iterator<Resource> keys = resprint.keySet().iterator(); while (keys.hasNext()){ Resource k = keys.next(); Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/TrainAndTestSet.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/TrainAndTestSet.java 2011-03-29 16:09:59 UTC (rev 2740) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/TrainAndTestSet.java 2011-03-31 06:34:17 UTC (rev 2741) @@ -23,6 +23,15 @@ public String[] getTestset() { return testset; } + + public TrainAndTestSet (String pdbID) { + String[] pdbIDs = {pdbID}; + this.trainset = pdbIDs; + } + + public TrainAndTestSet (String[] pdbIDs) { + this.trainset = pdbIDs; + } public TrainAndTestSet (int setsize) { @@ -50,8 +59,8 @@ } // lets create Train- and Testset - this.trainset = this.create_set(setsize, linenr); - this.testset = this.create_set(setsize, linenr); + this.trainset = this.createSet(setsize, linenr); + this.testset = this.createSet(setsize, linenr); } catch (MalformedURLException e) { // TODO Auto-generated catch block @@ -108,7 +117,7 @@ */ //creates Sets of PDB IDs equal to setsize - private String [] create_set(int setsize, int linenr){ + private String [] createSet(int setsize, int linenr){ String [] set = new String [setsize]; if (this.setentries == null) { this.setentries = new HashMap<Integer,String>(2*setsize); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |