-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_as_fastq.py
executable file
·45 lines (35 loc) · 1.11 KB
/
print_as_fastq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/env python3
# Print the reads in a PIP/NGS database.
# John Conery / Kevin Xu Junjie
# University of Oregon
# 2014-04-15
import sqlite3
import argparse
from FASTQ import *
fetch_reads = 'SELECT read_id, read FROM R{}'
def print_sequences(args):
db = sqlite3.connect(args.dbname)
for n in [1,2]:
sql = fetch_reads.format(n)
if args.limit is not None:
sql += ' LIMIT {}'.format(args.limit)
for rid, blob in db.execute(sql).fetchall():
x = FASTQ(blob)
x._def = "{}.{}".format(n,rid)
x.unpack()
print(x)
###
# Set up command line arguments
def init_api():
parser = argparse.ArgumentParser(
description="Print the sequences in a PIP/NGS database.",
epilog="If a limit N is specified the first N reads from both ends of paired end read are printed."
)
parser.add_argument('dbname', help='the name of the SQLite database file')
parser.add_argument('-l', '--limit', required=False, help='number of sequences to print')
return parser.parse_args()
###
# Parse the command line arguments, call the top level function...
if __name__ == "__main__":
args = init_api()
print_sequences(args)