Entering edit mode
6.1 years ago
Galaxy123
▴
20
Hi,
I have a function that searches a csv database file for a disease (for example melanoma). The function will then produce a list of gene symbols that match the disease name in the file. However I want to create an error message that will be produced if the disease is not found within the file (for example Epilepsy is not in the database). Currently my code has an if statement that I know does not work, i'm new to Python so i'd really appreciate any help.
disease='melanoma'
input_file="curated_gene_disease_associations.tsv"
def select_disease_df(input_file,disease):
df=pd.read_csv(input_file, sep='\t')
selection=df['diseaseName']==disease
if disease not in df['diseaseName']:
raise Exception("Disease not found in database")
my_list=(df[selection]['geneSymbol']).tolist()
return(my_list)