Skip to content

Commit ef3a43d

Browse files
committed
add getpos_primers.py to add positions for primerdesign.py output
1 parent 0133c04 commit ef3a43d

5 files changed

Lines changed: 124 additions & 10 deletions

File tree

bin/getpos_primers.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python
2+
#-*- coding: utf-8 -*-
3+
#@Time : 17/7/2023 10:18 pm
4+
#@Author : Runsheng
5+
#@File : getpos_primers.py
6+
7+
"""
8+
get the position using ispcr function for all output from primerdiffer.py
9+
run example:
10+
cd /t1/ref_BN
11+
getpos_primers.py -f primer10.txt -g cb5.fa -o primer10_pos.txt
12+
"""
13+
14+
import argparse
15+
import os,sys
16+
17+
# self import
18+
from primerdiffer.primer_check import insilicon_pcr, product2seqdic
19+
from primerdiffer.utils import checkblastdb, dic2fasta, dic2dic,fasta2dic
20+
21+
22+
parser=argparse.ArgumentParser()
23+
parser.add_argument("-d", "--wkdir", default=None,
24+
help="The dir path contain the file, if not given, use the current dir")
25+
# input
26+
parser.add_argument("-f", "--file",
27+
help="the 4 col table generated by primerdesign.py")
28+
29+
parser.add_argument("-g", "--genome",
30+
help="the fasta file used to design primer")
31+
32+
# primer cutoff
33+
parser.add_argument("--alignlen", type=int, default=16,
34+
help="the cutoff of primer min align length as a right hit, default is 16")
35+
parser.add_argument("--free3len", type=int, default=2,
36+
help="the cutoff of primer 3' align length as a right hit, default is 2")
37+
parser.add_argument("--productlen", type=int, default=2000,
38+
help="the cutoff of max product which will be treated as a false priming, default is 2000.")
39+
40+
# output paramenter
41+
parser.add_argument("-o", "--out", default="primerpos.txt",
42+
help="output file, contains possible amplification regions of this primer pair")
43+
44+
# default handler
45+
args = parser.parse_args(args=None if sys.argv[1:] else ['--help'])
46+
wkdir=os.getcwd() if args.wkdir is None else args.wkdir
47+
48+
# main
49+
checkblastdb(args.genome) # check blastdb, if no, run makeblastdb
50+
seqdic=dic2dic(fasta2dic(args.genome))
51+
52+
def read_primerdiffer_out(filename):
53+
lines=[]
54+
with open(filename, "r") as f:
55+
for line in f.readlines():
56+
line_l=line.strip().split("\t")
57+
lines.append(line_l)
58+
return lines
59+
60+
lines=read_primerdiffer_out(args.file)
61+
62+
lines_new=[]
63+
for line_l in lines:
64+
name_raw, forward, reverse, length_str=line_l
65+
66+
product_l=insilicon_pcr(primer_left=forward,
67+
primer_right=reverse,
68+
db=args.genome,
69+
cutoff_alignlength=args.alignlen,
70+
cutoff_free3=args.free3len,
71+
product_cutoff=args.productlen
72+
)
73+
74+
outdic=product2seqdic(product_l,seqdic)
75+
name_pos=list(outdic.keys())[0]
76+
seq=outdic[name_pos]
77+
line_one=[name_raw, forward, reverse, length_str, name_pos, seq]
78+
lines_new.append(line_one)
79+
80+
with open(args.out, "w") as fw:
81+
for line_one in lines_new:
82+
fw.write("\t".join(line_one))
83+
fw.write("\n")

primerdiffer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__= "0.1.5"
1+
__version__= "0.1.6"

readme.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,47 @@ primerdesign.py -g1 cb5.fa -g2 cn3_new.fa -pos "ChrX:12881200-15106660" --interv
7070
```
7171

7272
```
73-
# check the result in file "primers_ChrX:12881200-15106660.txt"
74-
head primers_ChrX\:12881200-15106660.txt
73+
# check the result in file "primers_ChrX_12881200-15106660.txt"
74+
head primers_ChrX_12881200-15106660.txt
7575
#ChrX:12881200-12881700 GATCCAAAACATGAGTGGCC CGAGATCATTGGCTCAAAGT 287
7676
#ChrX:12886200-12886700 GTTTTCTCTTCAAGTGCCCG CTCCCACATCTTGTAGGTCC 416
7777
#ChrX:12891200-12891700 GTAGATGCTGTTGAGGCTCT CGAGTGGGACATTGTCAGTA 299
7878
#ChrX:12896200-12896700 GGCGCATTATACGAAGCTTT TTCCTGCTGCCAGATAGAAG 362
7979
```
8080

81+
## Case example: use getpos_primers.py to annotate the primerdiffer.py output with position and in silicon PCR result
8182

82-
Use in silico PCR to get the position and the product of the primer
83+
```bash
84+
usage: getpos_primers.py [-h] [-d WKDIR] [-f FILE] [-g GENOME] [--alignlen ALIGNLEN] [--free3len FREE3LEN] [--productlen PRODUCTLEN] [-o OUT]
85+
86+
optional arguments:
87+
-h, --help show this help message and exit
88+
-d WKDIR, --wkdir WKDIR
89+
The dir path contain the file, if not given, use the current dir
90+
-f FILE, --file FILE the 4 col table generated by primerdesign.py
91+
-g GENOME, --genome GENOME
92+
the fasta file used to design primer
93+
--alignlen ALIGNLEN the cutoff of primer min align length as a right hit, default is 16
94+
--free3len FREE3LEN the cutoff of primer 3' align length as a right hit, default is 2
95+
--productlen PRODUCTLEN the cutoff of max product which will be treated as a false priming, default is 2000.
96+
-o OUT, --out OUT output file, contains possible amplification regions of this primer pair
97+
```
98+
99+
```bash
100+
# example: first check the input file format, the col4 is from the primerdesign.py output
101+
head primers_ChrX_12881200-15106660.txt
102+
#ChrX:12881200-12881700 GATCCAAAACATGAGTGGCC CGAGATCATTGGCTCAAAGT 287
103+
104+
# run get_posprimers.py
105+
getpos_primers.py -f primers_ChrX_12881200-15106660.txt -g cb5.fa -o primer_pos.txt
106+
107+
# the output is 6 col table
108+
#ChrX:12881200-12881700 GATCCAAAACATGAGTGGCC CGAGATCATTGGCTCAAAGT 287 ChrX:12881301-12881587 ATCCAAAACATGAG....
109+
```
110+
111+
112+
## Case example: in silico PCR for one primer
113+
Use in silico PCR to get the position and the product of one primer
83114
```
84115
usage: ispcr.py [-h] [-d WKDIR] [-f FORWARD] [-r REVERSE] [-g GENOME] [--alignlen ALIGNLEN]
85116
[--free3len FREE3LEN] [--productlen PRODUCTLEN] [-o OUT]
@@ -102,7 +133,6 @@ optional arguments:
102133
-o OUT, --out OUT output file, contains all possible amplification regions of this primer pair
103134
```
104135
105-
## Case example: in silico PCR product
106136
107137
```bash
108138
ispcr.py -f gcactttcatgtccctcaac -r cactctattctcaccccacc -g cb5.fa -o ispcr.fa
@@ -119,6 +149,7 @@ head ispcr.fa
119149
#ATGATGATGATGATGGTGGGGTGAGAATAGAGT
120150
```
121151
152+
122153
## Case example: Design general purpose primers with given parameters
123154
The default primer design parameter is described in [general_setting.py](https://github.com/Runsheng/primerdiffer/blob/master/primerdiffer/general_settings.py):
124155
```python
@@ -163,5 +194,4 @@ Please kindly cite our paper in bioinformatics if you find primerdiffer or prime
163194
164195
## Other functions:
165196
1. To design the primer using VCF file for closely related haplotypes (i.e., strain/individual level differences). Please check primervcf package.
166-
2. Todo: To update the RFLP method for primer design to differ sequences with almost identical sequence.
167-
197+
2. add the primerdffer output table description and ispcr function for the output.

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
install_requires = ["primer3-py>=0.6.1",
1919
"biopython>=1.78"],
2020
scripts = ['bin/primerdesign.py',
21-
'bin/ispcr.py'
21+
'bin/ispcr.py',
22+
'bin/getpos_primers.py'
2223
]
2324
)
2425

test/test_walk_chr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def setUp(self):
3030
def test_config_dump_load(self):
3131
import json
3232
from primerdiffer.general_settings import primer3_general_settings
33-
with open("./test/primer3config", "w") as fw:
34-
json.dump(primer3_general_settings, )
33+
with open("./primer3config", "w") as fw:
34+
json.dump(primer3_general_settings, fw)
3535

3636

3737
def test_walk_chr_dense(self):

0 commit comments

Comments
 (0)