From b4cc85c3c4456f59023f16ae4e8feb187febfb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Balajti?= <mate.balajti@unibas.ch> Date: Mon, 31 Jul 2023 15:37:27 +0200 Subject: [PATCH] feat: add cli support --- .gitignore | 7 ++- .../input_files}/expression.csv | 0 {input_files => tests/input_files}/test.gtf | 0 transcript_sampler/__init__.py | 2 +- transcript_sampler/{new_exe.py => cli.py} | 59 +++++++++++------- .../images}/.gitkeep | 0 .../screenshot_git_tutorial_1_hGillet.png | Bin .../screenshot_git_tutorial_2_hGillet.png | Bin .../screenshot_markdown_tutorial_hGillet.png | Bin .../obsolete_scripts}/exon_length_filter.py | 0 .../org_test_representative.py | 0 .../obsolete_scripts}/representative.py | 0 .../obsolete_scripts}/transcript_extractor.py | 0 13 files changed, 44 insertions(+), 24 deletions(-) rename {input_files => tests/input_files}/expression.csv (100%) rename {input_files => tests/input_files}/test.gtf (100%) rename transcript_sampler/{new_exe.py => cli.py} (59%) rename {images => transcript_sampler/images}/.gitkeep (100%) rename {images => transcript_sampler/images}/screenshot_git_tutorial_1_hGillet.png (100%) rename {images => transcript_sampler/images}/screenshot_git_tutorial_2_hGillet.png (100%) rename {images => transcript_sampler/images}/screenshot_markdown_tutorial_hGillet.png (100%) rename {scripts => transcript_sampler/obsolete_scripts}/exon_length_filter.py (100%) rename {scripts => transcript_sampler/obsolete_scripts}/org_test_representative.py (100%) rename {scripts => transcript_sampler/obsolete_scripts}/representative.py (100%) rename {scripts => transcript_sampler/obsolete_scripts}/transcript_extractor.py (100%) diff --git a/.gitignore b/.gitignore index 7a8baad..2a680d3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,9 @@ # ignore ALL files in ANY directory named temp temp/ __pycache__ -output_files \ No newline at end of file +output_files +*_cache +*egg-info/ +.coverage +build/ +*/play.py \ No newline at end of file diff --git a/input_files/expression.csv b/tests/input_files/expression.csv similarity index 100% rename from input_files/expression.csv rename to tests/input_files/expression.csv diff --git a/input_files/test.gtf b/tests/input_files/test.gtf similarity index 100% rename from input_files/test.gtf rename to tests/input_files/test.gtf diff --git a/transcript_sampler/__init__.py b/transcript_sampler/__init__.py index 4572092..bb7d5f3 100644 --- a/transcript_sampler/__init__.py +++ b/transcript_sampler/__init__.py @@ -1 +1 @@ -"""Init.py.""" +"""Initialise package.""" diff --git a/transcript_sampler/new_exe.py b/transcript_sampler/cli.py similarity index 59% rename from transcript_sampler/new_exe.py rename to transcript_sampler/cli.py index d96f613..f2d67d0 100644 --- a/transcript_sampler/new_exe.py +++ b/transcript_sampler/cli.py @@ -1,46 +1,56 @@ -"""This module executes the transcript_sampler""" +"""This module executes the transcript_sampler.""" import argparse import time import logging -logging.basicConfig( - format='[%(asctime)s: %(levelname)s] %(message)s (module "%(module)s")', - level=logging.INFO, - ) -from find_reptrans import FindRepTrans # pylint: disable=E0401,C0413 -from match_reptrans_explvl import MatchReptransExplvl # pylint: disable=E0401,C0413 -from poisson_sampling import SampleTranscript # pylint: disable=E0401,C0413 +from find_reptrans import FindRepTrans +from match_reptrans_explvl import MatchReptransExplvl +from poisson_sampling import SampleTranscript find_rep_trans = FindRepTrans() match_reptrs_explvl = MatchReptransExplvl() poisson_sample = SampleTranscript() -LOG = logging.getLogger(__name__) +logging.basicConfig( + format='[%(asctime)s: %(levelname)s] %(message)s \ + (module "%(module)s")', + level=logging.INFO, +) +LOG = logging.getLogger("main") -def exe(input_gtf, input_csv, output_gtf, output_csv, transcript_nr): +def main(args: argparse.Namespace): """Execute transcript sampler.""" start = time.time() LOG.info("Started transcript sampler...") - dict_repr_trans = find_rep_trans.get_rep_trans(input_gtf) + dict_repr_trans = find_rep_trans.get_rep_trans(args.input_gtf) df_repr = match_reptrs_explvl.match_repr_transcript_expression_level( - dict_reprTrans=dict_repr_trans, exprTrans=input_csv, gtf_file=input_gtf + dict_reprTrans=dict_repr_trans, + exprTrans=args.input_csv, + gtf_file=args.input_gtf ) LOG.info( "Finding match between representative transcripts \ and expression level file" ) LOG.info("Poisson sampling of transcripts") - poisson_sample.transcript_sampling(transcript_nr, df_repr, output_csv) + poisson_sample.transcript_sampling( + args.transcript_nr, df_repr, args.output_csv) LOG.info("Output CSV file ready") LOG.info("Writing output GTF file") - find_rep_trans.gtf_file_writer(input_gtf, dict_repr_trans, output_gtf) + find_rep_trans.gtf_file_writer( + args.input_gtf, dict_repr_trans, args.output_gtf) end = time.time() LOG.info("Script executed in %s sec", (end - start)) -if __name__ == "__main__": +def parse_arguments() -> argparse.Namespace: + """Request parameters from user on CLI. + + Returns: + argparse.Namespace: object of arguments from CLI. + """ parser = argparse.ArgumentParser( description="Transcript sampler", formatter_class=argparse.ArgumentDefaultsHelpFormatter, @@ -67,12 +77,17 @@ if __name__ == "__main__": help="Total number of transcripts to sample" ) args = parser.parse_args() - print(args) - exe( - args.input_gtf, - args.input_csv, - args.output_gtf, - args.output_csv, - args.n_to_sample, + return args + + +if __name__ == '__main__': + logging.basicConfig( + format='[%(asctime)s: %(levelname)s] %(message)s \ + (module "%(module)s")', + level=logging.INFO, ) + logger = logging.getLogger(__name__) + + arguments = parse_arguments() + main(arguments) diff --git a/images/.gitkeep b/transcript_sampler/images/.gitkeep similarity index 100% rename from images/.gitkeep rename to transcript_sampler/images/.gitkeep diff --git a/images/screenshot_git_tutorial_1_hGillet.png b/transcript_sampler/images/screenshot_git_tutorial_1_hGillet.png similarity index 100% rename from images/screenshot_git_tutorial_1_hGillet.png rename to transcript_sampler/images/screenshot_git_tutorial_1_hGillet.png diff --git a/images/screenshot_git_tutorial_2_hGillet.png b/transcript_sampler/images/screenshot_git_tutorial_2_hGillet.png similarity index 100% rename from images/screenshot_git_tutorial_2_hGillet.png rename to transcript_sampler/images/screenshot_git_tutorial_2_hGillet.png diff --git a/images/screenshot_markdown_tutorial_hGillet.png b/transcript_sampler/images/screenshot_markdown_tutorial_hGillet.png similarity index 100% rename from images/screenshot_markdown_tutorial_hGillet.png rename to transcript_sampler/images/screenshot_markdown_tutorial_hGillet.png diff --git a/scripts/exon_length_filter.py b/transcript_sampler/obsolete_scripts/exon_length_filter.py similarity index 100% rename from scripts/exon_length_filter.py rename to transcript_sampler/obsolete_scripts/exon_length_filter.py diff --git a/scripts/org_test_representative.py b/transcript_sampler/obsolete_scripts/org_test_representative.py similarity index 100% rename from scripts/org_test_representative.py rename to transcript_sampler/obsolete_scripts/org_test_representative.py diff --git a/scripts/representative.py b/transcript_sampler/obsolete_scripts/representative.py similarity index 100% rename from scripts/representative.py rename to transcript_sampler/obsolete_scripts/representative.py diff --git a/scripts/transcript_extractor.py b/transcript_sampler/obsolete_scripts/transcript_extractor.py similarity index 100% rename from scripts/transcript_extractor.py rename to transcript_sampler/obsolete_scripts/transcript_extractor.py -- GitLab