Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package dl.tmp;
 
 import java.io.File;
public class ChebiSDFExtractor {
	public static void main(String[] argsthrows Exception {
		File f1 =new File("C:/My Documents/OPSIN/resources/ChEBI_complete_4th_July.sdf");
		FileWriter fosmi =new FileWriter(new File("C:/My Documents/OPSIN/resources/chebismiles.txt"));
		FileWriter foinchi =new FileWriter(new File("C:/My Documents/OPSIN/resources/chebiInChI.txt"));
		FileWriter fonames =new FileWriter(new File("C:/My Documents/OPSIN/resources/chebiIUPACnames.txt"));
		BufferedReader compoundsFile = new BufferedReader(new InputStreamReader(new FileInputStream(f1)));
		String cLine=compoundsFile.readLine();
		HashMap<StringList<String>> compoundInformation =new HashMap<String,List<String>>();
		while(cLine != null) {
			if("> <SMILES>".equals(cLine)) {
				cLine = compoundsFile.readLine();
				List<Stringsmiles = new ArrayList<String>();
				smiles.add(cLine);
				compoundInformation.put("SMILES"smiles);
			}
			if("> <InChI>".equals(cLine)) {
				cLine = compoundsFile.readLine();
				List<Stringinchi = new ArrayList<String>();
				inchi.add(cLine);
				compoundInformation.put("InChI"inchi);
			}
			if("> <IUPAC Names>".equals(cLine)) {
				cLine = compoundsFile.readLine();
				List<Stringnames = new ArrayList<String>();
				while (!cLine.equals("")){
					names.add(cLine);
					cLine = compoundsFile.readLine();
				}
				compoundInformation.put("IUPAC_Names"names);
			}
			else if("$$$$".equals(cLine)) {
				if (compoundInformation.get("IUPAC_Names")!=null && compoundInformation.get("SMILES")!=null  && compoundInformation.get("InChI")!=null){
					for (String name : compoundInformation.get("IUPAC_Names")) {
						fonames.write(name +"\t" +compoundInformation.get("InChI").get(0)+"\n");
						foinchi.write(compoundInformation.get("InChI").get(0) +"\n");
						fosmi.write(compoundInformation.get("SMILES").get(0)+"\n");
					}
				}	
				compoundInformation =new HashMap<String,List<String>>();
			}
			cLine = compoundsFile.readLine();
		}
		fosmi.close();
		fonames.close();
		foinchi.close();
	}
New to GrepCode? Check out our FAQ X