Created
October 10, 2011 16:52
-
-
Save idot/1275785 to your computer and use it in GitHub Desktop.
converts 1.8+ illumina qualities somehow to 1.5+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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