Skip to content

Instantly share code, notes, and snippets.

@audy
Created May 4, 2011 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save audy/955875 to your computer and use it in GitHub Desktop.
Save audy/955875 to your computer and use it in GitHub Desktop.
illuminaobscura.py
#!/usr/bin/env python
from glob import glob
from PIL import Image, ImageDraw
from itertools import defaultdict
# Create matrix
matrix = defaultdict(dict)
lanes = [1, 2, 3, 4, 5, 6, 7]
# Open every QSEQ file and get average quality scores:
# Use only one pair from the paired end sequencing.
for filename in glob('s_*_1_*qseq*'):
with open(filename) as handle:
for line in handle:
line = line.split('\t')[8]
x, y, qual = int(line[4]), int(line[5]), line[9]
qual = [ ord(i) for i in qual if i != 'B' ]
# Get average quality for read x, y
average_qual = sum(qual)/float(len(qual))
# Put it in the matrix:
matrix[x][y] = average
# Optional, save matrix:
# import cPickle as pickle
# with open('quality_matrix.pickle', 'w') as output:
# pickle_dump(output, matrix)
# Load matrix:
# with open('quality_matrix.pickle') as handle:
# matrix = pickle_load(handle)
# Draw picture
MEAN = 99
GOOD = "#f00"
BAD = "#0f0"
SIZE = (20000, 20000) # I knew the size beforehand
image = Image.new('RGB', SIZE)
draw = ImageDraw.Draw(image)
for i in matrix:
for j in matrix[k]:
if matrix[k][v] > MEAN: draw.point((i, j), GOOD))
else: draw.point((i, j), BAD))
image.save("IlluminaObscura.png", "png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment