# HG changeset patch # User iuc # Date 1634659034 0 # Node ID 26ccb678abc856c5ca46c588b1d2613db2a7c483 # Parent 59bb6d34fca626359f0fedd6976980f84aa0e9d1 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ba358013c83e7dfffec895946d36585f237e54c5" diff -r 59bb6d34fca6 -r 26ccb678abc8 check_remote.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_remote.py Tue Oct 19 15:57:14 2021 +0000 @@ -0,0 +1,23 @@ +import json + +import requests + +URL = "https://www.ebi.ac.uk/ena/portal/api/search" + + +def check_remote_entry(entry_type, query_dict, out_format='json'): + ''' + Checks if an entry with that alias exists in the ENA repos + entry_type = [study | sample | experiment | run] + ''' + assert entry_type in ['study', 'sample', 'experiment', 'run'] + params_dict = {} + query_str = ' AND '.join(['%s=%s' % (key, value) for (key, value) in query_dict.items()]) + params_dict['query'] = query_str + params_dict['result'] = 'read_' + entry_type + params_dict['fields'] = entry_type + '_alias' + params_dict['format'] = out_format + response = requests.post(URL, data=params_dict) + if response.content != b'': + return json.loads(response.content) + return [] diff -r 59bb6d34fca6 -r 26ccb678abc8 ena_upload.xml --- a/ena_upload.xml Wed Aug 18 19:42:49 2021 +0000 +++ b/ena_upload.xml Tue Oct 19 15:57:14 2021 +0000 @@ -1,6 +1,6 @@ - + - 0.3.1 + 0.4.1 samples_macros.xml @@ -33,6 +33,9 @@ #if $action_options.input_format_conditional.viral_submission == "true": --vir #end if + #if $action_options.test_submit_parameters.submit_dev == "true": + --dev + #end if --action '$action_options.action' --form '$action_options.input_format_conditional.xlsx_file' --out_dir ./submission_files --verbose > '$output'; #end if @@ -84,7 +87,26 @@ #for $run in $experiment.rep_runs: #for $file in $run.upload_files: #set $safename_reads_file = re.sub('[^\w\-_\.]', '_', $file.element_identifier) - ln -s '$file' $safename_reads_file && + #if $action_options.input_format_conditional.add_extension == "true": + #set $extension = '.fastq' + #else + #set $extension = '' + #end if + #if $file.is_of_type('fastq', 'fastqsanger'): + ## compression output is defined as safename_reads_file so no need to symlink + #set $safename_reads_file = $safename_reads_file + $extension + '.gz' + gzip -c '$file' > $safename_reads_file && + #else: + #if $action_options.input_format_conditional.add_extension == "true": + #if $file.is_of_type('fastq.gz', 'fastqsanger.gz'): + #set $compression = '.gz' + #elif $file.is_of_type('fastqsanger.bz2', 'fastq.bz2'): + #set $compression = '.bz2' + #end if + #set $safename_reads_file = $safename_reads_file + $extension + $compression + #end if + ln -s '$file' $safename_reads_file && + #end if $files_to_upload.append(str($safename_reads_file)) #end for #end for @@ -95,31 +117,61 @@ #if $action_options.input_format_conditional.run_input_format_conditional.run_input_format == 'paired_list': #for $pair in $action_options.input_format_conditional.run_input_format_conditional.paired_end_collection: #set $safename_reads_file = re.sub('[^\w\-_\.]', '_', $pair.name) - #if $pair.forward.is_of_type('fastq.gz', 'fastqsanger.gz'): - #set $safename_fwd_reads_file = $safename_reads_file + '_1.fastq.gz' - #elif $pair.forward.is_of_type('fastqsanger.bz2', 'fastq.bz2'): - #set $safename_fwd_reads_file = $safename_reads_file + '_1.fastq.bz2' - #else: - #set $safename_fwd_reads_file = $safename_reads_file + '_1.fastq' - #end if - #if $pair.reverse.is_of_type('fastq.gz', 'fastqsanger.gz'): - #set $safename_rev_reads_file = $safename_reads_file + '_2.fastq.gz' - #elif $pair.reverse.is_of_type('fastqsanger.bz2', 'fastq.bz2'): - #set $safename_rev_reads_file = $safename_reads_file + '_2.fastq.bz2' - #else: - #set $safename_rev_reads_file = $safename_reads_file + '_2.fastq' + ## Always need to add .fastq + compression suffix because the name is based on the pair name which has no extensions + #if $pair.forward.is_of_type('fastq', 'fastqsanger'): + ## compress the file, no need to create the link then + ## always add the compression suffix (.gz) + #set $safename_fwd_reads_file = $safename_reads_file + '_1' + 'fastq' + '.gz' + gzip -c '$file' > $safename_fwd_reads_file && + #else + #if $pair.forward.is_of_type('fastq.gz', 'fastqsanger.gz'): + #set $compression = '.gz' + #elif $pair.forward.is_of_type('fastqsanger.bz2', 'fastq.bz2'): + #set $compression = '.bz2' + #end if + #set $safename_fwd_reads_file = $safename_reads_file + '_1' + '.fastq' + $compression + ln -s '$pair.forward' $safename_fwd_reads_file && #end if - ln -s '$pair.forward' $safename_fwd_reads_file && + #if $pair.reverse.is_of_type('fastq', 'fastqsanger'): + ## compress the file, no need to create the link then + #set $safename_reverse_reads_file = $safename_reads_file + '_1' + '.fastq' + '.gz' + gzip -c '$file' > $safename_rev_reads_file && + #else + #if $pair.reverse.is_of_type('fastqsanger.bz2', 'fastq.bz2'): + #set $compression = '.bz2' + #elif $pair.reverse.is_of_type('fastqsanger.gz', 'fastq.gz'): + #set $compression = '.gz' + #end if + #set $safename_rev_reads_file = $safename_reads_file + '_2' + '.fastq' + $compression + ln -s '$pair.reverse' $safename_rev_reads_file && + #end if $files_to_upload.append(str($safename_fwd_reads_file)) - ln -s '$pair.reverse' $safename_rev_reads_file && $files_to_upload.append(str($safename_rev_reads_file)) #end for #end if #if $action_options.input_format_conditional.run_input_format_conditional.run_input_format == 'multiple_selection_list': #for $file in $action_options.input_format_conditional.run_input_format_conditional.data: #set $safename_reads_file = re.sub('[^\w\-_\.]', '_', $file.element_identifier) - ln -s '$file' $safename_reads_file && + #if $file.is_of_type('fastq', 'fastqsanger'): + ## always compress add the gz extension + #if $action_options.input_format_conditional.run_input_format_conditional.add_extension == "true": + #set $safename_reads_file = $safename_reads_file + 'fastq.gz' + #else + #set $safename_reads_file = $safename_reads_file + '.gz' + #end if + gzip -c '$file' > $safename_reads_file && + #else + #if $action_options.input_format_conditional.run_input_format_conditional.add_extension == "true": + #if $file.is_of_type('fastq.gz', 'fastqsanger.gz'): + #set $extension = 'fastq.gz' + #elif $file.is_of_type('fastqsanger.bz2', 'fastq.bz2'): + #set $extension = 'fastq.bz2' + #end if + #set $safename_reads_file = $safename_reads_file + $extension + #end if + ln -s '$file' $safename_reads_file && + #end if $files_to_upload.append(str($safename_reads_file)) #end for #end if @@ -127,6 +179,7 @@ #if $action_options.test_submit_parameters.dry_run == "false": +#if $action_options.action == "add": ena-upload-cli --tool 'ena-upload-cli v@VERSION@ @ Galaxy' --action '$action_options.action' @@ -136,22 +189,23 @@ #for $dataset in $files_to_upload: '$dataset' #end for +--action add --experiment '$experiments_table_path' --study '$studies_table_path' --run '$runs_table_path' --sample '$samples_table_path' #if $action_options.input_format_conditional.input_format == "user_generated_tables": #if "$action_options.input_format_conditional.viral_submission" == "true": - --vir + --checklist ERC000033 #end if #else: #if $action_options.input_format_conditional.input_format == "build_tables": #if $action_options.input_format_conditional.conditional_viral_metadata.viral_sample == "true": - --vir + --checklist ERC000033 #end if #else: #if $action_options.input_format_conditional.viral_submission == "true": - --vir + --checklist ERC000033 #end if #end if #end if @@ -160,6 +214,40 @@ -d #end if >> '$output'; +#end if + +#if $action_options.action == "modify": + ena-upload-cli + --tool 'ena-upload-cli v@VERSION@ @ Galaxy' + --action '$action_options.action' + --center '$action_options.center' + --secret \${credentials_path} + --data + #for $dataset in $files_to_upload: + '$dataset' + #end for +--action 'modify' +--experiment '$experiments_table_path' +--study '$studies_table_path' +--run '$runs_table_path' +--sample '$samples_table_path' +#if $action_options.input_format_conditional.input_format == "user_generated_tables": + #if "$action_options.input_format_conditional.viral_submission" == "true": + --checklist ERC000033 + #end if +#else: + #if $action_options.input_format_conditional.input_format == "build_tables": + #if $action_options.input_format_conditional.conditional_viral_metadata.viral_sample == "true": + --checklist ERC000033 + #end if + #else: + #if $action_options.input_format_conditional.viral_submission == "true": + --checklist ERC000033 + #end if + #end if +#end if + >> '$output'; +#end if echo -e 'center_name\t$action_options.center' >> '$output'; echo -e 'action_option\t$action_options.action' >> '$output'; #if $action_options.input_format_conditional.input_format != "user_generated_tables": @@ -232,6 +320,7 @@ + @@ -252,7 +341,7 @@ - + @@ -265,6 +354,7 @@ + @@ -276,7 +366,7 @@ - + @@ -284,14 +374,13 @@ - + - @@ -299,11 +388,11 @@ - + - + @@ -316,6 +405,7 @@ + @@ -327,7 +417,7 @@ - + @@ -335,14 +425,13 @@ - + - @@ -350,11 +439,11 @@ - + - + @@ -367,6 +456,7 @@ + @@ -399,11 +489,11 @@ - + - + @@ -412,6 +502,7 @@ + @@ -437,7 +528,7 @@ - + @@ -447,6 +538,7 @@ + @@ -507,7 +599,7 @@ - + @@ -517,6 +609,7 @@ + @@ -554,7 +647,8 @@ - + @@ -564,6 +658,7 @@ + @@ -590,7 +685,7 @@ - + @@ -601,14 +696,15 @@ - + + - + @@ -618,6 +714,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + @@ -654,7 +817,7 @@ - + @@ -665,9 +828,10 @@ - - - + + + + diff -r 59bb6d34fca6 -r 26ccb678abc8 process_xlsx.py --- a/process_xlsx.py Wed Aug 18 19:42:49 2021 +0000 +++ b/process_xlsx.py Tue Oct 19 15:57:14 2021 +0000 @@ -4,11 +4,24 @@ import xlrd import yaml +from check_remote import check_remote_entry from mappings import optional_samples_cols_mapping FILE_FORMAT = 'fastq' +def identify_action(entry_type, alias): + ''' define action ['add' | 'modify'] that needs to be perfomed for this entry ''' + query = {entry_type + '_alias': alias} + remote_accessions = check_remote_entry(entry_type, query) + if len(remote_accessions) > 0: + print(f'Found: {entry_type} entry with alias {alias}') + return 'modify' + else: + print(f'No {entry_type} entry found with alias {alias}') + return 'add' + + def extract_data(xl_sheet, expected_columns, optional_cols=None): """ 1. Check that the columns I expect are present in the sheet @@ -86,6 +99,7 @@ parser.add_argument('--out_dir', dest='out_path', required=True) parser.add_argument('--action', dest='action', required=True) parser.add_argument('--vir', dest='viral_submission', required=False, action='store_true') +parser.add_argument('--dev', dest='dev_submission', required=False, action='store_true') parser.add_argument('--verbose', dest='verbose', required=False, action='store_true') args = parser.parse_args() @@ -148,10 +162,10 @@ samples_cols = samples_cols + ['status', 'accession', 'taxon_id', 'submission_date'] if args.viral_submission: # extend the samples columns with the viral specific data - samples_cols = samples_cols + ['geographic_location', 'host_common_name', - 'host_subject_id', 'host_health_state', 'host_sex', - 'host_scientific_name', 'collector_name', - 'collecting_institution', 'isolate'] + samples_cols = samples_cols + ['geographic location (country and/or sea)', 'host common name', + 'host subject id', 'host health state', 'host sex', + 'host scientific name', 'collector name', + 'collecting institution', 'isolate'] if len(samples_optional_cols_loaded) > 0: for optional_cols_excel in samples_optional_cols_loaded: samples_cols.append(optional_samples_cols_mapping[optional_cols_excel]) @@ -168,7 +182,7 @@ runs_table.write('\t'.join(['alias', 'status', 'accession', 'experiment_alias', 'file_name', 'file_format', 'file_checksum', 'submission_date']) + '\n') action = args.action - +# actionable_items # WRITE DICTIONARIES TO TABLE FILES # ADD A TIMESTAMP TO THE ALIAS? SEEMS LIKE ENA REQUIRES ALL ENTRIES FOR A WEBIN TO HAVE UNIQUE IDS? @@ -178,14 +192,22 @@ exp_included = [] for study_alias, study in studies_dict.items(): # study_alias = study_alias + '_' + timestamp - studies_table.write('\t'.join([study_alias, action, 'ENA_accession', study['title'], + if args.dev_submission: + entry_action = args.action + else: + entry_action = identify_action('study', study_alias) + studies_table.write('\t'.join([study_alias, entry_action, 'ENA_accession', study['title'], study['study_type'], study['study_abstract'], '', 'ENA_submission_data']) + '\n') # assuming no pubmed_id for sample_alias, sample in samples_dict.items(): # sample_alias = sample_alias + '_' + timestamp + if args.dev_submission: + entry_action = args.action + else: + entry_action = identify_action('sample', sample_alias) samples_row_values = [sample_alias, sample['title'], sample['scientific_name'], - sample['sample_description'], action, 'ena_accession', - 'tax_id_updated_by_ENA', 'ENA_submission_date'] + sample['sample_description'], entry_action, 'ena_accession', + '', 'ENA_submission_date'] if args.viral_submission: # add the values that are unique for the viral samples if sample['collector name'] == '': @@ -230,7 +252,12 @@ # (not listed in the samples or study dict) # process the experiments for this sample if exp['sample_alias'] == sample_alias: - experiments_table.write('\t'.join([exp_alias, action, 'accession_ena', exp['title'], + # check the remote status + if args.dev_submission: + entry_action = args.action + else: + entry_action = identify_action('experiment', exp_alias) + experiments_table.write('\t'.join([exp_alias, entry_action, 'accession_ena', exp['title'], exp['study_alias'], sample_alias, exp['design_description'], exp['library_name'], exp['library_strategy'], exp['library_source'], @@ -250,9 +277,13 @@ runs_list = run for run_entry in runs_list: if run_entry['experiment_alias'] == exp_alias: - runs_table.write('\t'.join([run_alias, action, 'ena_run_accession', + if args.dev_submission: + entry_action = args.action + else: + entry_action = identify_action('run', run_alias) + runs_table.write('\t'.join([run_alias, entry_action, 'ena_run_accession', exp_alias, run_entry['file_name'], - FILE_FORMAT, 'file_checksum', + FILE_FORMAT, '', 'submission_date_ENA']) + '\n') runs_included.append(run_alias) diff -r 59bb6d34fca6 -r 26ccb678abc8 samples_macros.xml --- a/samples_macros.xml Wed Aug 18 19:42:49 2021 +0000 +++ b/samples_macros.xml Tue Oct 19 15:57:14 2021 +0000 @@ -12,10 +12,11 @@ - + + - + @@ -40,6 +41,7 @@ + @@ -138,8 +140,8 @@ - - + + @@ -203,8 +205,8 @@ - - + +