Skip to content

Instantly share code, notes, and snippets.

@LeeBergstrand
Created February 13, 2021 06:12
Show Gist options
  • Save LeeBergstrand/d429041fa50698fec5a83ddb2a295ed0 to your computer and use it in GitHub Desktop.
Save LeeBergstrand/d429041fa50698fec5a83ddb2a295ed0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
Created by: Lee Bergstrand
Description: Makes newer InterProScan TSV file compatible with Pygenprop.
Requirements: None
"""
import argparse
import csv
import os
def main(args):
"""
Makes newer InterProScan TSV file compatible with Pygenprop.
:param args: CLI Arguments
"""
path = args.input
path_filename = os.path.splitext(path)[0]
new_path = os.path.join(path_filename + ".tsv2")
with open(new_path, 'w') as new_tsv_file:
with open(path, 'r') as tsv_file:
reader = csv.reader(tsv_file, delimiter='\t')
writer = csv.writer(new_tsv_file, delimiter='\t')
for row in reader:
if row[8] == '-':
row[8] = 1337
new_row = ['' if value == '-' else value for value in row]
writer.writerow(new_row)
if __name__ == '__main__':
cli_title = """Makes newer InterProScan TSV file compatible with Pygenprop. Replaces '-' (indicating no value)
with no blank values. Blank values in the TSV e_value column with 1337."""
parser = argparse.ArgumentParser(description=cli_title)
parser.add_argument('-i', '--input', metavar='TSV', required=True,
help='The path to the InterProScan TSV to be sanitized.')
cli_args = parser.parse_args()
main(cli_args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment