Merge tag 'upstream/2.6.1+ds'
Upstream version 2.6.1+ds
Sascha Steinbiss
7 years ago
7 | 7 | def __init__(self, infile, duplicate_warnings=True): |
8 | 8 | self.infile = infile |
9 | 9 | self.duplicate_warnings = duplicate_warnings |
10 | self.columns_to_ignore = ['clonal_complex', 'CC', 'Lineage', 'mlst_clade', 'species'] | |
10 | 11 | |
11 | 12 | if not os.path.exists(self.infile): |
12 | 13 | raise Error('Error! Input file "' + self.infile + '" not found.') |
21 | 22 | if reader.fieldnames[0] != 'ST': |
22 | 23 | raise Error('Error. Expected first column of profile file "' + self.infile + '" to be "ST"') |
23 | 24 | |
24 | self.genes_list = reader.fieldnames[1:] | |
25 | if self.genes_list[-1] == 'clonal_complex': | |
26 | self.genes_list.pop() | |
25 | self.genes_list = [column_name for column_name in reader.fieldnames[1:] if column_name not in self.columns_to_ignore] | |
27 | 26 | |
28 | 27 | for row in reader: |
29 | 28 | type_tuple = tuple(int(row[x]) for x in self.genes_list) |
0 | ST nusA rpoB eno gltB lepA nuoL nrdA clonal_complex CC Lineage mlst_clade species | |
1 | 1 1 26 2 2 59 8 1 1 CC10 II 123 Bacteria | |
2 | 2 1 26 2 4 59 2 5 2 CC10 II 123 Bacteria |
9 | 9 | def test_init(self): |
10 | 10 | '''test init''' |
11 | 11 | infile = os.path.join(data_dir, 'mlst_profile_test.init.profile.tsv') |
12 | profile = mlst_profile.MlstProfile(infile) | |
13 | expected_genes = ['nusA', 'rpoB', 'eno', 'gltB', 'lepA', 'nuoL', 'nrdA'] | |
14 | self.assertEqual(expected_genes, profile.genes_list) | |
15 | self.assertEqual(set(expected_genes), profile.genes_set) | |
16 | expected_dict = { | |
17 | (1, 26, 2, 2, 59, 8, 1): 1, | |
18 | (1, 26, 2, 4, 59, 2, 5): 2 | |
19 | } | |
20 | self.assertEqual(expected_dict, profile.profile_to_type) | |
21 | ||
22 | def test_init_multiple_extra_columns(self): | |
23 | '''test init''' | |
24 | infile = os.path.join(data_dir, 'mlst_profile_test.init_multiple_extra_columns.profile.tsv') | |
12 | 25 | profile = mlst_profile.MlstProfile(infile) |
13 | 26 | expected_genes = ['nusA', 'rpoB', 'eno', 'gltB', 'lepA', 'nuoL', 'nrdA'] |
14 | 27 | self.assertEqual(expected_genes, profile.genes_list) |