comparison data_manager_gene_annotation/data_manager/data_manager.py @ 16:9002c2f64e2a draft

Uploaded
author scottx611x
date Wed, 22 Jun 2016 16:35:28 -0400
parents 6261b513ae1b
children 6a67977a23da
comparison
equal deleted inserted replaced
15:6261b513ae1b 16:9002c2f64e2a
28 28
29 args = parser.parse_args() 29 args = parser.parse_args()
30 30
31 31
32 def url_download(url, name, workdir): 32 def url_download(url, name, workdir):
33 # Create path if it doesn't exist
34 if not os.path.exists(workdir):
35 os.makedirs(workdir)
36 33
37 response = requests.get(url=url, stream=True) 34 response = requests.get(url=url, stream=True)
38 35
39 # Create path that we will write the file to 36 # Create path that we will write the file to
40 file_path = os.path.join(workdir, 'download_{}.dat'.format(name)) 37 file_path = 'download_{}.dat'.format(name)
41 38
42 block_size = 10 * 1024 * 1024 # 10MB chunked download 39 block_size = 10 * 1024 * 1024 # 10MB chunked download
43 with open(file_path, 'w+') as f: 40 with open(file_path, 'w+') as f:
44 try: 41 try:
45 for buf in response.iter_content(block_size): 42 for buf in response.iter_content(block_size):
54 51
55 def main(args): 52 def main(args):
56 workdir = os.path.join(os.getcwd(), 'gene_annotation') 53 workdir = os.path.join(os.getcwd(), 'gene_annotation')
57 54
58 # Attempt to download gene annotation file from given url 55 # Attempt to download gene annotation file from given url
59 gene_annotation_file_path = url_download(args.url, args.name, workdir) 56 gene_annotation_file_path = url_download("http://www.scott-ouellette.com/gene_annotations/chr1-hg19_genes.gtf", args.name, workdir)
60 57
61 # Update Data Manager Json and write out 58 # Update Data Manager Json and write out
62 data_manager_entry = { 59 data_manager_entry = {
63 'data_tables': { 60 'data_tables': {
64 'gene_annotation': { 61 'gene_annotation': {
65 'date': str(datetime.datetime.now()), 62 'date': str(datetime.datetime.now()),
66 'dbkey': str(args.name), 63 'dbkey': str(args.name),
67 'name': str(args.name), 64 'name': str(args.name),
68 'path': gene_annotation_file_path,
69 } 65 }
70 } 66 }
71 } 67 }
72 68
73 with open(os.path.join(workdir, args.output), "w+") as f: 69 with open(os.path.join(workdir, args.output), "w+") as f: