Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assembly.download module and Events.dump logging updated #203

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion pipelines/nextflow/modules/download/download_asm_data.nf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ process DOWNLOAD_ASM_DATA {

shell:
'''
assembly_download --accession !{meta.accession} --asm_download_dir ./
assembly_download --accession !{meta.accession} --asm_download_dir ./ -d
'''
}
34 changes: 26 additions & 8 deletions src/python/ensembl/io/genomio/assembly/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,6 @@ def retrieve_assembly_data(
download_path = Path(download_dir)
download_dir = download_path / accession

# Configure logging
log_file = f"{accession}_download.log"
reload(logging)
logging.basicConfig(
filename=log_file, format="%(levelname)s:%(message)s", filemode="w", level=logging.DEBUG
)

# Set and create dedicated dir for download
if not download_dir.is_dir():
download_dir.mkdir(parents=True)
Expand Down Expand Up @@ -277,10 +270,35 @@ def retrieve_assembly_data(
def main() -> None:
"""Module's entry-point."""
parser = ArgumentParser(description="Download an assembly data files from INSDC or RefSeq.")
parser.add_argument("-v", "--verbose", action="store_true", required=False,
help="Verbose level logging")
parser.add_argument("-d", "--debug", action="store_true", required=False,
help="Debug level logging")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should place these after the mandatory arguments ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I can do, only reason I put them there was I thought it was needed given they are optional flag not positional args

"The add_argument() method must know whether an optional argument, like -f or --foo, or a positional argument, like a list of filenames, is expected. The first arguments passed to add_argument() must therefore be either a series of flags, or a simple argument name."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that sentence refers to the first arguments passed to the function add_argument(), i.e. add_argument("-f", "--foo", ...), and not to the parser.

parser.add_argument("--accession", required=True, help="Genome assembly accession")
parser.add_argument_dst_path(
"--download_dir", default=Path.cwd(), help="Folder where the data will be downloaded"
)
args = parser.parse_args()

retrieve_assembly_data(**vars(args))
# Configure logging
log_file = ("assembly_download.log")
JAlvarezJarreta marked this conversation as resolved.
Show resolved Hide resolved
date_format='%m/%d/%Y_%I:%M:%S(%p)'
JAlvarezJarreta marked this conversation as resolved.
Show resolved Hide resolved
logging_format='%(asctime)s - %(levelname)s - %(message)s'
reload(logging)
if args.verbose:
logging.basicConfig(
filename=log_file, format=logging_format, datefmt=date_format,
filemode="w", level=logging.INFO
)
elif args.debug:
logging.basicConfig(
filename=log_file, format=logging_format, datefmt=date_format,
filemode="w", level=logging.DEBUG
)
else:
logging.basicConfig(
filename=log_file, format=logging_format, datefmt=date_format,
filemode="w", level=logging.WARNING
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can factorize this further with something like:

Suggested change
if args.verbose:
logging.basicConfig(
filename=log_file, format=logging_format, datefmt=date_format,
filemode="w", level=logging.INFO
)
elif args.debug:
logging.basicConfig(
filename=log_file, format=logging_format, datefmt=date_format,
filemode="w", level=logging.DEBUG
)
else:
logging.basicConfig(
filename=log_file, format=logging_format, datefmt=date_format,
filemode="w", level=logging.WARNING
)
log_level = None
if args.debug:
log_level = logging.DEBUG
elif args.verbose:
log_level = logging.INFO
logging.basicConfig(
filename=log_file, format=logging_format, datefmt=date_format,
filemode="w", level=log_level
)

Note that I've put debug before verbose: assuming we get the 2 params, I suppose debug should take priority.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually better handled by the add_mutually_exclusive_group() when adding the parameters to the parser [link].


retrieve_assembly_data(args.accession, args.download_dir)