Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@idot
Created October 10, 2011 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idot/1275785 to your computer and use it in GitHub Desktop.
Save idot/1275785 to your computer and use it in GitHub Desktop.
converts 1.8+ illumina qualities somehow to 1.5+
#!/usr/bin/env python
def toIllu(c):
"""returns the 1.5 value of phred+33
>>> [toIllu(ord(n)) for n in["!",'"',"#","$","H","I","J"]]
['B', 'B', 'B', 'C', 'g', 'h', 'h']
"""
if c < 36:
return "B"
elif c > 73:
return "h"
else:
return chr(c+31)
def toArray(s):
"""to chr array
>>> toArray('!"#GHIJ')
[33, 34, 35, 71, 72, 73, 74]
"""
return [ord(c) for c in unpack('%sc' % len(s), s)]
import sys
from struct import unpack
def process(infile):
lineNo = 1
for line in open(infile):
if lineNo % 4 == 0 :
ill = [toIllu(c) for c in toArray(line.strip())]
print "".join(ill)
else:
print(line),
lineNo += 1
if __name__ == "__main__":
if sys.argv[1] == "-v":
import doctest
doctest.testmod()
else:
process(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment