Skip to content

Commit

Permalink
ruff errors resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
KristinaGomoryova committed Jul 3, 2024
1 parent d8114ab commit ece56c0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extras = dev

[tool.ruff]
# Enable Pyflakes `E` and `F` codes by default.
select = [
lint.select = [
"F", # Pyflakes
"E", # pycodestyle (error)
"W", # pycodestyle (warning)
Expand All @@ -57,7 +57,7 @@ select = [
# "PLW", # Warning

]
ignore = [
lint.ignore = [
'D100', # Missing module docstring
'D104', # Missing public package docstring
# The following list excludes rules irrelevant to the Google style
Expand All @@ -76,8 +76,8 @@ ignore = [
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "I"]
unfixable = []
lint.fixable = ["A", "B", "C", "D", "E", "F", "I"]
lint.unfixable = []

exclude = [
".bzr",
Expand All @@ -102,16 +102,16 @@ exclude = [
".venv",
"scripts",
]
per-file-ignores = {}
lint.per-file-ignores = {}


# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

target-version = "py39"
line-length = 120

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["rcx_tk"]
force-single-line = true
no-lines-before = ["future","standard-library","third-party","first-party","local-folder"]
Expand All @@ -129,4 +129,4 @@ filename = "pyproject.toml"
filename = "CITATION.cff"

[[tool.bumpversion.files]]
filename = "docs/conf.py"
filename = "docs/conf.py"
44 changes: 23 additions & 21 deletions src/rcx_tk/process_metadata_file.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
import pandas as pd
import os
import pandas as pd


def read_file(file_path):
"""Reads a file and returns a DataFrame based on the file extension."""
file_extension = os.path.splitext(file_path)[1].lower()
if file_extension == '.csv':
if file_extension == ".csv":
return pd.read_csv(file_path)
elif file_extension in ['.xls', '.xlsx']:
elif file_extension in [".xls", ".xlsx"]:
return pd.read_excel(file_path)
elif file_extension == '.txt':
return pd.read_csv(file_path, sep='\t')
elif file_extension == ".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, file_path):
"""Saves a DataFrame as a TSV file."""
output_file = f'processed_{os.path.splitext(os.path.basename(file_path))[0]}.tsv'
df.to_csv(output_file, sep='\t', index=False)
output_file = f"processed_{os.path.splitext(os.path.basename(file_path))[0]}.tsv"
df.to_csv(output_file, sep="\t", index=False)
print(f"Processed file saved as: {output_file}")


def process_metadata_file(file_path):
"""Processes a metadata file, keeping and renaming specific columns."""
columns_to_keep = {
'File name': 'sampleName',
'Type': 'sampleType',
'Class ID': 'class',
'Batch': 'batch',
'Analytical order': 'injectionOrder'
"File name": "sampleName",
"Type": "sampleType",
"Class ID": "class",
"Batch": "batch",
"Analytical order": "injectionOrder",
}

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, file_path)


def process_alkane_ri_file(file_path):
"""Processes an Alkane RI file, keeping and renaming specific columns."""
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, file_path)


# File paths
metadata_file_path = 'metadata file path'
alkane_file_path = 'alkane file path'
metadata_file_path = "metadata file path"
alkane_file_path = "alkane file path"

# Process files
process_metadata_file(metadata_file_path)
Expand Down

0 comments on commit ece56c0

Please sign in to comment.