-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tao Zhu
committed
Jul 19, 2019
1 parent
6ac1485
commit bfed0a5
Showing
7 changed files
with
186 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# pysam | ||
|
||
# primer3-py | ||
# flask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env python3 | ||
|
||
'''Here is the title | ||
Here is the document | ||
''' | ||
|
||
__author__ = 'Tao Zhu' | ||
__copyright__ = 'Copyright 2019' | ||
__license__ = 'GPL' | ||
__version__ = '0.1' | ||
__email__ = '[email protected]' | ||
__status__ = 'Development' | ||
|
||
import argparse | ||
import re | ||
import os | ||
import json | ||
import shutil | ||
|
||
from distutils.version import LooseVersion | ||
|
||
import make_sites, make_primers, design_primer, run_blast, sort_primers, output | ||
|
||
parser = argparse.ArgumentParser(description='PrimerServer2: a high-throughput primer \ | ||
design and specificity-checking platform', formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
parser.add_argument('query', help='query file. (STDIN is acceptable)', type=argparse.FileType('r')) | ||
parser.add_argument('template', help='template file in FASTA format') | ||
|
||
group = parser.add_mutually_exclusive_group() | ||
group.add_argument('--no-specificity', help="Don't check specificity; Only design primers", action='store_true') | ||
group.add_argument('--only-specificity', help="Only check specificity and skip primer designs", action='store_true') | ||
parser.add_argument('--type', choices=['SEQUENCE_TARGET', 'SEQUENCE_INCLUDED_REGION', 'FORCE_END'],\ | ||
help='primer types', default='SEQUENCE_TARGET') | ||
parser.add_argument('-p', '--cpu', type=int, help='Used CPU number.', default=2) | ||
parser.add_argument('-l', '--checking-size-min', type=int, help='Lower limit of the checking amplicon size range (bp).', \ | ||
default=70) | ||
parser.add_argument('-u', '--checking-size-max', type=int, help='Upper limit of the checking amplicon size range (bp).', \ | ||
default=1000) | ||
parser.add_argument('-r', '--primer-num-retain', type=int, help='The maximum number of primers for each site to return.', \ | ||
default=10) | ||
parser.add_argument('-a', '--report-amplicon-seqs', help="Get amplicon seqs (might be slow)", action='store_true') | ||
parser.add_argument('--json-debug', help="Output debug information in JSON mode", action='store_true') | ||
parser.add_argument('-o', '--out', help="Output primers in JSON format", type=argparse.FileType('w')) | ||
parser.add_argument('-t', '--tsv', help="Output primers in TSV format", type=argparse.FileType('w')) | ||
args = parser.parse_args() | ||
|
||
def error(msg): | ||
if args.json_debug is True: | ||
print(json.dumps({'ERROR': msg})) | ||
raise Exception(msg) | ||
|
||
############### Check Environments ############### | ||
if shutil.which('samtools') is None: | ||
error('No samtools detected in your system') | ||
|
||
samtools_version = os.popen('samtools --version').readlines()[0].strip().split(' ')[1] | ||
if LooseVersion(samtools_version) < LooseVersion('1.9'): | ||
error(f'Your samtools version is v{samtools_version}, but >=v1.9 is required') | ||
|
||
if shutil.which('blastn') is None: | ||
error('No NCBI-BLAST+ (blastn) detected in your system') | ||
|
||
if shutil.which('makeblastdb') is None: | ||
error('No NCBI-BLAST+ (makeblastdb) detected in your system') | ||
|
||
############### Check Template File (FASTA) ####### | ||
if os.path.isfile(args.template) is False: | ||
error(f'File not found: {args.template}') | ||
if os.path.isfile(args.template+'.fai') is False: | ||
code = os.system(f'samtools faidx {args.template} 2>/dev/null') | ||
if code != 0: | ||
error(f'File {args.template} cannot be indexed by samtools faidx. Perhaps it is not in FASTA format') | ||
|
||
############### Run ############################### | ||
#### primers #### | ||
query_string = args.query.read() | ||
if args.only_specificity is True: | ||
primers = make_primers.make_primers(query=query_string) | ||
else: | ||
sites = make_sites.build(query=query_string, template_file=args.template, primer_type=args.type) | ||
primers = design_primer.multiple(sites, cpu=args.cpu) | ||
|
||
#### specificity #### | ||
dbs = [args.template] | ||
if args.no_specificity is False: | ||
primers = run_blast.run_blast_parallel(primers=primers, dbs=dbs, cpu=args.cpu,\ | ||
checking_size_max=args.checking_size_max, checking_size_min=args.checking_size_min, \ | ||
report_amplicon_seq=args.report_amplicon_seqs) | ||
primers = sort_primers.sort_rank(primers=primers, dbs=dbs, max_num_return=args.primer_num_retain) | ||
|
||
#### output ######### | ||
if args.out is not None: | ||
print(json.dumps(primers, indent=4), file=args.out) | ||
else: | ||
print(json.dumps(primers, indent=4)) | ||
|
||
if args.tsv is not None: | ||
if args.no_specificity is False: | ||
output.after_check(primers, dbs, file=args.tsv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters