Skip to content

Commit

Permalink
add a new component that lets the user upload their own predefined IC…
Browse files Browse the repository at this point in the history
…Ps (issue SouthernBio#9)
  • Loading branch information
heflavie committed Oct 26, 2024
1 parent f22722d commit 782151f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bioseeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions tools/upload_icps.py
Original file line number Diff line number Diff line change
@@ -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)}"

0 comments on commit 782151f

Please sign in to comment.