|
| 1 | +##figure ploting functions incorporates and standardizes the calls made across figures |
| 2 | + |
| 3 | +library(ggplot2) |
| 4 | +library(dplyr) |
| 5 | +library(ggridges) |
| 6 | +library(synapser) |
| 7 | + |
| 8 | +##COLORS: standardize here |
| 9 | +modelcolors <- c() |
| 10 | +datasetcolors <- c() |
| 11 | + |
| 12 | +exvivo = c('mpnst','beataml','sarcpdo','pancpdo','bladderpdo') |
| 13 | + |
| 14 | +synapser::synLogin() |
| 15 | + |
| 16 | +getModelPerformanceData <- function(){ |
| 17 | + |
| 18 | + allscoreslist <- list(deepttc = 'syn65880080',graphdrp = 'syn65928973',lgbm = 'syn65880116',pathdsp = 'syn65880133',uno = 'syn65676159') |
| 19 | + |
| 20 | + ##with pancpdo |
| 21 | + allscoreslist <- list(deepttc = 'syn66323471',graphdrp = 'syn66323492',lgbm = 'syn66323510',pathdsp = 'syn66326173',uno = 'syn66323527') |
| 22 | + |
| 23 | + fullres <- do.call(rbind,lapply(names(allscoreslist),function(mod) |
| 24 | + readr::read_csv(synapser::synGet(allscoreslist[[mod]])$path) |> mutate(model = mod))) |
| 25 | + |
| 26 | + fullres <- fullres |> |
| 27 | + mutate(withinDataset = ifelse(src == trg,TRUE,FALSE)) |
| 28 | + |
| 29 | + #lets remove same-dataset data |
| 30 | + cdres <- subset(fullres,!withinDataset) |
| 31 | + |
| 32 | + ##lets remove ex vivo training |
| 33 | + cdres <- subset(cdres,!src %in% c('mpnst','beataml')) |
| 34 | + |
| 35 | + return(cdres) |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +###these files are very big so i'm not sure how to deal with them. |
| 41 | +getModelPredictionData<-function(dset='lgbm'){ |
| 42 | + |
| 43 | + preds <- list(deepttc = 'syn68149793', graphdrp = 'syn68146828', lgbm = 'syn68149807', pathdsp = 'syn66772452', uno = 'syn68149809') |
| 44 | + |
| 45 | + |
| 46 | + fullres <- do.call(rbind,lapply(dset,function(mod) |
| 47 | + readr::read_csv(synapser::synGet(preds[[mod]])$path) |> mutate(model = mod))) |
| 48 | + |
| 49 | + return(preds) |
| 50 | +} |
| 51 | + |
| 52 | +#this function plots a single metric by all the possible values |
| 53 | +# |
| 54 | +ridgelineMetricPlots <- function(metric,dataset=cdres, prefix='all'){ |
| 55 | + |
| 56 | + sr <- dataset |> |
| 57 | + subset(met == metric) |
| 58 | + |
| 59 | + |
| 60 | + ##facet by source - compare performance across a single source |
| 61 | + |
| 62 | + ##re-rank src samples by mean metrics |
| 63 | + mvals <- sr |> group_by(src) |> |
| 64 | + summarize(mvals = mean(value)) |> |
| 65 | + arrange(mvals) |
| 66 | + |
| 67 | + if (metric == 'r2') { |
| 68 | + sr$value <- sapply(sr$value,function(x) ifelse(x < (-1),-1,x)) |
| 69 | + } |
| 70 | + |
| 71 | + sr$src = factor(sr$src,levels = mvals$src) |
| 72 | + |
| 73 | + #compare models by source dataset |
| 74 | + p1 <- sr |> |
| 75 | + ggplot(aes(x = value,y = trg,fill = model)) + |
| 76 | + ggridges::geom_density_ridges(alpha = 0.5) + |
| 77 | + facet_grid(src~.) + |
| 78 | + ggtitle(paste0(metric,' by source dataset')) |
| 79 | + |
| 80 | + ##now we rerank by target dataset and evaluate by target |
| 81 | + mvals <- sr |> group_by(trg) |> |
| 82 | + summarize(mvals = mean(value)) |> |
| 83 | + arrange(mvals) |
| 84 | + sr$trg = factor(sr$trg,levels = mvals$trg) |
| 85 | + |
| 86 | + #plot source by target data |
| 87 | + p3 <- sr |> |
| 88 | + ggplot(aes(x = value,y = src,fill = model)) + |
| 89 | + ggridges::geom_density_ridges(alpha = 0.5) + |
| 90 | + facet_grid(trg~.) + |
| 91 | + ggtitle(paste0(metric,' by target dataset')) |
| 92 | + |
| 93 | + return(list(src=p1,trg=p3)) |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | +##here we have to interrogate the results to visualize how specific drugs are behaving |
| 98 | +performanceByDrugOrSample<-function(){ |
| 99 | + |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +##do we still need this function? |
| 104 | + |
| 105 | +doModelPlot <- function(metric, dataset=cdres){ |
| 106 | + |
| 107 | + sr <- dataset |> |
| 108 | + subset(met == metric) |
| 109 | + ##re-rank src samples by mean metric |
| 110 | + mvals <- sr |> |
| 111 | + group_by(trg) |> |
| 112 | + summarize(mvals = mean(value)) |> |
| 113 | + arrange(mvals) |
| 114 | + |
| 115 | + if(metric == 'r2') { |
| 116 | + sr$value <- sapply(sr$value,function (x) ifelse(x<(-1),-1,x)) |
| 117 | + } |
| 118 | + |
| 119 | + sr$trg = factor(sr$trg,levels = mvals$trg) |
| 120 | + |
| 121 | + sr |> |
| 122 | + subset(trg %in% exvivo) |> |
| 123 | + ggplot(aes(x = value,alpha = 0.8)) + |
| 124 | + geom_histogram() + facet_grid(model~trg) + |
| 125 | + ggtitle(paste0(metric,' evaluated on ex vivo data')) |
| 126 | + |
| 127 | + |
| 128 | + ggsave(paste0(metric,'exVivoPerformance.png')) |
| 129 | + |
| 130 | + |
| 131 | + sr |> subset(!trg %in% exvivo) |> |
| 132 | + ggplot(aes(x = value,alpha = 0.8)) + |
| 133 | + geom_histogram() + facet_grid(model~trg) + |
| 134 | + ggtitle(paste0(metric,' evaluated on cell line data')) |
| 135 | + |
| 136 | + |
| 137 | + ggsave(paste0(metric,'CellLinePerformance.png')) |
| 138 | + |
| 139 | +} |
0 commit comments