Ipynb idioms: Difference between revisions

From DISI
Jump to navigation Jump to search
No edit summary
(asdf)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
These are idioms for iPython Notebooks, also generally python.  
These are idioms for iPython Notebooks, also generally python.  
 
{{TOCright}}


== top of every ipynb ==
== top of every ipynb ==
Line 9: Line 9:
  import urllib
  import urllib


== set up variables for webapi ==
== set up to use ZINC API ==
(hint ask john for credentials)
(hint ask john for credentials)
  urlroot = 'http://x.ucsf.bkslab.org:y'
  urlroot = 'http://zinc15.docking.org'
  format = 'txt'
  format = 'txt'


== execute a command, with optional limits ==
R = requests.get(cmd + '?count=10000')
lines = list(R.iter_lines())
print len(lines)
print R.text
== setup ==
from rdkit.Chem.Draw import IPythonConsole
import rdkit.Chem.Draw as D
import rdkit.Chem as C
import rdkit.Chem.Descriptors as CD
from rdkit.Chem import SmilesMolSupplier
== activate zinc api ==
import zinc.api
api=zinc.api.make_api()
== Display mols ==
path = '/nfs/home/jji/ipynb/data/test.smi'
mols = SmilesMolSupplier(path, titleLine=False)
D.MolsToGridImage( mols, legends=[m.GetProp('_Name') for m in mols])
== drill down on mol ==
s1 =api.substances.get(110341849)
[(ci.supplier_code,ci.catalog.name) for ci in s1.catalog_items]
== stuff about sets ==
from sets import Set
https://docs.python.org/2/library/sets.html
employees = engineers | programmers | managers          # union
engineering_management = engineers & managers            # intersection
fulltime_management = managers - engineers - programmers # difference
engineers.add('Marvin')                                  # add element
== working with results==
cmd3 = urlroot + '/' + table1 + '/txt:best_purchasable,best_catalog/substance.sub_id={0}'
cmd4 = urlroot + '/' + table1 + '/txt:best_purchasable,best_catalog/substance.sub_id in {0}'
def getPurchasability(sub_id):
    R1 = requests.get(cmd3.format(sub_id))
    purch,cat = R1.text.splitlines()[1].split('\t')
    return int(purch),cat
def getPurchasability2(*sub_ids):
    R1 = requests.get(cmd4.format(','.join(map(str, sub_ids))))
    data_lines = [line.split('\t') for line in R1.text.splitlines()[1:]]
    print data_lines
    return [(int(purch), cat) for purch, cat in data_lines]
def to_sub_id(zinc_id):
    return int(zinc_id.lower().replace('zinc', ''))


[[Category:webapi]]
[[Category:ZINC15]]
[[Category:ZINC]]
[[Category:Idioms]]
[[Category:Idioms]]

Latest revision as of 23:30, 1 October 2015

These are idioms for iPython Notebooks, also generally python.

top of every ipynb

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import requests
import urllib

set up to use ZINC API

(hint ask john for credentials)

urlroot = 'http://zinc15.docking.org'
format = 'txt'

execute a command, with optional limits

R = requests.get(cmd + '?count=10000')
lines = list(R.iter_lines())
print len(lines)
print R.text

setup

from rdkit.Chem.Draw import IPythonConsole
import rdkit.Chem.Draw as D
import rdkit.Chem as C
import rdkit.Chem.Descriptors as CD
from rdkit.Chem import SmilesMolSupplier

activate zinc api

import zinc.api
api=zinc.api.make_api()

Display mols

path = '/nfs/home/jji/ipynb/data/test.smi'
mols = SmilesMolSupplier(path, titleLine=False)
D.MolsToGridImage( mols, legends=[m.GetProp('_Name') for m in mols])

drill down on mol

s1 =api.substances.get(110341849)
[(ci.supplier_code,ci.catalog.name) for ci in s1.catalog_items]

stuff about sets

from sets import Set

https://docs.python.org/2/library/sets.html

employees = engineers | programmers | managers           # union
engineering_management = engineers & managers            # intersection
fulltime_management = managers - engineers - programmers # difference
engineers.add('Marvin')                                  # add element


working with results

cmd3 = urlroot + '/' + table1 + '/txt:best_purchasable,best_catalog/substance.sub_id={0}'
cmd4 = urlroot + '/' + table1 + '/txt:best_purchasable,best_catalog/substance.sub_id in {0}'
def getPurchasability(sub_id):
   R1 = requests.get(cmd3.format(sub_id))
   purch,cat = R1.text.splitlines()[1].split('\t')
   return int(purch),cat
def getPurchasability2(*sub_ids):
   R1 = requests.get(cmd4.format(','.join(map(str, sub_ids))))
   data_lines = [line.split('\t') for line in R1.text.splitlines()[1:]]
   print data_lines
   return [(int(purch), cat) for purch, cat in data_lines]
def to_sub_id(zinc_id):
   return int(zinc_id.lower().replace('zinc', ))