2
$\begingroup$

I'm looking to parse a large .sdf file and put it into a .csv file.

The only software I could find that parses .sdf files is OpenBabel's Pybel, but it won't properly install for my El Capitan, for either python2.7 or 3.+. (It's an open issue, and might hopefully be fixed with the next release). Are there any other languages/OSs that can easily parse this file? If there aren't any, is there a recommended operating system I could spin up with VirtualBox that will easily run OpenBabel/Pybel?

$\endgroup$
  • $\begingroup$ Instead of using python why not use Notepad++ or Atom (both free) to extract the data you want (using column select tool) or use their syntax to convert to csv. Alternatively you could write a small python prog just to read data you have. If you look at some .sdf files you will soon see that the way data is organised is very clear. $\endgroup$ – porphyrin Jul 13 '16 at 8:07
  • $\begingroup$ afaik, chemsketch has scripting capabilities. But it isn't opensource, just freeware. $\endgroup$ – permeakra Jul 13 '16 at 12:22
  • $\begingroup$ I'm not sure what "open issue" you indicate. I run Open Babel and Pybel all the time on El Capitan. Please contact me (or the Babel mailing list). As indicated below, there are many tools for parsing SD files. $\endgroup$ – Geoff Hutchison Jul 28 '16 at 15:54
1
$\begingroup$

The free, open-source RDKit chemoinformatics software can read .sdf files. This software is most often used via it's Python API.

You can learn more about RDKit at the project's home page.

I recommend installing it via conda. (If you use python regularly but don't use conda for controlling environments and package distribution, you probably should.) The installation command is conda install -c https://conda.anaconda.org/rdkit rdkit .

The python code to parse an sdf file and write to a csv file is very simple.

import pandas as pd
from rdkit import Chem
from rdkit.Chem import PandasTools


my_sdf_file = '/Users/curt/Desktop/sdf-isothiocyanates.sdf'

frame = PandasTools.LoadSDF(my_sdf_file,
                            smilesName='SMILES',
                            molColName='Molecule',
                            includeFingerprints=False)

frame.to_csv('/Users/curt/Desktop/excel_isothiocyanates.csv')
$\endgroup$
0
$\begingroup$

The .png below has some stand alone python that will read .sdf files and produce comma separated output. Its come out rather small but should still be readable. You can run the code from Atom on an apple mac or notepad++ on a pc.

sdf python page 1 sdf python image 2

$\endgroup$
0
$\begingroup$

You can also have a look at Bioclipse, which mixes a graphical interface with scripting (JavaScript, Python, and Groovy):

enter image description here

I blogged about an example script for Bioclipse before, which looks like:

hmdbIndex =
  molTable.createSDFIndex(
    "/WikiPathways/hmdb.sdf"
);
props = new java.util.HashSet();
props.add("HMDB_ID");
molTable.parseProperties(hmdbIndex, props);

idIndex = new java.util.HashMap();
molCount = hmdbIndex.getNumberOfMolecules();
for (i=0; i<molCount; i++) {
  hmdbID = hmdbIndex.getPropertyFor(i, "HMDB_ID")
  idIndex.put(hmdbID, i);
}

Bioclipse is developed by a team predominantly working on OS/X.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.