diff --git a/.gitignore b/.gitignore index 7a8baad3fbb9055363fc60eda6a2113c091f85f5..2a680d3b0a4bafbaa25ed4d8d76d524aafe15891 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 4572092b49877321a9bb2f4fc1483a63bbbd1aed..bb7d5f3186cb2e516714c06c9a5e8d2b57696586 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 d96f6136bf181b6c98078bb94a222893ab6e1ef5..f2d67d0ee27756d0768524a508eac7cf441cb4ec 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