From 782151f37fdc2e4d57ed73d6a1fd578cbfe3ea5a Mon Sep 17 00:00:00 2001 From: heflavie Date: Sat, 26 Oct 2024 10:34:54 +0200 Subject: [PATCH] add a new component that lets the user upload their own predefined ICPs (issue #9) --- bioseeker.py | 9 +++++++++ tools/upload_icps.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tools/upload_icps.py diff --git a/bioseeker.py b/bioseeker.py index d5ce388..f099ce2 100755 --- a/bioseeker.py +++ b/bioseeker.py @@ -7,9 +7,18 @@ from tools.delete import delete_csv_files from utils.intro import intro_message from os import getcwd +from upload_icps import upload_icps + def main(): intro_message() + + # Ask the user to upload an ICP file + file_path = input("Please enter the path of the ICP file to upload: ") + upload_message = upload_icps(file_path) + print(upload_message) + + # Generating list of files on current working directory BASE_PATH = getcwd() files = lf.list_of_files(BASE_PATH) diff --git a/tools/upload_icps.py b/tools/upload_icps.py new file mode 100644 index 0000000..0905f99 --- /dev/null +++ b/tools/upload_icps.py @@ -0,0 +1,32 @@ +# upload_icps.py +import pandas as pd +import os + +def upload_icps(file_path: str): + """Function to upload ICPs from a CSV file and store it in the appropriate directory. + + Args: + file_path (str): Path of the file to upload. + + Returns: + str: Confirmation message. + """ + if not os.path.exists(file_path) or not file_path.endswith('.csv'): + return "The file does not exist or is not a valid CSV file." + + try: + df = pd.read_csv(file_path) + + # Check if the file contains the necessary columns (adapt as needed) + required_columns = ['Codon', 'ConservationRate'] # Example of expected columns + if not all(col in df.columns for col in required_columns): + return "The CSV file does not contain all required columns." + + # Save the file to a specific directory + output_dir = 'user_uploaded_icps' + os.makedirs(output_dir, exist_ok=True) + df.to_csv(os.path.join(output_dir, 'uploaded_icps.csv'), index=False) + + return "ICPs file uploaded successfully." + except Exception as e: + return f"Error while uploading the ICPs file: {str(e)}"