Renaming project to NSBDiagnosisToolkit
This commit is contained in:
23
src/nsbdiagnosistoolkit/cli/aggregator.py
Normal file
23
src/nsbdiagnosistoolkit/cli/aggregator.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from os import path
|
||||
from typing import Any, AsyncGenerator, AsyncIterable, Iterable, Sequence
|
||||
from nsbdiagnosistoolkit.engine.data.MLST import MLSTProfile
|
||||
from nsbdiagnosistoolkit.engine.data.genomics import NamedString
|
||||
from nsbdiagnosistoolkit.engine.local.abif import read_abif
|
||||
from nsbdiagnosistoolkit.engine.local.fasta import read_fasta
|
||||
from nsbdiagnosistoolkit.engine.remote.databases.institutpasteur.profiling import InstitutPasteurProfiler
|
||||
|
||||
|
||||
async def aggregate_sequences(fastas: Iterable[str], abifs: Iterable[str]) -> AsyncGenerator[str, Any]:
|
||||
for fasta_path in fastas:
|
||||
async for fasta in read_fasta(fasta_path):
|
||||
yield fasta.sequence
|
||||
for abif_path in abifs:
|
||||
abif_data = await read_abif(abif_path)
|
||||
yield "".join(abif_data.sequence)
|
||||
|
||||
async def profile_all_genetic_strings(strings: AsyncIterable[str], database_name: str) -> Sequence[MLSTProfile]:
|
||||
profiles = list()
|
||||
async with InstitutPasteurProfiler(database_name=database_name) as profiler:
|
||||
async for string in strings:
|
||||
profiles.append(await profiler.profile_string(string))
|
||||
return profiles
|
58
src/nsbdiagnosistoolkit/cli/program.py
Normal file
58
src/nsbdiagnosistoolkit/cli/program.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
from os import path
|
||||
|
||||
from nsbdiagnosistoolkit.cli import aggregator
|
||||
from nsbdiagnosistoolkit.engine.data.genomics import NamedString
|
||||
from nsbdiagnosistoolkit.engine.local.abif import read_abif
|
||||
from nsbdiagnosistoolkit.engine.local.csv import write_mlst_profiles_as_csv
|
||||
from nsbdiagnosistoolkit.engine.local.fasta import read_fasta
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--fasta", "-fa", "-fst",
|
||||
nargs="+",
|
||||
action='extend',
|
||||
dest="fastas",
|
||||
required=False,
|
||||
default=[],
|
||||
type=str,
|
||||
help="The FASTA files to process. Multiple can be listed."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--abif", "-abi", "-ab1",
|
||||
action='extend',
|
||||
dest="abifs",
|
||||
required=False,
|
||||
default=[],
|
||||
type=str,
|
||||
help="The ABIF files to process. Multiple can be listed."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--institut-pasteur-mlst",
|
||||
"-ipdbmlst",
|
||||
dest="institut_pasteur_db",
|
||||
type=str,
|
||||
help="The Institut Pasteur MLST database to use."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-csv",
|
||||
dest="csv_path",
|
||||
required=False,
|
||||
default=None,
|
||||
help="The destination to place the CSV output."
|
||||
)
|
||||
|
||||
|
||||
def cli():
|
||||
args = parser.parse_args()
|
||||
gen_strings = aggregator.aggregate_sequences(args.fastas, args.abifs)
|
||||
mlst_profiles = aggregator.profile_all_genetic_strings(
|
||||
gen_strings, args.institut_pasteur_db)
|
||||
asyncio.run(write_mlst_profiles_as_csv(
|
||||
asyncio.run(mlst_profiles), str(args.csv_path)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
Reference in New Issue
Block a user