forked from aakechin/NGS-PrimerPlex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddSeqToPrimers.py
58 lines (54 loc) · 1.88 KB
/
addSeqToPrimers.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
49
50
51
52
53
54
55
56
57
58
import argparse,xlrd,os
import xlsxwriter as xls
thisDir=os.path.dirname(os.path.realpath(__file__))+'/'
parser=argparse.ArgumentParser(description='This script adds tags to primers for NGS')
parser.add_argument('--input','-in',dest='input',type=str,help='input XLS-file with designed primers')
parser.add_argument('--tags-file','-tags',dest='tagsFile',type=str,help='text file with tags that we want to add to each primer. Default: "'+thisDir+'kplex_for_primers.txt"',default=thisDir+'kplex_for_primers.txt')
args=parser.parse_args()
try:
file=open(args.tagsFile)
except FileNotFoundError:
print('ERROR! File with tags was not found:',args.tagsFile)
exit(0)
addSeq=[]
for string in file:
if 'For ' in string:
continue
addSeq.append(string.replace('\n','').replace('\r',''))
file.close()
wb=xlrd.open_workbook(args.input)
ws=wb.sheet_by_index(0)
primerNames=[]
primers=[]
for i in range(ws.nrows):
row=ws.row_values(i)
if i==0 or row[0]=='':
continue
if row[1]!='':
primerNames.append(row[3]+'_F')
primers.append(addSeq[0]+row[1])
if row[2]!='':
primerNames.append(row[3]+'_R')
primers.append(addSeq[1]+row[2])
# If there is also external primers
if len(wb.sheet_names())>1:
ws=wb.sheet_by_index(1)
for i in range(ws.nrows):
row=ws.row_values(i)
if i==0 or row[0]=='':
continue
if row[1]!='':
primerNames.append(row[3]+'_F')
primers.append(row[1])
if row[2]!='':
primerNames.append(row[3]+'_R')
primers.append(row[2])
wbw=xls.Workbook(args.input[:-4]+'_with_seq.xls')
wsw=wbw.add_worksheet('Primers')
wsw.write_row(0,0,['Primer',"5' to 3' sequence"])
wsw.set_column(0,0,25)
wsw.set_column(1,1,60)
for i,(name,primer) in enumerate(zip(primerNames,primers)):
wsw.write_row(i+1,0,[name,primer])
wbw.close()
print('NGS-PrimerPlex finished!')