Skip to content
Snippets Groups Projects

Package this lib for pypi

Merged Remi PLANEL requested to merge add-gitlab-ci into dev
Files
7
+ 21
18
import click
from crisprbact import on_target_predict
from pathlib import Path
from Bio import SeqIO
import click
class Config(object):
@@ -11,6 +10,8 @@ class Config(object):
pass_config = click.make_pass_decorator(Config, ensure=True)
HEADER = ["target", "PAM position", "prediction", "seq_id"]
@click.group()
@click.option("-v", "--verbose", is_flag=True)
@@ -31,19 +32,17 @@ def predict(config):
@pass_config
def from_str(config, target, output_file):
"""
Outputs candidate guide RNAs for the S. pyogenes dCas9 with predicted on-target activity from a target gene.
Outputs candidate guide RNAs for the S. pyogenes dCas9 with predicted on-target
activity from a target gene.
[OUTPUT_FILE] file where the precitions are saved. Default = "stdout"
[OUTPUT_FILE] file where the candidate guide RNAs are saved. Default = "stdout"
"""
if config.verbose:
print_parameters(target)
guide_rnas = on_target_predict(target)
click.echo(
"\t".join(["target", "PAM position", "prediction", "input_id"]),
file=output_file,
)
click.echo("\t".join(HEADER), file=output_file)
write_guide_rnas(guide_rnas, output_file)
@@ -51,24 +50,28 @@ def from_str(config, target, output_file):
@click.option(
"-t", "--target", type=click.File("rU"), required=True, help="Sequence file"
)
@click.option("-f", "--seq-format", help="Sequence file format", default="fasta")
@click.option(
"-f",
"--seq-format",
type=click.Choice(["fasta", "fa", "gb", "genbank"]),
help="Sequence file format",
default="fasta",
show_default=True,
)
@click.argument("output-file", type=click.File("w"), default="-")
@pass_config
def from_seq(config, target, seq_format, output_file):
"""
Outputs candidate guide RNAs for the S. pyogenes dCas9 with predicted on-target activity from a target gene.
Outputs candidate guide RNAs for the S. pyogenes dCas9 with predicted on-target
activity from a target gene.
[OUTPUT_FILE] file where the precitions are saved. Default = "stdout"
[OUTPUT_FILE] file where the candidate guide RNAs are saved. Default = "stdout"
"""
fg = "blue"
if config.verbose:
print_parameters(target.name, fg)
# with open(target, "rU") as handle:
click.echo(
"\t".join(["target", "PAM position", "prediction", "input_id"]),
file=output_file,
)
click.echo("\t".join(HEADER), file=output_file)
for record in SeqIO.parse(target, seq_format):
if config.verbose:
click.secho(" - search guide RNAs for %s " % record.id, fg=fg)
@@ -81,7 +84,7 @@ def print_parameters(target, fg="blue"):
click.secho("Target sequence : %s" % target, fg=fg)
def write_guide_rnas(guide_rnas, output_file, input_id="N/A"):
def write_guide_rnas(guide_rnas, output_file, seq_id="N/A"):
for guide_rna in guide_rnas:
# click.echo(guide_rna)
@@ -91,7 +94,7 @@ def write_guide_rnas(guide_rnas, output_file, input_id="N/A"):
guide_rna["target"],
str(guide_rna["pam"]),
str(guide_rna["pred"]),
input_id,
seq_id,
]
),
file=output_file,
Loading