Exemple #1
0
def name2id(name, outformat):

  import cirpy
  import chemspipy
  import queryDevice  
  
  idstring = None
  source = None

  if idstring is None:
    source = 'NCI'
    idstring = cirpy.resolve(name, outformat)
  if idstring is None:
    source = 'ChemSpi'
    chemspid = chemspipy.find_one(name)
    try:
      smiles = chemspid.smiles
      idstring = cirpy.resolve(smiles, outformat)
    except AttributeError:
      idstring = None
  if idstring is None:
    source = 'NCI-pattern-match'
    idstring = cirpy.resolve(name, outformat,['name_pattern'])
  if idstring is None:
    source = None
    idstring = str(idstring)
  try: 
    idstring = (idstring.rstrip(),source)
  except AttributeError:
    idstring  = (idstring[0].rstrip(),source)
    print 'There were multiple results for: ', name, ' using: ', idstring[0], '\n', idstring 

  return idstring
#!/usr/bin/env python

# from:
# http://blog.matt-swain.com/post/16893587098/chemspipy-a-python-wrapper-for-the-chemspider-api

import chemspipy
import re, sys

if len(sys.argv) != 2:
  print 'usage : molecule_name.py <search string>'
  sys.exit(1)

search = sys.argv[1]
c = chemspipy.find_one(search)

try:
  name = c.commonname
except AttributeError:
  name = 0
print name

Exemple #3
0
with open('E coli core.core metabolism.json', 'r') as f:
    core_map = json.load(f)

# only look at primary metabolites
nodes = {k: node for k, node in core_map[1]['nodes'].iteritems()
         if node['node_type'] == 'metabolite' and node['node_is_primary'] is True}
print 'searching for {} structures'.format(len(nodes))

for k, node in nodes.iteritems():
    # check for img
    structure_path = join(structures_dir, '{}.png'.format(remove_compartment(node['bigg_id'])))
    if exists(structure_path):
        print 'Structure image already downloaded: {}'.format(structure_path)
        continue

    # search for the formula
    chem = chemspipy.find_one(node['name'])
    if not chem:
        print 'could not find match for {}'.format(node['name'])
        continue

    # convert to transparent
    image = Image.open(StringIO(b64decode(chem.image)))
    image = image.convert('RGBA')
    new_data = [x if x[:3] != (255, 255, 255) else (255, 255, 255, 0) for x in image.getdata()]
    image.putdata(new_data)

    # save the image
    print 'Found structure for {}. Saving to {}'.format(node['name'], structure_path)
    image.save(structure_path, "PNG")
Exemple #4
0
#import getopt
#opts = getopt.getopt(sys.argv[1])


class Logger(object):
    def __init__(self, filename="Default.log"):
        self.terminal = sys.stdout
        self.log = open(filename, "a")

    def write(self, message):
        self.terminal.write(message)
        self.log.write(message)


sys.stdout = Logger("log.txt")

cos = sys.argv[1]
name = sys.argv[2]

try:
    chemspipy.find_one(name)
except AttributeError:
    print("%s\t" % (cos))
else:
    c_1 = chemspipy.find_one(name)
    if c_1:
        print("%s\t%s\t%s\t%s\t%s\t%s" %
              (cos, name, c_1.smiles, c_1.inchi, c_1.inchikey, c_1.commonname))
    else:
        print("%s\t" % (cos))
Exemple #5
0
import chemspipy
import sys
import fileinput

terms = []

print "Enter your search terms, one per line. When done, hit  Crtl+D on an empty line to start the search."

for line in fileinput.input():
    if len(line.strip()) > 0:
        terms.append(line.strip())
    pass

for term in terms:
    d = {}
    c = chemspipy.find_one(term)
    if not c:
        continue
    d["imageurl"] = c.imageurl
    d["mf"] = c.mf
    d["smiles"] = c.smiles
    d["inchi"] = c.inchi
    d["inchikey"] = c.inchikey
    d["averagemass"] = c.averagemass
    d["molecularweight"] = c.molecularweight
    d["monoisotopicmass"] = c.monoisotopicmass
    d["nominalmass"] = c.nominalmass
    d["alogp"] = c.alogp
    d["xlogp"] = c.xlogp
    d["commonname"] = c.commonname
    #d["image"] = c.image
import chemspipy
import re
import sys

if len(sys.argv) == 1:
	indfilnavn = raw_input("Filnavn med stoffer? >")
else:
	indfilnavn = sys.argv[1]
	
fjern = re.compile('[^a-zA-Z0-9]')
print("Stof\tSumformel\tMonoisotopicmass")
 
with open(indfilnavn) as f:
	for line in f:
		c = chemspipy.find_one(line)
		print line.strip(), "\t", re.sub(fjern, '', c.mf) , "\t", c.monoisotopicmass