annotate process_xlsx.py @ 1:57251c760cab draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
author iuc
date Fri, 30 Apr 2021 12:09:25 +0000
parents 382518f24d6d
children 9e2df763086c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
1 import argparse
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
2 import pathlib
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
3 import sys
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
4
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
5 import xlrd
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
6 import yaml
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
7
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
8 FILE_FORMAT = 'fastq'
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
9
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
10
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
11 def extract_data(xl_sheet, expected_columns):
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
12 """
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
13 1. Check that the columns I expect are present in the sheet
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
14 (any order and mixed with others, it's just a verification that
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
15 the user filled the correct template)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
16 2. Fill a dictionary with the rows data indexed by first column in list"""
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
17 sheet_columns = {}
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
18 for sh_col in range(xl_sheet.ncols):
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
19 if xl_sheet.cell(0, sh_col).value in expected_columns:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
20 if xl_sheet.cell(0, sh_col).value in sheet_columns.keys():
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
21 sys.exit("Duplicated columns")
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
22 else:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
23 sheet_columns[xl_sheet.cell(0, sh_col).value] = sh_col
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
24 for col in range(len(expected_columns)):
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
25 assert expected_columns[col] in sheet_columns.keys(), \
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
26 "Expected column %s not found" % expected_columns[col]
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
27
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
28 # fetch rows in a dict
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
29 data_dict = {}
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
30 # the first of the expected columns will be the index
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
31 index_col = sheet_columns[expected_columns[0]]
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
32 # skip first 2 rows: column names + comments rows
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
33 for row_id in range(2, xl_sheet.nrows):
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
34 row_dict = {}
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
35 for col in range(1, len(expected_columns)):
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
36 sheet_col_index = sheet_columns[expected_columns[col]]
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
37 row_dict[expected_columns[col]] = xl_sheet.cell(row_id, sheet_col_index).value
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
38 # should check for duplicate alias/ids?
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
39 if xl_sheet.cell(row_id, index_col).value in data_dict.keys():
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
40 tmp = data_dict[xl_sheet.cell(row_id, index_col).value]
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
41 data_dict[xl_sheet.cell(row_id, index_col).value] = [tmp]
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
42 data_dict[xl_sheet.cell(row_id, index_col).value].append(row_dict)
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
43 else:
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
44 data_dict[xl_sheet.cell(row_id, index_col).value] = row_dict
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
45 return data_dict
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
46
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
47
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
48 def paste_xls2yaml(xlsx_path):
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
49 print('YAML -------------')
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
50 xls = xlrd.open_workbook(xlsx_path)
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
51 content_dict = {}
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
52 for sheet_name in xls.sheet_names():
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
53 if sheet_name == 'controlled_vocabulary':
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
54 continue
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
55 xls_sheet = xls.sheet_by_name(sheet_name)
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
56 sheet_contents_dict = {}
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
57 colnames = []
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
58 for col in range(xls_sheet.ncols):
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
59 colnames.append(xls_sheet.cell(0, col).value)
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
60 # skip first 2 rows (column names and suggestions)
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
61 for row_id in range(2, xls_sheet.nrows):
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
62 row_dict = {}
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
63 for col_id in range(0, xls_sheet.ncols):
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
64 row_dict[colnames[col_id]] = xls_sheet.cell(row_id, col_id).value
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
65 # should check for duplicate alias/ids?
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
66 sheet_contents_dict[row_id] = row_dict
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
67 content_dict[sheet_name] = sheet_contents_dict
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
68 yaml.dump(content_dict, sys.stdout)
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
69 print('YAML -------------')
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
70
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
71
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
72 parser = argparse.ArgumentParser()
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
73 parser.add_argument('--form', dest='xlsx_path', required=True)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
74 parser.add_argument('--out_dir', dest='out_path', required=True)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
75 parser.add_argument('--action', dest='action', required=True)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
76 parser.add_argument('--vir', dest='viral_submission', required=False, action='store_true')
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
77 parser.add_argument('--verbose', dest='verbose', required=False, action='store_true')
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
78 args = parser.parse_args()
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
79
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
80 xl_workbook = xlrd.open_workbook(args.xlsx_path)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
81
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
82 # PARSE STUDIES
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
83 #################
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
84 xl_sheet = xl_workbook.sheet_by_name('ENA_study')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
85 if xl_sheet.nrows < 3:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
86 raise ValueError('No entries found in studies sheet')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
87 studies_dict = {}
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
88 studies_col = ['alias', 'title', 'study_type', 'study_abstract']
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
89 studies_dict = extract_data(xl_sheet, studies_col)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
90
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
91 # PARSE SAMPLES
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
92 #################
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
93 xl_sheet = xl_workbook.sheet_by_name('ENA_sample')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
94 if xl_sheet.nrows < 3:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
95 raise ValueError('No entries found in samples')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
96 if args.viral_submission:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
97 samples_cols = ['alias', 'title', 'scientific_name', 'sample_description',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
98 'geographic location (country and/or sea)', 'host common name',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
99 'host health state', 'host sex', 'host scientific name', 'collector name',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
100 'collection date', 'collecting institution', 'isolate']
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
101 else:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
102 samples_cols = ['alias', 'title', 'scientific_name', 'sample_description']
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
103 samples_dict = extract_data(xl_sheet, samples_cols)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
104
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
105 # PARSE EXPERIMENTS
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
106 #################
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
107 xl_sheet = xl_workbook.sheet_by_name('ENA_experiment')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
108 if xl_sheet.nrows < 3:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
109 raise ValueError('No experiments found in experiments sheet')
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
110 exp_columns = ['alias', 'title', 'study_alias', 'sample_alias', 'design_description',
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
111 'library_name', 'library_strategy', 'library_source', 'library_selection',
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
112 'library_layout', 'insert_size', 'library_construction_protocol',
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
113 'platform', 'instrument_model']
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
114
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
115 experiments_dict = extract_data(xl_sheet, exp_columns)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
116
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
117 # PARSE RUNS SHEET
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
118 #################
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
119 xl_sheet = xl_workbook.sheet_by_name('ENA_run')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
120 if xl_sheet.nrows < 3:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
121 raise ValueError('No entries found in runs sheet')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
122 run_cols = ['alias', 'experiment_alias', 'file_name', 'file_format']
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
123 runs_dict = extract_data(xl_sheet, run_cols)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
124
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
125 # WRITE HEADERS TO TABLES
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
126 studies_table = open(pathlib.Path(args.out_path) / 'studies.tsv', 'w')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
127 studies_table.write('\t'.join(['alias', 'status', 'accession', 'title', 'study_type',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
128 'study_abstract', 'pubmed_id', 'submission_date']) + '\n')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
129 samples_table = open(pathlib.Path(args.out_path) / 'samples.tsv', 'w')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
130 if args.viral_submission:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
131 samples_table.write('\t'.join(['alias', 'status', 'accession', 'title', 'scientific_name',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
132 'taxon_id', 'sample_description', 'collection_date',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
133 'geographic_location', 'host_common_name', 'host_subject_id',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
134 'host_health_state', 'host_sex', 'host_scientific_name',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
135 'collector_name', 'collecting_institution', 'isolate',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
136 'submission_date']) + '\n')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
137 else:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
138 samples_table.write('\t'.join(['alias', 'status', 'accession', 'title', 'scientific_name',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
139 'taxon_id', 'sample_description', 'submission_date']) + '\n')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
140
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
141 experiments_table = open(pathlib.Path(args.out_path) / 'experiments.tsv', 'w')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
142 experiments_table.write('\t'.join(['alias', 'status', 'accession', 'title', 'study_alias',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
143 'sample_alias', 'design_description', 'library_name',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
144 'library_strategy', 'library_source', 'library_selection',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
145 'library_layout', 'insert_size', 'library_construction_protocol',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
146 'platform', 'instrument_model', 'submission_date']) + '\n')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
147
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
148 runs_table = open(pathlib.Path(args.out_path) / 'runs.tsv', 'w')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
149 runs_table.write('\t'.join(['alias', 'status', 'accession', 'experiment_alias', 'file_name',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
150 'file_format', 'file_checksum', 'submission_date']) + '\n')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
151 action = args.action
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
152
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
153 # WRITE DICTIONARIES TO TABLE FILES
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
154
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
155 # ADD A TIMESTAMP TO THE ALIAS? SEEMS LIKE ENA REQUIRES ALL ENTRIES FOR A WEBIN TO HAVE UNIQUE IDS?
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
156 # dt_oobj = datetime.now(tz=None)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
157 # timestamp = dt_oobj.strftime("%Y%m%d_%H:%M:%S")
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
158 runs_included = []
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
159 exp_included = []
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
160 for study_alias, study in studies_dict.items():
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
161 # study_alias = study_alias + '_' + timestamp
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
162 studies_table.write('\t'.join([study_alias, action, 'ENA_accession', study['title'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
163 study['study_type'], study['study_abstract'], '',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
164 'ENA_submission_data']) + '\n') # assuming no pubmed_id
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
165 for sample_alias, sample in samples_dict.items():
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
166 # sample_alias = sample_alias + '_' + timestamp
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
167 if args.viral_submission:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
168 if sample['collector name'] == '':
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
169 sample['collector name'] = 'unknown'
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
170 samples_table.write('\t'.join([sample_alias, action, 'ena_accession', sample['title'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
171 sample['scientific_name'], 'tax_id_updated_by_ENA',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
172 sample['sample_description'], sample['collection date'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
173 sample['geographic location (country and/or sea)'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
174 sample['host common name'], 'host subject id',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
175 sample['host health state'], sample['host sex'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
176 sample['host scientific name'], sample['collector name'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
177 sample['collecting institution'], sample['isolate'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
178 'ENA_submission_date']) + '\n')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
179 else:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
180 samples_table.write('\t'.join([sample_alias, action, 'ena_accession', sample['title'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
181 sample['scientific_name'], 'tax_id_updated_by_ENA',
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
182 sample['sample_description']]) + '\n')
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
183 for exp_alias, exp in experiments_dict.items():
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
184 # should I check here if any experiment has a study or sample alias that is incorrect?
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
185 # (not listed in the samples or study dict)
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
186 # process the experiments for this sample
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
187 if exp['sample_alias'] == sample_alias:
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
188 lib_alias = 'library_' + exp_alias + '_' + exp['sample_alias']
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
189 experiments_table.write('\t'.join([exp_alias, action, 'accession_ena', exp['title'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
190 exp['study_alias'], sample_alias,
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
191 exp['design_description'], lib_alias,
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
192 exp['library_strategy'], exp['library_source'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
193 exp['library_selection'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
194 exp['library_layout'].lower(),
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
195 str(int(exp['insert_size'])),
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
196 exp['library_construction_protocol'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
197 exp['platform'], exp['instrument_model'],
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
198 'submission_date_ENA']) + '\n')
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
199 exp_included.append(exp_alias)
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
200 for run_alias, run in runs_dict.items():
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
201 # check that the experiments library_layout is set to paired
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
202 # when multiple entries are associated with the same run alias
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
203 if not isinstance(run, list):
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
204 runs_list = [run]
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
205 else:
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
206 runs_list = run
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
207 for run_entry in runs_list:
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
208 if run_entry['experiment_alias'] == exp_alias:
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
209 runs_table.write('\t'.join([run_alias, action, 'ena_run_accession',
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
210 exp_alias, run_entry['file_name'],
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
211 FILE_FORMAT, 'file_checksum',
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
212 'submission_date_ENA']) + '\n')
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
213 runs_included.append(run_alias)
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
214
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
215 # check if any experiment or run was not associated with any sample
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
216 for run in runs_dict.keys():
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
217 if run not in runs_included:
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
218 print(f'The run {run} is listed in the runs section but not associated with any \
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
219 used experiment')
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
220
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
221 for exp in experiments_dict.keys():
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
222 if exp not in exp_included:
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
223 print(f'The experiment {exp} is listed in the experiments section but not associated \
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
224 with any used sample')
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
225
0
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
226 studies_table.close()
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
227 samples_table.close()
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
228 experiments_table.close()
382518f24d6d "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit 57b434bcf493554d060a99b65e66f274d5c00e0a"
iuc
parents:
diff changeset
229 runs_table.close()
1
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
230
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
231 if args.verbose:
57251c760cab "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ena_upload commit ffea061c1ad6e7291abfe220230dbdbe8d19a2bd"
iuc
parents: 0
diff changeset
232 paste_xls2yaml(args.xlsx_path)