Advertisement
SUBANGKAR

matchingkmers

Feb 19th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. #!/usr/bin/python3  
  2. import sys  
  3. import collections
  4.  
  5. # print('Number of arguments:', len(sys.argv), 'arguments.')
  6. # print('Argument List:', str(sys.argv))
  7. if sys.argv.__len__() < 5:
  8.     print("Files?")
  9.     exit()
  10. file_q=sys.argv[1]
  11. file_case=sys.argv[2]
  12. file_cntl=sys.argv[3]
  13. outf=sys.argv[4]
  14. # print(file_q
  15. #)
  16. # print(file_case)
  17. i=0
  18. def_val='            '
  19. kmers_map=collections.defaultdict(lambda : (def_val,def_val,def_val))
  20. kmers_match=collections.defaultdict(lambda : ('-1.0','-1.0','-1.0'))
  21. with open(file_q) as f:
  22.     # content=f.read()
  23.     for line in f:
  24.         # print(line.split('\t')[0])
  25.         kmers_map[line.split('\t')[0]]=(line.split('\t')[1],def_val,def_val)
  26. print(kmers_map.__len__())
  27. print(file_q+'_read')
  28. with open(file_case) as f:
  29.     # content=f.read()
  30.     for line in f:
  31.         if line.split('\t')[0] in kmers_map:
  32.             kmers_map[line.split('\t')[0]]=(kmers_map[line.split('\t')[0]][0],line.split('\t')[3],def_val)
  33.         # print(line.split('\t')[0])
  34.         # kmers_map[line.split('\t')[0]]=line.split('\t')[2]
  35. print(file_case+'_read')
  36. with open(file_cntl) as f:
  37.     # content=f.read()
  38.     for line in f:
  39.         if line.split('\t')[0] in kmers_map:
  40.             kmers_map[line.split('\t')[0]]=(kmers_map[line.split('\t')[0]][0],kmers_map[line.split('\t')[0]][1],line.split('\t')[3])
  41.         # print(line.split('\t')[0])
  42.         # kmers_map[line.split('\t')[0]]=line.split('\t')[2]
  43. print(file_cntl+'_read')
  44. # for kmer, pvals in kmers_map.items():
  45. #     i+=1
  46. #     print(kmer, pvals)
  47. #     if i>4:
  48. #         break
  49.  
  50. with open(outf,"w") as f:
  51.     f.write(file_q+'  '+file_case+'  '+file_cntl+'\n')
  52.     for kmer, pvals in kmers_map.items():
  53.         # if pvals[1]!=def_val or pvals[2]!=def_val:
  54.             f.write(kmer+'   '+pvals[0]+'   '+pvals[1]+'   '+pvals[2]+'\n')
  55.             # f.write('{0: <31}'.format())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement