Mercurial > repos > iuc > vsnp_add_zero_coverage
annotate vsnp_build_tables.py @ 0:0ad85e7db2fc draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
author | iuc |
---|---|
date | Sun, 27 Sep 2020 10:07:44 +0000 |
parents | |
children | aed013f6b13b |
rev | line source |
---|---|
0
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
2 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
3 import argparse |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
4 import multiprocessing |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
5 import os |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
6 import pandas |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
7 import queue |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
8 import pandas.io.formats.excel |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
9 import re |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
10 from Bio import SeqIO |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
11 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
12 INPUT_JSON_AVG_MQ_DIR = 'input_json_avg_mq_dir' |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
13 INPUT_JSON_DIR = 'input_json_dir' |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
14 INPUT_NEWICK_DIR = 'input_newick_dir' |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
15 # Maximum columns allowed in a LibreOffice |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
16 # spreadsheet is 1024. Excel allows for |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
17 # 16,384 columns, but we'll set the lower |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
18 # number as the maximum. Some browsers |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
19 # (e.g., Firefox on Linux) are configured |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
20 # to use LibreOffice for Excel spreadsheets. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
21 MAXCOLS = 1024 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
22 OUTPUT_EXCEL_DIR = 'output_excel_dir' |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
23 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
24 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
25 def annotate_table(table_df, group, annotation_dict): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
26 for gbk_chrome, pro in list(annotation_dict.items()): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
27 ref_pos = list(table_df) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
28 ref_series = pandas.Series(ref_pos) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
29 ref_df = pandas.DataFrame(ref_series.str.split(':', expand=True).values, columns=['reference', 'position']) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
30 all_ref = ref_df[ref_df['reference'] == gbk_chrome] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
31 positions = all_ref.position.to_frame() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
32 # Create an annotation file. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
33 annotation_file = "%s_annotations.csv" % group |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
34 with open(annotation_file, "a") as fh: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
35 for index, row in positions.iterrows(): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
36 pos = row.position |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
37 try: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
38 aaa = pro.iloc[pro.index.get_loc(int(pos))][['chrom', 'locus', 'product', 'gene']] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
39 try: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
40 chrom, name, locus, tag = aaa.values[0] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
41 print("{}:{}\t{}, {}, {}".format(chrom, pos, locus, tag, name), file=fh) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
42 except ValueError: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
43 # If only one annotation for the entire |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
44 # chromosome (e.g., flu) then having [0] fails |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
45 chrom, name, locus, tag = aaa.values |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
46 print("{}:{}\t{}, {}, {}".format(chrom, pos, locus, tag, name), file=fh) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
47 except KeyError: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
48 print("{}:{}\tNo annotated product".format(gbk_chrome, pos), file=fh) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
49 # Read the annotation file into a data frame. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
50 annotations_df = pandas.read_csv(annotation_file, sep='\t', header=None, names=['index', 'annotations'], index_col='index') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
51 # Remove the annotation_file from disk since both |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
52 # cascade and sort tables are built using the file, |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
53 # and it is opened for writing in append mode. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
54 os.remove(annotation_file) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
55 # Process the data. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
56 table_df_transposed = table_df.T |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
57 table_df_transposed.index = table_df_transposed.index.rename('index') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
58 table_df_transposed = table_df_transposed.merge(annotations_df, left_index=True, right_index=True) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
59 table_df = table_df_transposed.T |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
60 return table_df |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
61 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
62 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
63 def excel_formatter(json_file_name, excel_file_name, group, annotation_dict): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
64 pandas.io.formats.excel.header_style = None |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
65 table_df = pandas.read_json(json_file_name, orient='split') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
66 if annotation_dict is not None: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
67 table_df = annotate_table(table_df, group, annotation_dict) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
68 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
69 table_df = table_df.append(pandas.Series(name='no annotations')) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
70 writer = pandas.ExcelWriter(excel_file_name, engine='xlsxwriter') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
71 table_df.to_excel(writer, sheet_name='Sheet1') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
72 writer_book = writer.book |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
73 ws = writer.sheets['Sheet1'] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
74 format_a = writer_book.add_format({'bg_color': '#58FA82'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
75 format_g = writer_book.add_format({'bg_color': '#F7FE2E'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
76 format_c = writer_book.add_format({'bg_color': '#0000FF'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
77 format_t = writer_book.add_format({'bg_color': '#FF0000'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
78 format_normal = writer_book.add_format({'bg_color': '#FDFEFE'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
79 formatlowqual = writer_book.add_format({'font_color': '#C70039', 'bg_color': '#E2CFDD'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
80 format_ambigous = writer_book.add_format({'font_color': '#C70039', 'bg_color': '#E2CFDD'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
81 format_n = writer_book.add_format({'bg_color': '#E2CFDD'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
82 rows, cols = table_df.shape |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
83 ws.set_column(0, 0, 30) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
84 ws.set_column(1, cols, 2.1) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
85 ws.freeze_panes(2, 1) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
86 format_annotation = writer_book.add_format({'font_color': '#0A028C', 'rotation': '-90', 'align': 'top'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
87 # Set last row. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
88 ws.set_row(rows + 1, cols + 1, format_annotation) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
89 # Make sure that row/column locations don't overlap. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
90 ws.conditional_format(rows - 2, 1, rows - 1, cols, {'type': 'cell', 'criteria': '<', 'value': 55, 'format': formatlowqual}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
91 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'cell', 'criteria': '==', 'value': 'B$2', 'format': format_normal}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
92 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'A', 'format': format_a}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
93 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'G', 'format': format_g}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
94 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'C', 'format': format_c}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
95 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'T', 'format': format_t}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
96 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'S', 'format': format_ambigous}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
97 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'Y', 'format': format_ambigous}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
98 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'R', 'format': format_ambigous}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
99 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'W', 'format': format_ambigous}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
100 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'K', 'format': format_ambigous}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
101 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'M', 'format': format_ambigous}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
102 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': 'N', 'format': format_n}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
103 ws.conditional_format(2, 1, rows - 2, cols, {'type': 'text', 'criteria': 'containing', 'value': '-', 'format': format_n}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
104 format_rotation = writer_book.add_format({}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
105 format_rotation.set_rotation(90) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
106 for column_num, column_name in enumerate(list(table_df.columns)): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
107 ws.write(0, column_num + 1, column_name, format_rotation) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
108 format_annotation = writer_book.add_format({'font_color': '#0A028C', 'rotation': '-90', 'align': 'top'}) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
109 # Set last row. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
110 ws.set_row(rows, 400, format_annotation) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
111 writer.save() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
112 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
113 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
114 def get_annotation_dict(gbk_file): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
115 gbk_dict = SeqIO.to_dict(SeqIO.parse(gbk_file, "genbank")) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
116 annotation_dict = {} |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
117 tmp_file = "features.csv" |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
118 # Create a file of chromosomes and features. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
119 for chromosome in list(gbk_dict.keys()): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
120 with open(tmp_file, 'w+') as fh: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
121 for feature in gbk_dict[chromosome].features: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
122 if "CDS" in feature.type or "rRNA" in feature.type: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
123 try: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
124 product = feature.qualifiers['product'][0] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
125 except KeyError: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
126 product = None |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
127 try: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
128 locus = feature.qualifiers['locus_tag'][0] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
129 except KeyError: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
130 locus = None |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
131 try: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
132 gene = feature.qualifiers['gene'][0] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
133 except KeyError: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
134 gene = None |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
135 fh.write("%s\t%d\t%d\t%s\t%s\t%s\n" % (chromosome, int(feature.location.start), int(feature.location.end), locus, product, gene)) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
136 # Read the chromosomes and features file into a data frame. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
137 df = pandas.read_csv(tmp_file, sep='\t', names=["chrom", "start", "stop", "locus", "product", "gene"]) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
138 # Process the data. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
139 df = df.sort_values(['start', 'gene'], ascending=[True, False]) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
140 df = df.drop_duplicates('start') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
141 pro = df.reset_index(drop=True) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
142 pro.index = pandas.IntervalIndex.from_arrays(pro['start'], pro['stop'], closed='both') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
143 annotation_dict[chromosome] = pro |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
144 return annotation_dict |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
145 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
146 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
147 def get_base_file_name(file_path): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
148 base_file_name = os.path.basename(file_path) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
149 if base_file_name.find(".") > 0: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
150 # Eliminate the extension. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
151 return os.path.splitext(base_file_name)[0] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
152 elif base_file_name.find("_") > 0: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
153 # The dot extension was likely changed to |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
154 # the " character. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
155 items = base_file_name.split("_") |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
156 return "_".join(items[0:-1]) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
157 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
158 return base_file_name |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
159 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
160 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
161 def output_cascade_table(cascade_order, mqdf, group, annotation_dict): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
162 cascade_order_mq = pandas.concat([cascade_order, mqdf], join='inner') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
163 output_table(cascade_order_mq, "cascade", group, annotation_dict) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
164 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
165 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
166 def output_excel(df, type_str, group, annotation_dict, count=None): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
167 # Output the temporary json file that |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
168 # is used by the excel_formatter. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
169 if count is None: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
170 if group is None: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
171 json_file_name = "%s_order_mq.json" % type_str |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
172 excel_file_name = os.path.join(OUTPUT_EXCEL_DIR, "%s_table.xlsx" % type_str) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
173 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
174 json_file_name = "%s_%s_order_mq.json" % (group, type_str) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
175 excel_file_name = os.path.join(OUTPUT_EXCEL_DIR, "%s_%s_table.xlsx" % (group, type_str)) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
176 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
177 if group is None: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
178 json_file_name = "%s_order_mq_%d.json" % (type_str, count) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
179 excel_file_name = os.path.join(OUTPUT_EXCEL_DIR, "%s_table_%d.xlsx" % (type_str, count)) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
180 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
181 json_file_name = "%s_%s_order_mq_%d.json" % (group, type_str, count) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
182 excel_file_name = os.path.join(OUTPUT_EXCEL_DIR, "%s_%s_table_%d.xlsx" % (group, type_str, count)) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
183 df.to_json(json_file_name, orient='split') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
184 # Output the Excel file. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
185 excel_formatter(json_file_name, excel_file_name, group, annotation_dict) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
186 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
187 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
188 def output_sort_table(cascade_order, mqdf, group, annotation_dict): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
189 sort_df = cascade_order.T |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
190 sort_df['abs_value'] = sort_df.index |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
191 sort_df[['chrom', 'pos']] = sort_df['abs_value'].str.split(':', expand=True) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
192 sort_df = sort_df.drop(['abs_value', 'chrom'], axis=1) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
193 sort_df.pos = sort_df.pos.astype(int) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
194 sort_df = sort_df.sort_values(by=['pos']) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
195 sort_df = sort_df.drop(['pos'], axis=1) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
196 sort_df = sort_df.T |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
197 sort_order_mq = pandas.concat([sort_df, mqdf], join='inner') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
198 output_table(sort_order_mq, "sort", group, annotation_dict) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
199 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
200 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
201 def output_table(df, type_str, group, annotation_dict): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
202 if isinstance(group, str) and group.startswith("dataset"): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
203 # Inputs are single files, not collections, |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
204 # so input file names are not useful for naming |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
205 # output files. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
206 group_str = None |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
207 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
208 group_str = group |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
209 count = 0 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
210 chunk_start = 0 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
211 chunk_end = 0 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
212 column_count = df.shape[1] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
213 if column_count >= MAXCOLS: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
214 # Here the number of columns is greater than |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
215 # the maximum allowed by Excel, so multiple |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
216 # outputs will be produced. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
217 while column_count >= MAXCOLS: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
218 count += 1 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
219 chunk_end += MAXCOLS |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
220 df_of_type = df.iloc[:, chunk_start:chunk_end] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
221 output_excel(df_of_type, type_str, group_str, annotation_dict, count=count) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
222 chunk_start += MAXCOLS |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
223 column_count -= MAXCOLS |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
224 count += 1 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
225 df_of_type = df.iloc[:, chunk_start:] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
226 output_excel(df_of_type, type_str, group_str, annotation_dict, count=count) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
227 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
228 output_excel(df, type_str, group_str, annotation_dict) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
229 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
230 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
231 def preprocess_tables(task_queue, annotation_dict, timeout): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
232 while True: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
233 try: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
234 tup = task_queue.get(block=True, timeout=timeout) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
235 except queue.Empty: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
236 break |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
237 newick_file, json_file, json_avg_mq_file = tup |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
238 avg_mq_series = pandas.read_json(json_avg_mq_file, typ='series', orient='split') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
239 # Map quality to dataframe. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
240 mqdf = avg_mq_series.to_frame(name='MQ') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
241 mqdf = mqdf.T |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
242 # Get the group. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
243 group = get_base_file_name(newick_file) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
244 snps_df = pandas.read_json(json_file, orient='split') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
245 with open(newick_file, 'r') as fh: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
246 for line in fh: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
247 line = re.sub('[:,]', '\n', line) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
248 line = re.sub('[)(]', '', line) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
249 line = re.sub(r'[0-9].*\.[0-9].*\n', '', line) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
250 line = re.sub('root\n', '', line) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
251 sample_order = line.split('\n') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
252 sample_order = list([_f for _f in sample_order if _f]) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
253 sample_order.insert(0, 'root') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
254 tree_order = snps_df.loc[sample_order] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
255 # Count number of SNPs in each column. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
256 snp_per_column = [] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
257 for column_header in tree_order: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
258 count = 0 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
259 column = tree_order[column_header] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
260 for element in column: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
261 if element != column[0]: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
262 count = count + 1 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
263 snp_per_column.append(count) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
264 row1 = pandas.Series(snp_per_column, tree_order.columns, name="snp_per_column") |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
265 # Count number of SNPS from the |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
266 # top of each column in the table. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
267 snp_from_top = [] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
268 for column_header in tree_order: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
269 count = 0 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
270 column = tree_order[column_header] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
271 # for each element in the column |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
272 # skip the first element |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
273 for element in column[1:]: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
274 if element == column[0]: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
275 count = count + 1 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
276 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
277 break |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
278 snp_from_top.append(count) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
279 row2 = pandas.Series(snp_from_top, tree_order.columns, name="snp_from_top") |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
280 tree_order = tree_order.append([row1]) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
281 tree_order = tree_order.append([row2]) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
282 # In pandas=0.18.1 even this does not work: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
283 # abc = row1.to_frame() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
284 # abc = abc.T --> tree_order.shape (5, 18), abc.shape (1, 18) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
285 # tree_order.append(abc) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
286 # Continue to get error: "*** ValueError: all the input arrays must have same number of dimensions" |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
287 tree_order = tree_order.T |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
288 tree_order = tree_order.sort_values(['snp_from_top', 'snp_per_column'], ascending=[True, False]) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
289 tree_order = tree_order.T |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
290 # Remove snp_per_column and snp_from_top rows. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
291 cascade_order = tree_order[:-2] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
292 # Output the cascade table. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
293 output_cascade_table(cascade_order, mqdf, group, annotation_dict) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
294 # Output the sorted table. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
295 output_sort_table(cascade_order, mqdf, group, annotation_dict) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
296 task_queue.task_done() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
297 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
298 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
299 def set_num_cpus(num_files, processes): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
300 num_cpus = int(multiprocessing.cpu_count()) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
301 if num_files < num_cpus and num_files < processes: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
302 return num_files |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
303 if num_cpus < processes: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
304 half_cpus = int(num_cpus / 2) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
305 if num_files < half_cpus: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
306 return num_files |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
307 return half_cpus |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
308 return processes |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
309 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
310 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
311 if __name__ == '__main__': |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
312 parser = argparse.ArgumentParser() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
313 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
314 parser.add_argument('--input_avg_mq_json', action='store', dest='input_avg_mq_json', required=False, default=None, help='Average MQ json file') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
315 parser.add_argument('--input_newick', action='store', dest='input_newick', required=False, default=None, help='Newick file') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
316 parser.add_argument('--input_snps_json', action='store', dest='input_snps_json', required=False, default=None, help='SNPs json file') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
317 parser.add_argument('--gbk_file', action='store', dest='gbk_file', required=False, default=None, help='Optional gbk file'), |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
318 parser.add_argument('--processes', action='store', dest='processes', type=int, help='User-selected number of processes to use for job splitting') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
319 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
320 args = parser.parse_args() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
321 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
322 if args.gbk_file is not None: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
323 # Create the annotation_dict for annotating |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
324 # the Excel tables. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
325 annotation_dict = get_annotation_dict(args.gbk_file) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
326 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
327 annotation_dict = None |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
328 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
329 # The assumption here is that the list of files |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
330 # in both INPUT_NEWICK_DIR and INPUT_JSON_DIR are |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
331 # named such that they are properly matched if |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
332 # the directories contain more than 1 file (i.e., |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
333 # hopefully the newick file names and json file names |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
334 # will be something like Mbovis-01D6_* so they can be |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
335 # sorted and properly associated with each other). |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
336 if args.input_newick is not None: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
337 newick_files = [args.input_newick] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
338 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
339 newick_files = [] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
340 for file_name in sorted(os.listdir(INPUT_NEWICK_DIR)): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
341 file_path = os.path.abspath(os.path.join(INPUT_NEWICK_DIR, file_name)) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
342 newick_files.append(file_path) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
343 if args.input_snps_json is not None: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
344 json_files = [args.input_snps_json] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
345 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
346 json_files = [] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
347 for file_name in sorted(os.listdir(INPUT_JSON_DIR)): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
348 file_path = os.path.abspath(os.path.join(INPUT_JSON_DIR, file_name)) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
349 json_files.append(file_path) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
350 if args.input_avg_mq_json is not None: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
351 json_avg_mq_files = [args.input_avg_mq_json] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
352 else: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
353 json_avg_mq_files = [] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
354 for file_name in sorted(os.listdir(INPUT_JSON_AVG_MQ_DIR)): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
355 file_path = os.path.abspath(os.path.join(INPUT_JSON_AVG_MQ_DIR, file_name)) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
356 json_avg_mq_files.append(file_path) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
357 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
358 multiprocessing.set_start_method('spawn') |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
359 queue1 = multiprocessing.JoinableQueue() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
360 queue2 = multiprocessing.JoinableQueue() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
361 num_files = len(newick_files) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
362 cpus = set_num_cpus(num_files, args.processes) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
363 # Set a timeout for get()s in the queue. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
364 timeout = 0.05 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
365 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
366 for i, newick_file in enumerate(newick_files): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
367 json_file = json_files[i] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
368 json_avg_mq_file = json_avg_mq_files[i] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
369 queue1.put((newick_file, json_file, json_avg_mq_file)) |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
370 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
371 # Complete the preprocess_tables task. |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
372 processes = [multiprocessing.Process(target=preprocess_tables, args=(queue1, annotation_dict, timeout, )) for _ in range(cpus)] |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
373 for p in processes: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
374 p.start() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
375 for p in processes: |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
376 p.join() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
377 queue1.join() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
378 |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
379 if queue1.empty(): |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
380 queue1.close() |
0ad85e7db2fc
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 6a0c9a857c1f4638ef18e106b1f8c0681303acc5"
iuc
parents:
diff
changeset
|
381 queue1.join_thread() |