package org.wikipathways.wp2rdf;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;

import org.bridgedb.bio.Organism;
import org.pathvisio.core.model.ConverterException;
import org.pathvisio.core.model.Pathway;
import org.pathvisio.wikipathways.webservice.WSPathwayInfo;
import org.wikipathways.client.WikiPathwaysClient;
import org.wikipathways.wp2rdf.utils.Utils;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class WPREST2RDF {

	public static void main(String[] args) throws NumberFormatException, ConverterException, IOException {
		URL url = new URL("http://webservice.wikipathways.org");
		WikiPathwaysClient client = new WikiPathwaysClient(url);
		
		WSPathwayInfo [] pathways = client.listPathways(Organism.ArabidopsisThaliana);
		for(WSPathwayInfo i : pathways) {
			System.out.println(i.getId() + "\t" + i.getRevision());
			
			File output = new File("resources/testcollection/" + i.getId() +".ttl");
			
			Model pathwayModel = ModelFactory.createDefaultModel();
			Utils.setModelPrefix(pathwayModel);
			
			Pathway p = WikiPathwaysClient.toPathway(client.getPathway(i.getId(), Integer.parseInt(i.getRevision())));

			// New conversion of the pathway in GPML vocabulary
			GpmlConverter.convertGpml(p, i.getId(), i.getRevision(), pathwayModel);
			
			// New conversion of the pathway in WP vocabulary
			GpmlConverter.convertWp(p, i.getId(), i.getRevision(), pathwayModel);
			
			pathwayModel.write(new FileWriter(output), "TURTLE");
		}
	}

}

@@ -123,16 +123,64 @@
 net.URL;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0Aimport
@@ -571,16 +571,45 @@
 2RDF %7B%0A%0A
+%09@SuppressWarnings(%22serial%22)%0A
 %09public 
@@ -822,19 +822,200 @@
 t(url);%0A
+%0A
 %09%09
-%0A
+Map%3COrganism,String%3E species = new HashMap%3COrganism,String%3E() %7B%7B%0A%09%09%09put(Organism.ArabidopsisThaliana, %22arabidopsisthaliana%22);%0A%09%09%7D%7D;%0A%0A%09%09for (Organism organism : species.keySet()) %7B%0A%09
 %09%09WSPath
@@ -1060,39 +1060,20 @@
 ays(
-O
+o
 rganism
-.ArabidopsisThaliana
 );%0A
+%09
 %09%09fo
@@ -1104,16 +1104,17 @@
 ways) %7B%0A
+%09
 %09%09%09Syste
@@ -1168,92 +1168,10 @@
 ));%0A
-%09%09%09
 %0A%09
-%09%09File output = new File(%22resources/testcollection/%22 + i.getId() +%22.ttl%22);%0A%09%09%09%0A
 %09%09%09M
@@ -1228,16 +1228,17 @@
 l();%0A%09%09%09
+%09
 Utils.se
@@ -1265,20 +1265,18 @@
 Model);%0A
-%09%09%09
 %0A
+%09
 %09%09%09Pathw
@@ -1377,24 +1377,25 @@
 n())));%0A%0A%09%09%09
+%09
 // New conve
@@ -1426,32 +1426,33 @@
 GPML vocabulary%0A
+%09
 %09%09%09GpmlConverter
@@ -1514,65 +1514,386 @@
 l);%0A
+%0A
 %09%09%09
-%0A%09%09%09// New conversion of the pathway in WP vocabulary%0A
+%09String folder = %22output/gpml/%22 + species.get(organism) + %22/%22;%0A%09%09%09%09new File(folder).mkdirs();%0A%09%09%09%09FileWriter output = new FileWriter(folder + i.getId() +%22.ttl%22);%0A%09%09%09%09pathwayModel.write(output, %22TURTLE%22);%0A%09%09%09%09output.close();%0A%0A%09%09%09%09// New conversion of the pathway in WP vocabulary%0A%09%09%09%09pathwayModel = ModelFactory.createDefaultModel();%0A%09%09%09%09Utils.setModelPrefix(pathwayModel);%0A%09
 %09%09%09G
@@ -1965,56 +1965,183 @@
 l);%0A
+%0A
 %09%09%09
-%0A%09%09%09pathwayModel.write(new FileWriter
+%09folder = %22output/wp/%22 + species.get(organism) + %22/%22;%0A%09%09%09%09new File(folder).mkdirs();%0A%09%09%09%09output = new FileWriter(folder + i.getId() +%22.ttl%22);%0A%09%09%09%09pathwayModel.write
 (output
-)
 , %22T
@@ -2149,16 +2149,41 @@
 RTLE%22);%0A
+%09%09%09%09output.close();%0A%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%0A

Generalized the WP generation code.