Skip to content

Commit

Permalink
Merge pull request #8 from FridleyLab/oospina_dev
Browse files Browse the repository at this point in the history
error msg if no var genes in pca
  • Loading branch information
oospina authored Apr 22, 2024
2 parents d58d553 + 26e2b17 commit 51f1e0e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 14 additions & 10 deletions R/pseudobulk_samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ pseudobulk_samples = function(x=NULL, max_var_genes=5000){
# Turn transformed counts to a transposed matrix.
tr_df <- t(as.matrix(tr_df))

# Need at least two variable genes to create 2 PCs
if(max_var_genes < 2){
raise_err(err_code='error0005')
}
# Check that number of genes specified by user is lower than genes available across all samples
min_genes_pseudobulk = ncol(tr_df)
if(max_var_genes > min_genes_pseudobulk){
Expand Down Expand Up @@ -168,23 +172,23 @@ pseudobulk_pca_plot = function(x=NULL, color_pal='muted', plot_meta=NULL, pcx=1,
pcy = grep(paste0('^PC', pcy, '$'), colnames(pca_tbl), value=T)

# Make plot
pca_p = ggplot(pca_tbl) +
pca_p = ggplot2::ggplot(pca_tbl) +
#geom_point(aes(x=.data[[pcx]], y=.data[[pcy]], shape=.data[[plot_meta]], color=.data[[plot_meta]]), size=ptsize) +
geom_point(aes(x=.data[[pcx]], y=.data[[pcy]], color=.data[[plot_meta]]), size=ptsize) +
ggrepel::geom_text_repel(aes(x=.data[[pcx]], y=.data[[pcy]], label=pca_labs)) +
xlab(paste0(pcx, ' (', round(x@misc[['pbulk_pca_var']][pcx], 3) * 100, '%)')) +
ylab(paste0(pcy, ' (', round(x@misc[['pbulk_pca_var']][pcy], 3) * 100, '%)'))
ggplot2::geom_point(ggplot2::aes(x=.data[[pcx]], y=.data[[pcy]], color=.data[[plot_meta]]), size=ptsize) +
ggrepel::geom_text_repel(ggplot2::aes(x=.data[[pcx]], y=.data[[pcy]], label=pca_labs)) +
ggplot2::xlab(paste0(pcx, ' (', round(x@misc[['pbulk_pca_var']][pcx], 3) * 100, '%)')) +
ggplot2::ylab(paste0(pcy, ' (', round(x@misc[['pbulk_pca_var']][pcy], 3) * 100, '%)'))

if(plot_meta == 'pca_labs'){
pca_p = pca_p + labs(color='Sample')
pca_p = pca_p + ggplot2::labs(color='Sample')
}

pca_p = pca_p +
scale_color_manual(values=cat_cols) +
ggplot2::scale_color_manual(values=cat_cols) +
#scale_shape_manual(values=cat_shapes) +
ggtitle('PCA of "pseudobulk" samples') +
coord_fixed() +
theme_bw()
ggplot2::ggtitle('PCA of "pseudobulk" samples') +
ggplot2::coord_fixed() +
ggplot2::theme_bw()

return(pca_p)
}
Expand Down
3 changes: 2 additions & 1 deletion inst/err.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
error0001,'STlist -> process_sample_names: A sample name matches more than one expression path.'
error0002,'STlist -> process_lists: The ROI/spot/cell IDs in the count data (columns) and coordinate data (rows) do not match.'
error0003,'STlist -> detect_input: The input lists are not named. Please input named lists.'
error0004,'STlist -> detect_input: The samples argument requires a file path to clinical data or a vector with sample IDs. Data frames are not currently supported.'
error0004,'STlist -> detect_input: The samples argument requires a file path to clinical data or a vector with sample IDs. Data frames are not currently supported.'
error0005,'pseudobulk_samples: At least two variable genes are necessary to calculate principal components.'

0 comments on commit 51f1e0e

Please sign in to comment.