annotate vsnp_determine_ref_from_data.py @ 3:85587c8eb25f draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
author iuc
date Wed, 02 Dec 2020 09:10:07 +0000
parents
children efb86aade548
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
2
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
3 import argparse
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
4 import gzip
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
5 import os
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
6 from collections import OrderedDict
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
7
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
8 import yaml
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
9 from Bio.SeqIO.QualityIO import FastqGeneralIterator
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
10
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
11 OUTPUT_DBKEY_DIR = 'output_dbkey'
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
12 OUTPUT_METRICS_DIR = 'output_metrics'
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
13
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
14
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
15 def get_base_file_name(file_path):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
16 base_file_name = os.path.basename(file_path)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
17 if base_file_name.find(".") > 0:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
18 # Eliminate the extension.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
19 return os.path.splitext(base_file_name)[0]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
20 elif base_file_name.find("_fq") > 0:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
21 # The "." character has likely
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
22 # changed to an "_" character.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
23 return base_file_name.split("_fq")[0]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
24 elif base_file_name.find("_fastq") > 0:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
25 return base_file_name.split("_fastq")[0]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
26 return base_file_name
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
27
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
28
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
29 def get_dbkey(dnaprints_dict, key, s):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
30 # dnaprints_dict looks something like this:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
31 # {'brucella': {'NC_002945v4': ['11001110', '11011110', '11001100']}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
32 # {'bovis': {'NC_006895': ['11111110', '00010010', '01111011']}}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
33 d = dnaprints_dict.get(key, {})
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
34 for data_table_value, v_list in d.items():
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
35 if s in v_list:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
36 return data_table_value
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
37 return ""
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
38
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
39
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
40 def get_dnaprints_dict(dnaprint_fields):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
41 # A dndprint_fields entry looks something liek this.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
42 # [['AF2122', '/galaxy/tool-data/vsnp/AF2122/dnaprints/NC_002945v4.yml']]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
43 dnaprints_dict = {}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
44 for item in dnaprint_fields:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
45 # Here item is a 2-element list of data
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
46 # table components, # value and path.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
47 value = item[0]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
48 path = item[1].strip()
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
49 with open(path, "rt") as fh:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
50 # The format of all dnaprints yaml
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
51 # files is something like this:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
52 # brucella:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
53 # - 0111111111111111
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
54 print_dict = yaml.load(fh, Loader=yaml.Loader)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
55 for print_dict_k, print_dict_v in print_dict.items():
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
56 dnaprints_v_dict = dnaprints_dict.get(print_dict_k, {})
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
57 if len(dnaprints_v_dict) > 0:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
58 # dnaprints_dict already contains k (e.g., 'brucella',
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
59 # and dnaprints_v_dict will be a dictionary # that
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
60 # looks something like this:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
61 # {'NC_002945v4': ['11001110', '11011110', '11001100']}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
62 value_list = dnaprints_v_dict.get(value, [])
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
63 value_list = value_list + print_dict_v
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
64 dnaprints_v_dict[value] = value_list
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
65 else:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
66 # dnaprints_v_dict is an empty dictionary.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
67 dnaprints_v_dict[value] = print_dict_v
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
68 dnaprints_dict[print_dict_k] = dnaprints_v_dict
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
69 # dnaprints_dict looks something like this:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
70 # {'brucella': {'NC_002945v4': ['11001110', '11011110', '11001100']}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
71 # {'bovis': {'NC_006895': ['11111110', '00010010', '01111011']}}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
72 return dnaprints_dict
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
73
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
74
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
75 def get_group_and_dbkey(dnaprints_dict, brucella_string, brucella_sum, bovis_string, bovis_sum, para_string, para_sum):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
76 if brucella_sum > 3:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
77 group = "Brucella"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
78 dbkey = get_dbkey(dnaprints_dict, "brucella", brucella_string)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
79 elif bovis_sum > 3:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
80 group = "TB"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
81 dbkey = get_dbkey(dnaprints_dict, "bovis", bovis_string)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
82 elif para_sum >= 1:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
83 group = "paraTB"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
84 dbkey = get_dbkey(dnaprints_dict, "para", para_string)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
85 else:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
86 group = ""
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
87 dbkey = ""
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
88 return group, dbkey
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
89
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
90
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
91 def get_oligo_dict():
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
92 oligo_dict = {}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
93 oligo_dict["01_ab1"] = "AATTGTCGGATAGCCTGGCGATAACGACGC"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
94 oligo_dict["02_ab3"] = "CACACGCGGGCCGGAACTGCCGCAAATGAC"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
95 oligo_dict["03_ab5"] = "GCTGAAGCGGCAGACCGGCAGAACGAATAT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
96 oligo_dict["04_mel"] = "TGTCGCGCGTCAAGCGGCGTGAAATCTCTG"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
97 oligo_dict["05_suis1"] = "TGCGTTGCCGTGAAGCTTAATTCGGCTGAT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
98 oligo_dict["06_suis2"] = "GGCAATCATGCGCAGGGCTTTGCATTCGTC"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
99 oligo_dict["07_suis3"] = "CAAGGCAGATGCACATAATCCGGCGACCCG"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
100 oligo_dict["08_ceti1"] = "GTGAATATAGGGTGAATTGATCTTCAGCCG"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
101 oligo_dict["09_ceti2"] = "TTACAAGCAGGCCTATGAGCGCGGCGTGAA"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
102 oligo_dict["10_canis4"] = "CTGCTACATAAAGCACCCGGCGACCGAGTT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
103 oligo_dict["11_canis"] = "ATCGTTTTGCGGCATATCGCTGACCACAGC"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
104 oligo_dict["12_ovis"] = "CACTCAATCTTCTCTACGGGCGTGGTATCC"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
105 oligo_dict["13_ether2"] = "CGAAATCGTGGTGAAGGACGGGACCGAACC"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
106 oligo_dict["14_63B1"] = "CCTGTTTAAAAGAATCGTCGGAACCGCTCT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
107 oligo_dict["15_16M0"] = "TCCCGCCGCCATGCCGCCGAAAGTCGCCGT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
108 oligo_dict["16_mel1b"] = "TCTGTCCAAACCCCGTGACCGAACAATAGA"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
109 oligo_dict["17_tb157"] = "CTCTTCGTATACCGTTCCGTCGTCACCATGGTCCT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
110 oligo_dict["18_tb7"] = "TCACGCAGCCAACGATATTCGTGTACCGCGACGGT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
111 oligo_dict["19_tbbov"] = "CTGGGCGACCCGGCCGACCTGCACACCGCGCATCA"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
112 oligo_dict["20_tb5"] = "CCGTGGTGGCGTATCGGGCCCCTGGATCGCGCCCT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
113 oligo_dict["21_tb2"] = "ATGTCTGCGTAAAGAAGTTCCATGTCCGGGAAGTA"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
114 oligo_dict["22_tb3"] = "GAAGACCTTGATGCCGATCTGGGTGTCGATCTTGA"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
115 oligo_dict["23_tb4"] = "CGGTGTTGAAGGGTCCCCCGTTCCAGAAGCCGGTG"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
116 oligo_dict["24_tb6"] = "ACGGTGATTCGGGTGGTCGACACCGATGGTTCAGA"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
117 oligo_dict["25_para"] = "CCTTTCTTGAAGGGTGTTCG"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
118 oligo_dict["26_para_sheep"] = "CGTGGTGGCGACGGCGGCGGGCCTGTCTAT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
119 oligo_dict["27_para_cattle"] = "TCTCCTCGGTCGGTGATTCGGGGGCGCGGT"
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
120 return oligo_dict
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
121
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
122
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
123 def get_seq_counts(value, fastq_list, gzipped):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
124 count = 0
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
125 for fastq_file in fastq_list:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
126 if gzipped:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
127 with gzip.open(fastq_file, 'rt') as fh:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
128 for title, seq, qual in FastqGeneralIterator(fh):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
129 count += seq.count(value)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
130 else:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
131 with open(fastq_file, 'r') as fh:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
132 for title, seq, qual in FastqGeneralIterator(fh):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
133 count += seq.count(value)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
134 return(value, count)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
135
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
136
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
137 def get_species_counts(fastq_list, gzipped):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
138 count_summary = {}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
139 oligo_dict = get_oligo_dict()
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
140 for v1 in oligo_dict.values():
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
141 returned_value, count = get_seq_counts(v1, fastq_list, gzipped)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
142 for key, v2 in oligo_dict.items():
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
143 if returned_value == v2:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
144 count_summary.update({key: count})
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
145 count_list = []
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
146 for v in count_summary.values():
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
147 count_list.append(v)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
148 brucella_sum = sum(count_list[:16])
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
149 bovis_sum = sum(count_list[16:24])
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
150 para_sum = sum(count_list[24:])
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
151 return count_summary, count_list, brucella_sum, bovis_sum, para_sum
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
152
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
153
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
154 def get_species_strings(count_summary):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
155 binary_dictionary = {}
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
156 for k, v in count_summary.items():
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
157 if v > 1:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
158 binary_dictionary.update({k: 1})
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
159 else:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
160 binary_dictionary.update({k: 0})
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
161 binary_dictionary = OrderedDict(sorted(binary_dictionary.items()))
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
162 binary_list = []
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
163 for v in binary_dictionary.values():
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
164 binary_list.append(v)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
165 brucella_binary = binary_list[:16]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
166 brucella_string = ''.join(str(e) for e in brucella_binary)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
167 bovis_binary = binary_list[16:24]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
168 bovis_string = ''.join(str(e) for e in bovis_binary)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
169 para_binary = binary_list[24:]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
170 para_string = ''.join(str(e) for e in para_binary)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
171 return brucella_string, bovis_string, para_string
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
172
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
173
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
174 def output_dbkey(file_name, dbkey, output_file):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
175 # Output the dbkey.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
176 with open(output_file, "w") as fh:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
177 fh.write("%s" % dbkey)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
178
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
179
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
180 def output_files(fastq_file, count_list, group, dbkey, dbkey_file, metrics_file):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
181 base_file_name = get_base_file_name(fastq_file)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
182 output_dbkey(base_file_name, dbkey, dbkey_file)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
183 output_metrics(base_file_name, count_list, group, dbkey, metrics_file)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
184
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
185
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
186 def output_metrics(file_name, count_list, group, dbkey, output_file):
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
187 # Output the metrics.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
188 with open(output_file, "w") as fh:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
189 fh.write("Sample: %s\n" % file_name)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
190 fh.write("Brucella counts: ")
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
191 for i in count_list[:16]:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
192 fh.write("%d," % i)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
193 fh.write("\nTB counts: ")
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
194 for i in count_list[16:24]:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
195 fh.write("%d," % i)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
196 fh.write("\nPara counts: ")
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
197 for i in count_list[24:]:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
198 fh.write("%d," % i)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
199 fh.write("\nGroup: %s" % group)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
200 fh.write("\ndbkey: %s\n" % dbkey)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
201
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
202
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
203 if __name__ == '__main__':
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
204 parser = argparse.ArgumentParser()
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
205
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
206 parser.add_argument('--dnaprint_fields', action='append', dest='dnaprint_fields', nargs=2, required=False, default=None, help="List of dnaprints data table value, name and path fields")
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
207 parser.add_argument('--read1', action='store', dest='read1', required=True, default=None, help='Required: single read')
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
208 parser.add_argument('--read2', action='store', dest='read2', required=False, default=None, help='Optional: paired read')
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
209 parser.add_argument('--gzipped', action='store_true', dest='gzipped', default=False, help='Input files are gzipped')
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
210 parser.add_argument('--output_dbkey', action='store', dest='output_dbkey', required=True, default=None, help='Output reference file')
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
211 parser.add_argument('--output_metrics', action='store', dest='output_metrics', required=True, default=None, help='Output metrics file')
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
212
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
213 args = parser.parse_args()
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
214
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
215 fastq_list = [args.read1]
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
216 if args.read2 is not None:
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
217 fastq_list.append(args.read2)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
218
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
219 # The value of dnaprint_fields is a list of lists, where each list is
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
220 # the [value, name, path] components of the vsnp_dnaprints data table.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
221 # The data_manager_vsnp_dnaprints tool assigns the dbkey column from the
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
222 # all_fasta data table to the value column in the vsnp_dnaprints data
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
223 # table to ensure a proper mapping for discovering the dbkey.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
224 dnaprints_dict = get_dnaprints_dict(args.dnaprint_fields)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
225
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
226 # Here fastq_list consists of either a single read
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
227 # or a set of paired reads, producing single outputs.
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
228 count_summary, count_list, brucella_sum, bovis_sum, para_sum = get_species_counts(fastq_list, args.gzipped)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
229 brucella_string, bovis_string, para_string = get_species_strings(count_summary)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
230 group, dbkey = get_group_and_dbkey(dnaprints_dict, brucella_string, brucella_sum, bovis_string, bovis_sum, para_string, para_sum)
85587c8eb25f "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/vsnp commit 524a39e08f2bea8b8754284df606ff8dd27ed24b"
iuc
parents:
diff changeset
231 output_files(args.read1, count_list, group, dbkey, dbkey_file=args.output_dbkey, metrics_file=args.output_metrics)