Skip to content

Instantly share code, notes, and snippets.

@Fxe
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save Fxe/0aa52eae77f13885b973 to your computer and use it in GitHub Desktop.

Select an option

Save Fxe/0aa52eae77f13885b973 to your computer and use it in GitHub Desktop.
KeggRest
package pt.uminho.sysbio.biosynth.chemsynth;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import pt.uminho.sysbio.biosynthframework.biodb.kegg.KeggCompoundMetaboliteEntity;
import pt.uminho.sysbio.biosynthframework.core.data.io.dao.biodb.kegg.AbstractRestfulKeggDao;
import pt.uminho.sysbio.biosynthframework.core.data.io.dao.biodb.kegg.RestKeggCompoundMetaboliteDaoImpl;
import pt.uminho.sysbio.biosynthframework.core.data.io.dao.biodb.kegg.RestKeggGeneDaoImpl;
import pt.uminho.sysbio.biosynthframework.core.data.io.dao.biodb.kegg.parser.AbstractKeggFlatFileParser;
import pt.uminho.sysbio.biosynthframework.core.data.io.dao.biodb.kegg.parser.KeggCompoundFlatFileParser;
import pt.uminho.sysbio.biosynthframework.util.BioSynthUtilsIO;
import me.fliu.silico.retrosilico.io.AtomMappingDao;
import me.fliu.silico.retrosilico.io.MdlMolDao;
import me.fliu.silico.retrosilico.io.dao.MetacycDatReactionDaoImpl;
import me.fliu.silico.retrosilico.io.dao.MetacycMdlMolDaoImpl;
import me.fliu.silico.retrosilico.sigmol.SscanProcess;
public class MetacycReactionComp {
public static final int H = 1;
public static final String METACYC_MOL_PATH = "D:/var/biodb/biocyc/META/mol/";
public static final String METACYC_MAP_PATH = "D:/var/atom.txt";
public static class KoParser extends AbstractKeggFlatFileParser {
public KoParser(String flatfile) {
super(flatfile);
// TODO Auto-generated constructor stub
this.parseContent();
}
public String getEntry() {
int tabIndex = this.getTabIndex("ENTRY");
String content = this.tabContent_.get(tabIndex);
return content;
}
public String getBrite() {
int tabIndex = this.getTabIndex("BRITE");
String content = this.tabContent_.get(tabIndex);
return content;
}
}
public static class TestRestDao extends AbstractRestfulKeggDao {
private static final String restCpdQuery = "http://rest.kegg.jp/get/cpd:%s";
// public void listSomething() {
// getLocalOrWeb(restQuery, localPath);
// }
public String getMetaboliteById(String id) {
String restCpdQuery = String.format("http://rest.kegg.jp/get/ko:%s", id);
String localPath = this.getLocalStorage() + "ko" + "/" + id;
String cpdFlatFile = null;
try {
cpdFlatFile = getLocalOrWeb(restCpdQuery, localPath + ".txt");
if (cpdFlatFile == null) return cpdFlatFile;
// System.out.println(drFlatFile);
} catch (IOException e) {
System.err.println(e.getMessage());
}
KoParser parser = new KoParser(cpdFlatFile);
System.out.println(parser.getEntry());
System.out.println(parser.getBrite());
//do parse
KeggCompoundFlatFileParser parser2 = new KeggCompoundFlatFileParser(cpdFlatFile);
//// System.out.println(parser.getTabs());
// KeggCompoundMetaboliteEntity cpd = new KeggCompoundMetaboliteEntity();
//
// cpd.setEntry(parser.getEntry());
// cpd.setName(parser.getName());
// cpd.setFormula(parser.getFormula());
// cpd.setMass(parser.getMass());
// cpd.setRemark(parser.getRemark());
// cpd.setComment(parser.getComment());
// if (cpdMolFile != null && !cpdMolFile.isEmpty() && !cpdMolFile.startsWith("null")) {
// cpd.setMol2d(cpdMolFile);
// }
// cpd.setCrossReferences(parser.getCrossReferences());
// cpd.setReactions(parser.getReactions());
// cpd.setEnzymes(parser.getEnzymes());
// cpd.setPathways(parser.getPathways());
return "";
}
public List<String> listSomething(String id) {
List<String> cpdIds = new ArrayList<>();
String restListDrQuery = String.format("http://rest.kegg.jp/%s/%s", "list", id);
String localPath = this.getLocalStorage() + "query" + "/" + id + ".txt";
// LOGGER.debug("LocalPath: " + localPath);
try {
String httpResponseString = getLocalOrWeb(restListDrQuery, localPath);
String[] httpResponseLine = httpResponseString.split("\n");
for ( int i = 0; i < httpResponseLine.length; i++) {
String[] values = httpResponseLine[i].split("\\t");
cpdIds.add(values[0].substring(3));
}
} catch (IOException e) {
System.err.println(e.getMessage());
}
return cpdIds;
}
}
public static void main(String[] args) {
SscanProcess sscan = new SscanProcess("D:/opt/scan/asscan.exe", new String[] {});
AtomMappingDao atomMappingDao = new MetacycDatReactionDaoImpl(METACYC_MAP_PATH);
MdlMolDao molDao = new MetacycMdlMolDaoImpl(METACYC_MOL_PATH);
RestKeggGeneDaoImpl daoImpl = new RestKeggGeneDaoImpl();
daoImpl.setLocalStorage("D:/var/biodb/kegg/");
daoImpl.setSaveLocalStorage(true);
daoImpl.setUseLocalStorage(true);
System.out.println(daoImpl.getAllGeneIds("hsa"));
TestRestDao implementeME = new TestRestDao();
implementeME.setLocalStorage("D:/var/biodb/kegg/");
implementeME.setSaveLocalStorage(true);
implementeME.setUseLocalStorage(true);
System.out.println(implementeME.listSomething("ko"));
implementeME.getMetaboliteById("K00010");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment