comparison get_pubchem/get_pubchem_as_smiles.py @ 3:021f0ef9474f draft

Uploaded
author bgruening
date Wed, 18 Sep 2013 09:44:36 -0400
parents b65518a007fa
children 7c1f9962ac07
comparison
equal deleted inserted replaced
2:b65518a007fa 3:021f0ef9474f
27 27
28 result = pool.map_async(fetch_convert, filenames) 28 result = pool.map_async(fetch_convert, filenames)
29 result.get() 29 result.get()
30 30
31 for filename in os.listdir(td): 31 for filename in os.listdir(td):
32 path = os.path.join(td, filename) 32 path = os.path.join(td, filename) + '.smi'
33 shutil.copyfileobj(open(path, 'rb'), output_handle) 33 shutil.copyfileobj(open(path, 'rb'), output_handle)
34 34
35 output_handle.close() 35 output_handle.close()
36 shutil.rmtree( td ) 36 shutil.rmtree( td )
37 37
38 def fetch_convert(args): 38 def fetch_convert(args):
39 (filename, td) = args 39 (filename, td) = args
40 40
41 tmp_name = os.path.join( tempfile.gettempdir(), filename) 41 tmp_name = os.path.join( td, filename)
42 subprocess.call( ['wget', '-O', tmp_name, os.path.join('ftp://ftp.ncbi.nih.gov/pubchem/Compound/CURRENT-Full/SDF/', filename)] ) 42 subprocess.call( ['wget', '-O', tmp_name, os.path.join('ftp://ftp.ncbi.nih.gov/pubchem/Compound/CURRENT-Full/SDF/', filename)] )
43 output = os.path.join(td, filename) 43 output = os.path.join(td, filename) + '.smi'
44 subprocess.call(["obabel", "-isdf", tmp_name, "-ocan", '-O', output]) 44 subprocess.call(["obabel", "-isdf", tmp_name, "-ocan", '-O', output])
45 os.remove(tmp_name) 45 os.remove(tmp_name)
46 46
47 47
48 if __name__ == '__main__': 48 if __name__ == '__main__':