Skip to content

Instantly share code, notes, and snippets.

View zakandrewking's full-sized avatar

Zak King zakandrewking

View GitHub Profile
Visual Studio Code (1.76.1, undefined, desktop)
Jupyter Extension Version: 2023.2.1200692131.
Python Extension Version: 2023.4.1.
Workspace folder /Users/zak/repos/test
warn 13:48:48.940: Exception while attempting zmq : No native build was found for platform=darwin arch=arm64 runtime=electron abi=106 uv=1 armv=8 libc=glibc node=16.14.2 electron=19.1.11
loaded from: /Users/zak/.vscode/extensions/ms-toolsai.jupyter-2023.2.1200692131/out/node_modules/zeromq
User belongs to experiment group 'jupyterEnhancedDataViewer'
User belongs to experiment group 'jupyterTest'
debug 13:48:49.017: Updating cache with Python kernels
import contextlib
import os
import sys
# Suppress stdout http://stackoverflow.com/a/17753573
class DummyFile(object):
def write(self, x): pass
@contextlib.contextmanager
def no_stdout(std_channel, dest_filename):
old_std_channel = os.dup(std_channel.fileno())
@zakandrewking
zakandrewking / advanced_search_scrape.py
Last active May 29, 2023 11:26
Get BiGG compounds for KEGG IDs from BiGG Models
import requests
import re
response = requests.post(
'http://bigg.ucsd.edu/advanced_search_external_id_results',
data={'database_source': 'kegg.compound', 'query': 'C00234'}
)
try:
print re.search(r'/models/universal/metabolites/([^"]+)', response.text).group(1)
# inputs
# model, old_gene, new_gene
for reaction in model.genes.get_by_id(old_gene).reactions:
reaction.gene_reaction_rule = re.sub(r'\b' + old_gene + r'\b', new_gene,
reaction.gene_reaction_rule)
remove_genes(model, [g for g in model.genes if len(g.reactions) == 0])
@zakandrewking
zakandrewking / serve.sh
Created November 15, 2014 03:25
SimpleHTTPServer for UTF-8
# http://stackoverflow.com/questions/15288891/how-can-i-serve-files-with-utf-8-encoding-using-python-simplehttpserver
python -c "import SimpleHTTPServer; m = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map; m[''] = 'text/plain'; m.update(dict([(k, v + ';charset=UTF-8') for k, v in m.items()])); SimpleHTTPServer.test();"
diff <(jq -S '.' s_cerevisiae.iMM904.all_reactions.json) <(jq '.' 2007179_map.json -S) | less
@zakandrewking
zakandrewking / .ctags.bad
Last active August 29, 2015 14:06
etags.sh for windows
# http://ck.kennt-wayne.de/2013/sep/emacs-using-ctags-for-javascript-and-rails
--langdef=js
--langmap=js:.js
--regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\{/\1/,object/
--regex-js=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/,function/
--regex-js=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*\(([^)])\)/\1/,function/
--regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\[/\1/,array/
--regex-js=/([^= ]+)[ \t]*=[ \t]*[^"]'[^']*/\1/,string/
--regex-js=/([^= ]+)[ \t]*=[ \t]*[^']"[^"]*/\1/,string/
@zakandrewking
zakandrewking / post-checkout
Last active August 29, 2015 14:06
etags for javascript and python, with some ignores
#!/bin/bash
# Put this in .git/hooks/post-checkout, and chmod +x
/Users/zaking/.emacs.d/etags.sh -js -py -!/bin/ -!/lib/ -!escher.*
tax_id Org_name GeneID CurrentID Status Symbol Aliases description other_designations map_location chromosome genomic_nucleotide_accession.version start_position_on_the_genomic_accession end_position_on_the_genomic_accession orientation exon_count OMIM
511145 Escherichia coli str. K-12 substr. MG1655 5625560 0 live aaaD b4634ECK4439, ylcF pseudo NC_000913.3 581354 581662 plus 0
511145 Escherichia coli str. K-12 substr. MG1655 7751645 0 live aaaE b4693ECK1135, JW1135, ymfN pseudo NC_000913.3 1204404 1205537 plus 0
511145 Escherichia coli str. K-12 substr. MG1655 947748 0 live aaeA b3241ECK3230, JW3210, yhcQ p-hydroxybenzoic acid efflux system component NC_000913.3 3388194 3389126 minus 0
511145 Escherichia coli str. K-12 substr. MG1655 947747 0 live aaeB b3240ECK3229, JW3209, yhcP p-hydroxybenzoic acid efflux system component NC_000913.3 3386221 3388188 minus 0
511145 Escherichia coli str. K-12 substr. MG1655 947760 0 live aaeR b3243ECK3232, JW3212, qseA, yhcS transcriptional regulator for
import json
# save a single flux vector as JSON
flux_dictionary = {'asdf': 2}
with open('out.json', 'w') as f:
json.dump(flux_dictionary, f)
flux_dictionary = {'asdf': 2}
# save a flux comparison as JSON
flux_comp = [{'GAPD': 3}, {'GAPD': 4}]