Last active
September 1, 2023 08:21
-
-
Save kaspermunch/f6530b173c4779295fdd56003d522275 to your computer and use it in GitHub Desktop.
Read gene lists from columns in a google sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_google_sheet(): | |
SHEET_ID = '1JSjSLuto3jqdEnnG7JqzeC_1pUZw76n7XueVAYrUOpk' | |
SHEET_NAME = 'Sheet1' | |
url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}' | |
df = pd.read_csv(url, header=1) | |
return df.loc[:, [not x.startswith('Unnamed') for x in df.columns]] | |
def gene_list_names(): | |
df = read_google_sheet() | |
return sorted(df.columns.tolist()) | |
def gene_list(name): | |
df = read_google_sheet() | |
sr = df[name] | |
return sr[~sr.isnull()] | |
gene_list_names() # prints names in row 2 (row 1 is descriptive header for the sheet on Google Drive) | |
xi_escape_genes = gene_list('xi-escape') # argument must be one of the labels returned by gene_list_names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment