Skip to content
Snippets Groups Projects
Commit c30df085 authored by Mate Balajti's avatar Mate Balajti
Browse files

feat: add logging and update setup.py

parent 9e097418
No related branches found
No related tags found
1 merge request!7feat: add logging and update setup.py
Pipeline #17272 passed
"""cDNA generator."""
import warnings
import logging
from typing import Optional, List, Dict, Any
import pandas as pd # type: ignore
from Bio import SeqIO # type: ignore
......@@ -7,6 +8,8 @@ from Bio.Seq import Seq # type: ignore
from Bio.SeqRecord import SeqRecord # type: ignore
from gtfparse import read_gtf # type: ignore
LOG = logging.getLogger(__name__)
# ignore warnings from read_gtf
warnings.filterwarnings(action="ignore", category=FutureWarning)
......@@ -23,7 +26,7 @@ def complement(res: str) -> str:
"""
translate_dict = {"A": "T", "T": "A", "U": "A", "G": "C", "C": "G"}
if res not in translate_dict:
print(f"Unknown character, {res}")
LOG.warning("Unknown character, %s", res)
raise ValueError
return translate_dict[res]
......@@ -40,7 +43,9 @@ def seq_complement(sequence: str) -> Optional[str]:
"""
if sequence is None:
return None
_ = "".join([complement(char) for char in str(sequence)])[::-1] # reverse string # noqa: E501
_ = "".join([
complement(char) for char in str(sequence)
])[::-1] # reverse string
return _
......@@ -179,6 +184,9 @@ class CDNAGen:
# alongside the names of any optional keys \
# which appeared in the attribute column
gtf_df = read_gtf(self.gtf)
gtf_df = gtf_df.to_pandas() # convert polars df to pandas df
gtf_df["Binding_Probability"] = pd.to_numeric(
gtf_df["Binding_Probability"]
) # convert to numeric
......@@ -225,7 +233,7 @@ class CDNAGen:
"""
SeqIO.write(self.fasta_records, self.output_fasta, "fasta")
print(f"Fasta file successfully written to: {self.output_fasta}")
LOG.info("Fasta file successfully written to: %s", self.output_fasta)
def write_csv(self) -> None:
"""Write the copy number information to a csv file.
......@@ -237,5 +245,5 @@ class CDNAGen:
"""
df_to_save = self.gtf_df[["cdna_ID", "Transcript_Copy_Number"]]
df_to_save.to_csv(self.output_csv, index=False)
print(f"Copy number csv file successfully written to: \
{self.output_csv}")
LOG.info("Copy number csv file successfully written to: %s",
self.output_csv)
......@@ -3,10 +3,17 @@
import argparse
import logging
from cdna.cdna import CDNAGen
logging.basicConfig(
format='[%(asctime)s: %(levelname)s] %(message)s \
(module "%(module)s")',
level=logging.INFO,
)
LOG = logging.getLogger(__name__)
from cdna.cdna import CDNAGen # noqa: E402,E501 # pylint:disable=wrong-import-position
def cdna_parser() -> CDNAGen:
def main():
"""Parse sequences for cDNA generator.
Parses command line arguments for cDNA generation.
......@@ -35,27 +42,16 @@ def cdna_parser() -> CDNAGen:
"-ocsv", "--output_csv", help="output fasta file", required=True
)
args = parser.parse_args()
# Print parser arguments
print(" \n".join(f"{k}={v}" for k, v in vars(args).items()))
print()
cdna_inst = CDNAGen(
LOG.info("Running cDNA generator...")
CDNAGen(
ifasta=args.input_fasta,
igtf=args.input_gtf,
icpn=args.input_copy_number,
ocsv=args.output_csv,
ofasta=args.output_fasta,
)
return cdna_inst
if __name__ == "__main__":
logging.basicConfig(
format='[%(asctime)s: %(levelname)s] %(message)s \
(module "%(module)s")',
level=logging.INFO,
)
LOG = logging.getLogger(__name__)
print("**********************")
print("Running cDNA generator")
print("**********************")
cdna_parser()
main()
python cdna/cli.py -ifa test_files/yeast_example.fa \
-icpn test_files/copy_number_input.csv \
-igt test_files/Example_GTF_Input.GTF \
-ofa test_files/cDNA.fasta -ocsv test_files/cDNA.csv
\ No newline at end of file
"""Set up project."""
from pathlib import Path
from setuptools import setup, find_packages
with open('requirements.txt') as f:
required = f.read().splitlines()
project_root_dir = Path(__file__).parent.resolve()
with open(project_root_dir / "requirements.txt",
"r", encoding="utf-8") as f:
INSTALL_REQUIRED = f.read().splitlines()
URL = ('https://git.scicore.unibas.ch/zavolan_group/'
'tools/cdna-generator')
setup(
name='cdna',
url='https://gitlab.com/my_user_name/my_package.git',
author='My Name',
author_email='me@email.org',
description='Brief package description',
name='cdna-generator',
version='0.1.1',
url=URL,
license='MIT',
version='1.0.0',
packages=find_packages(), # this will autodetect Python packages from the directory tree, e.g., in `code/`
install_requires=required, # add here packages that are required for your package to run, including version or range of versions
author='Eric Boittier, Bastian Wagner, Quentin Badolle',
author_email='me@email.org',
description='cDNA generator',
packages=find_packages(),
install_required=INSTALL_REQUIRED,
entry_points={
'console_scripts': [
'cdna-generator=cdna.cli:main'
]
}
)
>1
GAUAGCUAGAGGAUUCUCAGAGGAGAAGCUAGAGGAGCUAGAGGAGCUAGAGGAGCUAGAGGAGCUAGAGG
>2
AGCUAGAGGAUAGCUAGAGGAUAGCUAGAGGAUAGCUAGAGGAGCUAGAGGAGCUAGAGGAGCUAGAGG
>3
AGCUAGAGGAUAGCUAGAGGAUAGCUAGAGGAUAGCUAGAGGAUAGCUAGAGGAGCUAGAGG
>4
AGCUAGAGGAUAGCUAGAGGAUAGCUAGAGGAUAGCUAGAGGAUAGCUAGAGGAGCUAGAGGAGCUAGAGG
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment