Skip to content
Snippets Groups Projects
Commit dd1be418 authored by Laros's avatar Laros
Browse files

Removed old assignment.

parent 59406270
Branches
No related tags found
No related merge requests found
#!/usr/bin/env python
from sequencer import Sequencer
def quality(quals):
return sum(quals) / len(quals)
def trim(read, quals, score):
for position in range(len(read) - 1, -1, -1):
if quals[position] >= score:
return read[:position + 1], quals[:position + 1]
def make_fastq():
spots = 2
run = Sequencer(spots)
reads = ["" for _ in range(spots)]
quals = [[] for _ in range(spots)]
for tile in run:
for read_id, base in enumerate(tile):
reads[read_id] += base[0]
quals[read_id].append(base[1])
for read_id, read in enumerate(reads):
print read, quality(quals[read_id])
read, quals[read_id] = trim(read, quals[read_id], 39)
print read, quality(quals[read_id])
if __name__ == "__main__":
make_fastq()
#!/usr/bin/env python
from sequencer import Sequencer
if __name__ == "__main__":
for tile in Sequencer(20):
print tile
#!/usr/bin/env python
import random
class Sequencer(object):
"""
Simulate a sequencing run.
For every iteration, return a tile of data points as a list of tuples. The
first element of the tuple contains the nucleotide, the second element
contains the quality score.
"""
bases = ['A', 'C', 'G', 'T']
def __init__(self, spots, readlength=100):
self.cycle = 0
self.readlength = readlength
self.spots = spots
def __iter__(self):
return self
def __len__(self):
return self.readlength
def next(self):
self.cycle += 1
if self.cycle > self.readlength:
raise StopIteration
tile = []
for _ in range(self.spots):
nucleotide = self.bases[random.randrange(4)]
quality = 40 - (self.cycle * random.randrange(40) /
self.readlength)
tile.append((nucleotide, quality))
return tile
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment