4 from optparse import OptionParser
9 parser = OptionParser()
10 parser.add_option('-o', '--output', help='output fastq file', default=None)
11 parser.add_option('-s', '--slice',
12 help='specify python slice, e.g. 0:75, 0:-1',
16 def parse_slice(slice_text):
17 if slice_text is None or len(slice_text) == 0:
21 for element in slice_text.split(':'):
25 element = int(element)
26 slice_data.append(element)
28 return slice(*slice_data)
30 def qseq2fastq(destination, qseqs, trim=None):
34 record = line.strip().split('\t')
35 machine_name = record[0]
36 run_number = record[1]
37 lane_number = record[2]
44 # Illumina scores are Phred + 64
45 # Fastq scores are Phread + 33
46 # the following code grabs the string, converts to short ints and
47 # subtracts 31 (64-33) to convert between the two score formats.
48 # The numpy solution is twice as fast as some of my other
49 # ideas for the conversion.
50 # sorry about the uglyness in changing from character, to 8-bit int
51 # and back to a character array
52 quality = numpy.asarray(record[9],'c')
53 quality.dtype = numpy.uint8
55 quality.dtype = '|S1' # I'd like to know what the real numpy char type is
59 destination.write('@%s_%s:%s:%s:%s:%s pf=%s%s' % ( \
68 destination.write(sequence[trim])
69 destination.write(os.linesep)
70 destination.write('+')
71 destination.write(os.linesep)
72 destination.write(quality[trim].tostring())
73 destination.write(os.linesep)
75 def main(cmdline=None):
76 parser = make_parser()
77 opts, args = parser.parse_args(cmdline)
79 if opts.output is not None:
80 dest = open(opts.output, 'w')
84 subseq = parse_slice(opts.slice)
86 qseq2fastq(dest, args, subseq)
90 if __name__ == "__main__":