Skip to content

Instantly share code, notes, and snippets.

@allaway
allaway / get_txgnn.R
Last active November 20, 2024 17:39
Get drug prediction values for a disease from TxGNN.org server
library(httr2)
library(dplyr)
library(purrr)
library(tibble)
library(dplyr)
##use this table to find your bert_grouped_disease_id
get_disease_map <- function(url = "http://txgnn.org/txgnn_data_v2/node_name_dict.json"){
id_map <- jsonlite::read_json(url)
dis_map <- id_map$disease %>%
@allaway
allaway / data.py
Created April 24, 2024 20:00
ChatGPT-generated script to change portal data status based on data present (not tested yet)
import synapseclient
import pandas as pd
# Constants for the views
FILE_VIEW_ID = "syn16858331"
PROJECT_VIEW_ID = "syn52677631"
def main():
syn = synapseclient.Synapse()
syn.login('YourUsername', 'YourPassword', rememberMe=True)
## prjna612365
for i in SRR11635884 SRR11635885 SRR11635886 SRR11635887 SRR11635888 SRR11635889 SRR11635890 SRR11635891 SRR11635892 SRR11635893 SRR11635894 SRR11635895 SRR11635896 SRR11635897 SRR11635898 SRR11635899 SRR11635900 SRR11635901 SRR11635902 SRR11635903 SRR11635904 SRR11635905 SRR11635906 SRR11635907 SRR11635908 SRR11635909 SRR11635910 SRR11635911 SRR11635912 SRR11635913 SRR11635914 SRR11635915 SRR11635916 SRR11635917 SRR11635918 SRR11635919 SRR11635920 SRR11635921 SRR11635922 SRR11635923 SRR11635924 SRR11635925 SRR11635926 SRR11635927 SRR11635928 SRR11635929 SRR11635930 SRR11635931 SRR11635932 SRR11635933 SRR11635934 SRR11635935 SRR11635936 SRR11635937 SRR11635938 SRR11635939 SRR11635940 SRR11635941 SRR11635942 SRR11635943 SRR11635944 SRR11635945 SRR11635946 SRR11635947 SRR11635948 SRR11635949 SRR11635950 SRR11635951 SRR11635952 SRR11635953 SRR11635954 SRR11635955 SRR11635956 SRR11635957 SRR11635958 SRR11635959 SRR11635960 SRR11635961 SRR11635962 SRR11635963 SRR11635964 SRR11635965 SRR11635966 SRR
@allaway
allaway / gist:e86402989a70ebde9efe8f181316fca6
Created November 9, 2023 21:04
convert column names in a google sheet to camelCase
library(googlesheets4)
gs4_auth()
convert_colname_to_camelcase <- function(ss_url) {
# Read the sheet
ss_data <- range_read(ss_url, n_max = 0)
colnames(ss_data)[colnames(ss_data)!="Component"] <- sapply(colnames(ss_data)[colnames(ss_data)!="Component"], stringr::str_replace, "_", " ")
# Convert column names to camelCase
@allaway
allaway / plot_incoming_data.R
Created November 9, 2023 21:00
Plot expected data for NF Data Portal using IncomingData table
library(ggplot2)
library(synapser)
library(lubridate)
library(tidyverse)
##datetime in unix time, integer
after_date <- 1704067200L
synLogin()
@allaway
allaway / update.R
Created November 9, 2023 20:57
Update NF Research Tools Central (temporary solution)
library(synapser)
library(googledrive)
library(googlesheets4)
library(tidyverse)
library(jsonlite)
gs4_auth()
synLogin()
goog_dir <- 'https://drive.google.com/drive/u/1/folders/1yblPMk-kgMj5KJi7P0AFOobZ9vkl6Nkk'
@allaway
allaway / validate.R
Last active November 9, 2023 21:03
submit manifests in a google drive folder to validation by manifest
library(googlesheets4)
library(nfportalutils)
submit_gs_to_api <- function(sheet_id,
schema_url) {
# Retrieve the Google Sheets document
sheet <- googlesheets4::gs4_get(sheet_id)
# Extract the workbook name and remove '.manifest' and split it on the underscore ("_")
workbook_name <- sheet$name
@allaway
allaway / conv_gs_to_cc.R
Created October 18, 2023 21:51
convert column names in google sheet to camelCase
library(googlesheets4)
gs4_auth()
convert_colname_to_camelcase <- function(ss_url) {
# Read the sheet
ss_data <- range_read(ss_url, n_max = 0)
colnames(ss_data)[colnames(ss_data)!="Component"] <- sapply(colnames(ss_data)[colnames(ss_data)!="Component"], stringr::str_replace, "_", "")
# Convert column names to camelCase
library(synapser)
library(tidyverse)
synLogin()
rename_columns <- function(data_frame, column_name_mapping) {
# Renaming the columns using dplyr
data_frame <- data_frame %>%
rename(!!!column_name_mapping)
# Return the modified data frame
@allaway
allaway / gist:9dd3707603f9595c0435853ff46e8d82
Created July 12, 2023 14:33
make nf-core/rnaseq manifest from Synapse fileview
library(synapser)
library(dplyr)
synLogin()
##query for files for manifest
query <- "SELECT id, specimenID, readPair FROM syn51907744 where fileFormat = 'fastq'"
key <- "readPair"
value <- "id"
res <- synTableQuery(query, includeRowIdAndRowVersion = F)$asDataFrame()