Skip to content

Instantly share code, notes, and snippets.

@mpkocher
Last active October 13, 2016 03:53
Show Gist options
  • Save mpkocher/21326a76b5b1ca7c27f82fc74fe4ea7b to your computer and use it in GitHub Desktop.
Save mpkocher/21326a76b5b1ca7c27f82fc74fe4ea7b to your computer and use it in GitHub Desktop.
Generate pbcommandr File Types code from pbcommand
from pbcommand.models import FileTypes
# Generate the pbcommandR file type definitions from the python code
# https://github.com/PacificBiosciences/pbcommandR/blob/master/R/common.R
def to_n(ext):
return ext.replace(".", '').replace("_", "")
def to_r(ft):
_d = dict(n=to_n(ft.ext), i=ft.file_type_id, b=ft.base_name, e=ft.ext, m=ft.mime_type)
return '{n} -> toF("{i}", "{b}", "{e}", "{m}")'.format(**_d)
def generate():
file_types = FileTypes.ALL().values()
code = "\n".join([to_r(x) for x in file_types])
names = [to_n(f.ext) for f in file_types]
xs = "return c(" + "\n,".join(["{m} = {n}".format(m=n.upper(), n=n) for n in names]) + ")"
return "\n\n".join([code, xs])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment