Mercurial > repos > p.lucas > concat_cov_and_iupac
comparison concat_cov_and_iupac_results.py @ 1:733edda2eb48 draft default tip
Uploaded
| author | p.lucas |
|---|---|
| date | Thu, 13 Jun 2024 14:50:57 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:4fdf1283e153 | 1:733edda2eb48 |
|---|---|
| 1 #!/usr/python3 | |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 4 import os | |
| 5 import argparse | |
| 6 import sys | |
| 7 | |
| 8 | |
| 9 # MAIN | |
| 10 def __main__(): | |
| 11 # Script options: | |
| 12 parser = argparse.ArgumentParser(description='''Add iupac value to coverage file.''', | |
| 13 epilog="""This script need few options, use -h to see it.""") | |
| 14 parser.add_argument('-c', '-covfile', dest='fc', help='Coverage file.') | |
| 15 parser.add_argument('-i', '-iupacfile', dest='fi', help='IUPAC file.') | |
| 16 parser.add_argument('-o', '-output_file', dest='output_file', help='Output File') | |
| 17 | |
| 18 # Get script options: | |
| 19 options = parser.parse_args() | |
| 20 fc = options.fc | |
| 21 fi = options.fi | |
| 22 output_file = options.output_file | |
| 23 | |
| 24 # Check options: | |
| 25 if len(sys.argv) < 7 or len(sys.argv) > 7: | |
| 26 parser.print_help() | |
| 27 sys.exit(1) | |
| 28 | |
| 29 # Output file | |
| 30 outputfile = open(output_file, "w") | |
| 31 | |
| 32 # Variables: | |
| 33 iup_list_ref = {} | |
| 34 | |
| 35 # Storing iupac values | |
| 36 for i in open(fi, "r").readlines(): | |
| 37 list_i = i.split("\t") | |
| 38 iup_list_ref[list_i[0]] = list_i[1] | |
| 39 | |
| 40 print(iup_list_ref.keys()) | |
| 41 # Add iupac value to coverage value: | |
| 42 for li in open(fc, "r").readlines(): | |
| 43 print(li) | |
| 44 outputfile.write(li) | |
| 45 ref = li.rstrip() | |
| 46 if ref in iup_list_ref.keys(): | |
| 47 print("line for iupac find") | |
| 48 outputfile.write(f"Percentage IUPAC: {iup_list_ref[ref]}") | |
| 49 | |
| 50 | |
| 51 # MAIN END | |
| 52 if __name__ == "__main__": | |
| 53 __main__() |
