forked from ShuXingYu94/Primer_Blast_Multiple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PBL_Local.py
137 lines (124 loc) · 5.29 KB
/
PBL_Local.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os
from PrimerBlast_Tools import Primer_Blast_Fuction as pb
gene_name = 'AHK2'
out_address = '/Users/******/Desktop/******/' # Needs a '/' in the end
db_address = '/Users/******/Desktop/ncbi-blast-2.10.1+/bin/******.fa'
print('Gene information recieved.')
evalue = 1
identity = 18
raw_seq='''ggggtcttcccccaagaattggtagatgtggttttggtgccggccgacatgtctatagct
tgtgagctctcgaatcccaatttaaagaagacaaaagcagaaaaacggataccaaccaag
attctgcttatccgggttttatgtggcttagttgttctctggctctgcttaagcttaagc
ttaggcttcttatgtatatgcaagaagaaagaggctgctgctgctgctgatgactcttct
tcttctgctaaagggatgttgttcaggaatcagagcagaagtgagattgatgctatgctt
tctctcttctttgattcaaatcaggtttcccactacttctttcttctttttattattgtt
tgacaatttaatttacttaaagcttttgaataattggagaacaggtaacatcttttgaat
gtcgcaaggagaatggtggtattacatgttccttgtcaacacgttccgagaaaggagacg
aggaggaggaggaggctaagagacatgttgttgcagaggttatgtcatcatctgagaatg
aagaagaaggaggtgtgctgcatcaggttgtgttgttttatgtaatgaacaaatggcatt
ggtggttggtcctttgtgtactactagtgggcggcggccgtgtgatatttgtaagaaaag
aagtttcttctttagtacaagacaagcagcagcagcagcagcaatgcaaaacagctggga
agtggaggaagaacatgcttctactcggcatcatcgcgggagtttctttgtctgttttat
ggttttgggataccaacgagaagatcttgttccaaaggaaagagacgttaaccaacatgt
gtgaggaacgagctcgggtgttgcaggaccagttcaatgttagcatgaaccatgtccacg
ccttgtccatcctcgtctctacctttcaccatggcaaaaccccttctgccattgatcagg
taaactaagagtccgaatggtaacatgtggtgcggttctaatagtaacaaaatcgtatag
atacatgtgtaaatctagagattttttaatgttaattgcggtgcgattctaatagtaaaa
aaaagtatagatacatgtgtatatctagagatttttgttattgttaactacgatggtgtt
ttaatagtaacaaaaacgtatagatacatatgtatatttagagatttttgttaatgttaa
ttgcggcgcggttctaatagtaaccaaaaagtatatatacatgtgtatatctagagattt
ttttaactgcggtgctgttccaatagtaacaaaaacgtatagatacatgtgtaaatctag
agatttttgttaatgttaattgtggtgcagttctaatagtaacaaaaacgtatagataca
tgtgtatatctaaagatttttgttaatgttaattgtggtgcggttccaatagtaacaaaa
acgtatagatacatgtgtaaatctagagatttttgttaatgttaattgtggtgcggttct
atagtaacaaaaacgtatagatacatgtgtatatctagagatttttgttaatgctaattg
tgctgcggtgcggttagaaataaaattccattcttaagatttttaactgttgattttttt
tttttcag'''
raw_seq=raw_seq.upper()
Nuc=list('ATGC')
target_seq=''
for nuc in raw_seq:
if nuc in Nuc:
target_seq+=nuc
# To get target DNA sequence with given name/information
seq_args = { # Set parameters: name,seq, include region etc.
'SEQUENCE_ID': gene_name,
'SEQUENCE_TEMPLATE': target_seq,
'SEQUENCE_INCLUDED_REGION': [0,len(target_seq)],
'SEQUENCE_TARGET': [],
'SEQUENCE_EXCLUDED_REGION': []
}
global_args = {
'PRIMER_OPT_SIZE': 20,
'PRIMER_PICK_INTERNAL_OLIGO': 0,
'PRIMER_INTERNAL_MAX_SELF_END': 8,
'PRIMER_MIN_SIZE': 18,
'PRIMER_MAX_SIZE': 25,
'PRIMER_OPT_TM': 60.0,
'PRIMER_MIN_TM': 50.0,
'PRIMER_MAX_TM': 68.0,
'PRIMER_MIN_GC': 20.0,
'PRIMER_MAX_GC': 80.0,
'PRIMER_MAX_POLY_X': 100,
'PRIMER_INTERNAL_MAX_POLY_X': 100,
'PRIMER_SALT_MONOVALENT': 50.0,
'PRIMER_DNA_CONC': 50.0,
'PRIMER_MAX_NS_ACCEPTED': 0,
'PRIMER_MAX_SELF_ANY': 12,
'PRIMER_MAX_SELF_END': 8,
'PRIMER_PAIR_MAX_COMPL_ANY': 12,
'PRIMER_PAIR_MAX_COMPL_END': 8,
'PRIMER_PRODUCT_SIZE_RANGE': [[100, 500], [500, 1000]],
'PRIMER_NUM_RETURN': 20
}
print('Parameters saved.')
print('Start designing primers for ', gene_name, '.')
primer_df = pb.design_primer(seq_args, global_args, out_address + gene_name + '_Original_Primer.txt')
# To get all primer pairs in the form of dataframe
primer_list = pb.extract_pairs(out_address + gene_name + '_Original_Primer.txt')
# Turn dataframe into list of primer pairs
print('\nStart confirming primer pairs...')
list_result = []
count = 0
list_r = []
list_f = []
for pair in primer_list:
print('\nChecking Primer pair ', str(count + 1), ':')
forward = pair[0]
tmp_f = open(out_address + "tmp_f.fasta", "w")
tmp_f.write("%s" % forward)
tmp_f.close()
reverse = pair[1]
tmp_r = open(out_address + "tmp_r.fasta", "w")
tmp_r.write("%s" % reverse)
tmp_r.close()
print('_Left Primer:')
f, f_n = pb.blastn(out_address + "tmp_f.fasta", db_address=db_address,
out_address1=out_address + gene_name + '_PBL.xml',
evalue=evalue, identity=len(forward)-2, task='blastn-short', dust='no')
print('_Right Primer:')
r, r_n = pb.blastn(out_address + "tmp_r.fasta", db_address=db_address,
out_address1=out_address + gene_name + '_PBL.xml',
evalue=evalue, identity=len(reverse)-2, task='blastn-short', dust='no')
list_f.append(f)
list_r.append(r)
if r == 1 and f == 1:
list_result.append(count)
# print('Primer Pair '+str(count)+': Forward/Reverse primer found '+str(f)+'/'+str(r)+' products on intended
# targets,respectively.')
count += 1
primer_df.loc['LEFT_PRIMER_PRODUCTS'] = list_f
primer_df.loc['RIGHT_PRIMER_PRODUCTS'] = list_r
pd_result = primer_df.iloc[:, list_result]
if pd_result.empty:
print('\nNo specified primer pair found. Try change parameters or increase primer numbers to return.')
else:
print('\nResult of useful primer(s):\n', pd_result)
pd_result.to_csv(out_address + gene_name + '_PrimerBlast_Result.csv')
print('\nResult saved.')
if os.path.exists(out_address + "tmp_f.fasta"):
os.remove(out_address + "tmp_f.fasta")
if os.path.exists(out_address + "tmp_r.fasta"):
os.remove(out_address + "tmp_r.fasta")
if os.path.exists(out_address + gene_name + '_PBL.xml'):
os.remove(out_address + gene_name + '_PBL.xml')