-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemux10x.py
49 lines (45 loc) · 2.36 KB
/
demux10x.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
46
47
48
#! /usr/bin/python
import os
import argparse
def parse_user_input():
parser=argparse.ArgumentParser()
parser.add_argument('-m','--mode',required=True,choices=['single','dual'],help='Indicate single- or dual-index demultiplexing.')
parser.add_argument('-s','--sample-table',required=True,help='Path to 2- or 3-column tab-delimited text file with sample name, index sequence 1, and optionally, index sequence 2.')
parser.add_argument('-i1','--index1-fastq',required=True,help='Path to index read 1 (I1) fastq file.')
parser.add_argument('-i2','--index2-fastq',required=False,help='Path to index read 2 (I2) fastq file. This is required only for dual index demultiplexing.')
parser.add_argument('-t','--target-fastq',required=True,help='Path to the target fastq file that you want to demultiplex.')
parser.add_argument('-r','--target-read',required=True,choices=['R1','R2','I1','I2'],help='Illumina read to which the target fastq corresponds (R1, R2, I1, or I2).')
parser.add_argument('-l','--target-lane',required=True,help='Illumina lane to which the target fastq corresponds (e.g. L001, L002, etc)')
return parser
parser = parse_user_input()
ui = parser.parse_args()
if ui.mode == 'dual':
if ui.index2_fastq==None:
print('Error: Dual index demultiplexing requires index read 2 (I2) fastq file required for argument --index2-fastq')
exit()
else:
target=ui.target_fastq
index1=ui.index1_fastq
index2=ui.index2_fastq
read=ui.target_read
lane=ui.target_lane
with open(ui.sample_table) as f:
for line in f:
llist = line.split()
s=llist[0]
i1=llist[1]
i2=llist[2]
cmd = 'zcat %(target)s | python dual_index_demux.py -i1 %(index1)s -i2 %(index2)s -ind1 %(i1)s -ind2 %(i2)s -s %(s)s | gzip > %(s)s_%(lane)s_%(read)s_001.fastq.gz &' % vars()
os.system(cmd)
elif ui.mode=='single':
target=ui.target_fastq
index1=ui.index1_fastq
read=ui.target_read
lane=ui.target_lane
with open(ui.sample_table) as f:
for line in f:
llist=line.split()
s=llist[0]
i1=llist[1]
cmd = 'zcat %(target)s | python single_index_demux.py -ind %(i1)s -s %(s)s -i %(index1)s | gzip > %(s)s_%(lane)s_%(read)s_001.fastq.gz &' % vars()
os.system(cmd)