Exemple #1
0
def submitter(opener, filename, organism_name):
    print "Submitting %s data to RAST" % organism_name
    
    # page1 - MultipartForm
    form = http.MultiPartForm()
    form.add_field('page', 'UploadGenome')
    form.add_file('upload', filename, open(filename, "r"))
    request = urllib2.Request(BASE_URL)
    body = str(form)
    request.add_header('Content-type', form.get_content_type())
    request.add_header('Content-length', len(body))
    request.add_data(body)
    page1 = opener.open(request)
    
    # page2 - simple form
    page2_query_args = {'upload_file':'', 'contig_count':'', 'upload_type':'', 'bp_count':'', 'gc_content':'', 'ambig_count':'', 'upload_check':''}
    # These have to be parsed out of the previous page    
    page2_query_args = http.extractValues (page1, page2_query_args)
    page2_query_args['organism_name'] = organism_name
    page2_query_args['genetic_code'] = '11'
    page2_query_args['page'] = 'UploadGenome'
    page2_query_args['domain'] = 'Bacteria'
    page2_query_args['taxonomy_id'] = ''
    page2_query_args['lineage'] = ''
    page2_query_args['laststep'] = 'Use this data and go to step 3'
    page2_encoded_args = urllib.urlencode(page2_query_args)
    page2 = opener.open(BASE_URL, page2_encoded_args)
    
    # page3 - simple form
    page3_query_args = {'organism_name':'', 'upload_file':'', 'contig_count':'', 'upload_type':'', 'gc_content':'', 'upload_check':'', 'laststep':'', 'bp_count':'', 'ambig_count':''}
    # These have to be parsed out of the previous page    
    page3_query_args = http.extractValues(page2, page3_query_args)
    page3_query_args['genetic_code'] = '11'
    page3_query_args['page'] = 'UploadGenome'
    page3_query_args['domain'] = 'Bacteria'
    page3_query_args['taxonomy_id'] = ''
    page3_query_args['lineage'] = ''
    page3_query_args['sequencing_method'] = 'Sanger'
    page3_query_args['coverage'] = 'unknown'
    page3_query_args['contigs'] = 'unknown'
    page3_query_args['average_read_length'] = ''
    page3_query_args['gene_caller'] = 'rast'
    page3_query_args['fix_errors'] = '1'
    page3_query_args['backfill_gaps'] = '1'
    page3_query_args['finish'] = 'Finish the upload'
    page3_encoded_args = urllib.urlencode(page3_query_args)
    page3 = opener.open(BASE_URL, page3_encoded_args)
    
    for line in page3.readlines():
        if "href='?page=JobDetails&job=" in line:
            id = line.split("href='?page=JobDetails&job=")[1].split("'")[0]
    print "Submitted to RAST with job id %s" % id
    return id
Exemple #2
0
def submitter(opener, filename, common_name, id):
    print "Submitting %s data to IMG" % common_name
    
    # page 1
    page1_query_args = {'section': 'ERSubmission', 'page':'showERPage'}
    page1_encoded_args = urllib.urlencode(page1_query_args)
    opener.open(BASE_URL, page1_encoded_args)
    
    # page 2
    page2_query_args = {'p_type': 'G', 'database': 'IMG ER', 'search_sp:gold_stamp_id':id, '_section_ERSubmission:selectSubProj':'Search Projects'}
    page2_encoded_args = urllib.urlencode(page2_query_args)
    page2 = opener.open(BASE_URL, page2_encoded_args)
       
    # page 3
    page3_query_args = {'project_oid': ''}
    # extract project_oid from previous page
    page3_query_args = http.extractValues(page2, page3_query_args)
    page3_query_args['database'] = 'IMG ER' 
    page3_query_args['_section_ERSubmission:submitProject'] = 'Select Project' 
    page3_encoded_args = urllib.urlencode(page3_query_args)
    opener.open(BASE_URL, page3_encoded_args)
    
    project_oid = page3_query_args['project_oid']
    
    # page 4 - MultipartForm
    form = http.MultiPartForm()
    form.add_field('database', 'IMG ER')
    form.add_field('project_oid', project_oid)
    form.add_file('genbank_file', filename, open(filename, "r"))
    form.add_field('img_ec_flag', 'Yes')
    form.add_field('gene_calling_flag', 'GeneMark')
    form.add_field('img_product_flag', 'Yes')
    form.add_field('is_img_public', 'No')
    form.add_field('seq_status', 'Draft')
    form.add_field('species_code', common_name)
    form.add_field('_section_ERSubmission:checkSubmission', 'Submit')
    request = urllib2.Request(BASE_URL)
    body = str(form)
    request.add_header('Content-type', form.get_content_type())
    request.add_header('Content-length', len(body))
    request.add_data(body)
    page4 = opener.open(request)
    
    for line in page4.readlines():
        if '(submission ID: ' in line:
            submission_id = line.split('(submission ID: ')[1].split(')')[0]
    print "Submitted to IMG with submission id %s" % submission_id
    return submission_id