Source code for

downloads a .2bit genome from UCSC
.. note:: please comply with the restrictions of use at

and do not over-use this module

By default, genomes are saved to the current directory
from urllib2 import urlopen, URLError
from shutil import copyfileobj
from os.path import exists, join
from os import getcwd

[docs]def save_genome(name, destdir=None, mode='ftp'): """ tries to download a genome from UCSC by name for example, 'hg19' is at """ urlpath = "%s://" % \ (mode, name, name) if destdir is None: destdir = getcwd() remotefile = urlopen(urlpath) assert exists(destdir), 'Desination directory %s does not exist' % destdir with open(join(destdir,"%s.2bit" % name), 'wb') as destfile: copyfileobj(remotefile, destfile) return
def main(): import sys if len(sys.argv)!=2: sys.exit('Example: python -m hg19') else: save_genome(sys.argv[1]) if __name__ == '__main__': main()