Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1.  
  2. ########################################################################
  3. #This script is used to convert BWA-generated .sam files to the IGB .gr
  4. #file format.
  5. ########################################################################
  6.  
  7. import re
  8. import string
  9. import sys
  10. from math import *
  11. from Bio import SeqIO
  12. import numpy as np
  13. from array import array
  14.  
  15. #set the constant for the start and end of the genome -- adjust this for different genome
  16. #for subtilis genome, this is from version 3 file
  17. GENOME_START_POS = 1
  18. GENOME_END_POS = 4215606
  19.  
  20. geno = array('I')
  21. for x in range(GENOME_END_POS-1):
  22.     geno.append(0)
  23.  
  24.  
  25. with open(sys.argv[1]) as f:
  26.     for line in f:
  27.         if not line.startswith('@'):
  28.             read = line.split()
  29.             pos = int(read[3])
  30.             for i in range(pos+1,pos+51):
  31.                 #print pos
  32.                 geno[i] = geno[i]+1
  33.            
  34. outfile=open(sys.argv[2],'w')
  35. x=0
  36. percent = 0
  37. part = GENOME_END_POS / 20
  38. for i in geno:
  39.     x+=1
  40.     outfile.write(str(x)+' '+str(i)+'\n')
  41.     if (x % part == 0):
  42.         percent+=5
  43.         print str(percent)+"%"
  44. outfile.close()
  45. print 'done'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement