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

fix linting #26

Merged
merged 14 commits into from
Jul 11, 2024
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
| :-- | :-- |
| (1/5) code repository | [![github repo badge](https://img.shields.io/badge/github-repo-000.svg?logo=github&labelColor=gray&color=blue)](https://github.com/RECETOX/rcx-tk) |
| (2/5) license | [![github license badge](https://img.shields.io/github/license/RECETOX/rcx-tk)](https://github.com/RECETOX/rcx-tk) |
| (3/5) community registry | [![RSD](https://img.shields.io/badge/rsd-rcx_tk-00a3e3.svg)](https://www.research-software.nl/software/rcx_tk) [![workflow pypi badge](https://img.shields.io/pypi/v/rcx_tk.svg?colorB=blue)](https://pypi.python.org/project/rcx_tk/) |
| (4/5) citation | [![DOI](https://zenodo.org/badge/DOI/<replace-with-created-DOI>.svg)](https://doi.org/<replace-with-created-DOI>) |
| (5/5) checklist | [![workflow cii badge](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>/badge)](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>) |
| (3/4) citation | [![DOI](https://zenodo.org/badge/DOI/<replace-with-created-DOI>.svg)](https://doi.org/<replace-with-created-DOI>) |
| (4/4) checklist | [![workflow cii badge](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>/badge)](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>) |
| howfairis | [![fair-software badge](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8B-yellow)](https://fair-software.eu) |
| **Other best practices** | &nbsp; |
| Static analysis | [![workflow scq badge](https://sonarcloud.io/api/project_badges/measure?project=RECETOX_rcx-tk&metric=alert_status)](https://sonarcloud.io/dashboard?id=RECETOX_rcx-tk) |
Expand Down
25 changes: 13 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

# -- Project information -----------------------------------------------------

project = u"rcx_tk"
copyright = u"2024, RECETOX, Masaryk University"
author = u"Zargham Ahmad"
project = "rcx_tk"
copyright = "2024, RECETOX, Masaryk University"
author = "Zargham Ahmad"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -61,7 +61,7 @@

# -- Use autoapi.extension to run sphinx-apidoc -------

autoapi_dirs = ['../src/rcx_tk']
autoapi_dirs = ["../src/rcx_tk"]

# -- Options for HTML output ----------------------------------------------

Expand All @@ -78,11 +78,12 @@

# -- Options for Intersphinx

intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
# Commonly used libraries, uncomment when used in package
# 'numpy': ('http://docs.scipy.org/doc/numpy/', None),
# 'scipy': ('http://docs.scipy.org/doc/scipy/reference/', None),
# 'scikit-learn': ('https://scikit-learn.org/stable/', None),
# 'matplotlib': ('https://matplotlib.org/stable/', None),
# 'pandas': ('http://pandas.pydata.org/docs/', None),
}
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
# Commonly used libraries, uncomment when used in package
# 'numpy': ('http://docs.scipy.org/doc/numpy/', None),
# 'scipy': ('http://docs.scipy.org/doc/scipy/reference/', None),
# 'scikit-learn': ('https://scikit-learn.org/stable/', None),
# 'matplotlib': ('https://matplotlib.org/stable/', None),
# 'pandas': ('http://pandas.pydata.org/docs/', None),
}
1 change: 1 addition & 0 deletions src/rcx_tk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Documentation about rcx_tk."""

import logging

logging.getLogger(__name__).addHandler(logging.NullHandler())
Expand Down
11 changes: 7 additions & 4 deletions src/rcx_tk/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import click

from rcx_tk.process_metadata_file import process_alkane_ri_file, process_metadata_file
from rcx_tk.process_metadata_file import process_alkane_ri_file
from rcx_tk.process_metadata_file import process_metadata_file


@click.command()
@click.option('--method', type=click.Choice(['metadata', 'alkanes']), required = True, help = 'A file type to be processed, either metadata or alkanes file.')
@click.option('--method', type=click.Choice(['metadata', 'alkanes']),
required = True,
help = 'A file type to be processed, either metadata or alkanes file.')
@click.argument('file_path')
@click.argument('out_path')
def main(method, file_path, out_path):
"""Process metadata or alkane file.

Args:
method (string): Whether a metadata or alkane file should be processed.
file_path (path): A path to the input data.
out_path (path): A path where the processed data will be exported to.
"""
Expand All @@ -23,4 +26,4 @@ def main(method, file_path, out_path):


if __name__ == "__main__":
main()
main()
29 changes: 13 additions & 16 deletions src/rcx_tk/process_metadata_file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import pandas as pd


def read_file(file_path: str) -> pd.DataFrame:
"""Imports the metadata file to pandas dataframe.
"""Imports the metadata file to pandas dataframe.

Args:
file_path (str): The path to the input data.
Expand All @@ -13,18 +14,17 @@ def read_file(file_path: str) -> pd.DataFrame:
Returns:
pd.DataFrame: Dataframe containing the metadata.
"""


file_extension = os.path.splitext(file_path)[1].lower()
if file_extension == '.csv':
return pd.read_csv(file_path, encoding='UTF-8')
elif file_extension in ['.xls', '.xlsx']:
if file_extension == ".csv":
return pd.read_csv(file_path, encoding="UTF-8")
elif file_extension in [".xls", ".xlsx"]:
return pd.read_excel(file_path)
elif file_extension in ['.tsv', '.txt']:
return pd.read_csv(file_path, sep='\t')
elif file_extension in [".tsv", ".txt"]:
return pd.read_csv(file_path, sep="\t")
else:
raise ValueError("Unsupported file format. Please provide a CSV, Excel, or TSV file.")


def save_dataframe_as_tsv(df: pd.DataFrame, file_path: str) -> None:
"""Saves the dataframe as a TSV file.

Expand All @@ -37,8 +37,8 @@ def save_dataframe_as_tsv(df: pd.DataFrame, file_path: str) -> None:
"""
if os.path.splitext(file_path)[1] != ".tsv":
raise ValueError("Unsupported file format. Please point to a TSV file.")
df.to_csv(file_path, sep='\t', index=False)
df.to_csv(file_path, sep="\t", index=False)


def process_metadata_file(file_path: str, out_path: str) -> None:
"""Processes a metadata file, keeping and renaming specific columns.
Expand All @@ -57,23 +57,20 @@ def process_metadata_file(file_path: str, out_path: str) -> None:

df = read_file(file_path)
df = df[list(columns_to_keep.keys())].rename(columns=columns_to_keep)
df['sampleName'] = df['sampleName'].str.replace(' ', '_')
df["sampleName"] = df["sampleName"].str.replace(" ", "_")
save_dataframe_as_tsv(df, out_path)


def process_alkane_ri_file(file_path: str, out_path: str) -> None:
"""Processes an alkane file, keeping and renaming specific columns.

Args:
file_path (str): A path to the alkane file.
out_path (str): A path where processed alkane file is exported.
"""
columns_to_keep = {
'Carbon number': 'carbon_number',
'RT (min)': 'rt'
}
columns_to_keep = {"Carbon number": "carbon_number", "RT (min)": "rt"}

df = read_file(file_path)
df.columns = df.columns.str.strip()
df = df.rename(columns=columns_to_keep)
save_dataframe_as_tsv(df, out_path)

Loading