annotate frameshift_deletions_report_fixer.py @ 3:99f43642d1ae draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit 19423b30ae2c08e9cc16f199c64e3b6d1fcfcb44
author iuc
date Mon, 03 Jun 2024 15:51:31 +0000
parents 029d90b0c4f6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
1 """Polish the output of the frameshift_deletions_check command.
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
2
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
3 - Drops the first index column, which is rather pointless to include
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
4 - Turns ref bases printed as literal bytes strings into plain output
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
5 - Removes [] around pos lists and spaces after comma separating list elements
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
6 - Turns None and empty list values into . as a cell placeholder
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
7 """
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
8
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
9 import re
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
10 import sys
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
11
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
12
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
13 def matchrepl(matchobj):
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
14 bytes_string_content = matchobj.group(1)
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
15 if bytes_string_content is not None:
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
16 return bytes_string_content
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
17 list_content = matchobj.group(2)
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
18 if list_content is not None:
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
19 if list_content == '':
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
20 return '.'
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
21 return list_content.replace(', ', ',')
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
22 none_cell = matchobj.group(3)
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
23 if none_cell is not None:
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
24 return '\t.\t'
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
25
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
26 raise ValueError('Error in regex parsing code')
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
27
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
28
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
29 if __name__ == '__main__':
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
30 regex = re.compile(r"b'(.+)'|\[([^\]]*)\]|\t(None)\t")
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
31 with open(sys.argv[1]) as i:
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
32 with open(sys.argv[2], 'w') as o:
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
33 for line in i:
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
34 line = line[line.index('\t') + 1:]
029d90b0c4f6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/smallgenomeutilities commit e702dcdbc7c3235ef3c4ee8998c7247d1af49465
iuc
parents:
diff changeset
35 o.write(regex.sub(matchrepl, line))