Commit a9f0c4ae authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

script to convert embl to genbank

parent c23a7e4b
#!/usr/bin/env python3
from Bio import SeqIO
from pathlib import Path
import click
from itertools import chain
@click.command()
@click.option(
"-d",
"--directory",
type=click.Path(exists=True, dir_okay=True, file_okay=True),
help="Genome input source",
)
@click.option("-o", "--output-dir", type=click.Path("wb"))
def convert_genomes(directory, output_dir):
genomes = gen_path_with_format(directory)
gen_genomes = gen_genomes_with_steam(genomes)
for filename, genome in gen_genomes:
write_genbank(genome, filename, output_dir)
def write_genbank(genome, filename, directory):
with open(Path(directory) / (filename + ".genbank"), "w") as output_handle:
print("-Write file " + filename)
SeqIO.write(genome, output_handle, "genbank")
def gen_path_with_format(input_str):
input_path = Path(input_str)
if input_path.is_dir():
for genome_path in chain(
map(lambda genome: ("embl", genome), input_path.rglob("*.embl")),
map(lambda genome: ("genbank", genome), input_path.rglob("*.gbk")),
):
yield genome_path
else:
suffix = input_path.suffix
if suffix == ".embl":
yield ("embl", input_path)
else:
yield ("genbank", input_path)
def gen_genomes_with_steam(genomes):
for genome_format, genome in genomes:
yield (str(Path(genome.stem)), SeqIO.parse(genome, genome_format))
if __name__ == "__main__":
convert_genomes()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment