saezlab / transcriptutorial

This is a tutorial to guide the analysis of RNAseq dataset using footprint based tools such as DOROTHEA, PROGENY and CARNIVAL
https://saezlab.github.io/transcriptutorial/
GNU General Public License v3.0
55 stars 30 forks source link

could not find function "magicPlotMakerLight" #40

Closed dilipgosar closed 2 years ago

dilipgosar commented 2 years ago

Dear Sir/ Madam,

I am trying R code for normalisation in transcriptutorial. I am getting following error at this step

plots <- magicPlotMakerLight(df = log2(count_df), targets = targets) Error in magicPlotMakerLight(df = log2(count_df), targets = targets) : could not find function "magicPlotMakerLight"

It seems it is not able to find magicPlotMakeLight function. I like to know to which package this function belongs and if you can fix this code.

Appreciate your help.

Sincerely,

Dilip Gosar

CheyennedeVriend commented 2 years ago

Hi there, I ran into the same problem previously. I found the support function online. You can copy paste the following piece of code:

#'\code{magicPlotMakerLight}
#'
#'This function is designed to generate and save a battery of plots aimed at helping visualise a measurments dataframe.
#'The function generate 3 plots to directly visualise measurements in the form of a cloud of points, a series of boxplots and surperimposed density curves.
#'It also genereate a pca plot (using nicePCA unction if a targets table is provided).
#'Finally it generates two heatmap, on directly clustering over the measurments and another one performing a clustring over the cross-correlation matrix of the samples.
#'The plots are directly saved to a folder. Nothing is returned.
#'
#'@param df the measurment n*m dataframe (n is number of omic features, m is number of samples) where columns are ordered by conditions.
#'@param targets A n*2 dataframe, where n is the number of samples. First column correspond to samples, second column correspond to conditions.
magicPlotMakerLight <- function(df, targets = NULL, no_pca_label = FALSE)
{

  if (!is.null(targets))
  {
    df_and_targets <- make_df_and_targets_great_again(df,targets)
    df <- df_and_targets[[1]]
    targets <- df_and_targets[[2]]
  }

  ##This part is just to generate the melted dataframe for ggplot
  df$ID <- row.names(df)

  melted_df <- reshape::melt(df)
  index <- c(1:length(melted_df[,1]))

  df <- df[,-length(df[1,])]

  #########################################
  ##                ggplots              ##
  #########################################

  violins <- ggplot(melted_df, aes(x = index, y = value, group = variable, color = variable)) + geom_violin() + theme_minimal()

  # plot(violins)

  complete_df <- df[complete.cases(df),]

  t_complete_df <- t(complete_df)
  if (is.null(targets)){
    PCA <- prcomp(t_complete_df ,center = TRUE, scale. = T)
    pcaPlot <- plot(PCA$x[,1],PCA$x[,2], pch = 19, xlab = paste("PC1 (",as.character(round(PCA$sdev[1]^2/sum(PCA$sdev^2)*100)),"%)"), ylab = paste("PC2 (",as.character(round(PCA$sdev[2]^2/sum(PCA$sdev^2)*100)),"%)"), main = "PCA of samples")
    text(PCA$x[,1],PCA$x[,2], labels = names(PCA$x[,1]), pos = 3)
  }
  else
  {
    if (no_pca_label)
    {
      pcaPlot <- nicePCA(df = complete_df, targets, c(1,2,3), no_label = T)
    }
    else
    {
      pcaPlot <- nicePCA(df = complete_df, targets, c(1,2,3))
    }
  }
  # plot(pcaPlot)
  return(list(violins,pcaPlot))
}

plotTF <- function(TF, geneLevelStats, regulon_df)
{
  names(geneLevelStats) <- c("ID","stat")
  targets <- regulon_df[regulon_df$TF == TF,]
  names(targets) <- c("ID","TF","sign")
  target_stats <- merge(geneLevelStats,targets, by = "ID")
  target_stats$stat <- target_stats$stat * target_stats$sign
  target_stats <- target_stats[order(target_stats$stat, decreasing = T),]
  target_stats <- unique(target_stats)
  target_stats$ID <- factor(target_stats$ID, levels = target_stats$ID)

  plot(ggplot(target_stats,aes(x = ID, y  = stat, fill = stat))+ geom_bar(stat = "identity"))
}

Hope it helps.

Kind regards, Cheyenne

dilipgosar commented 2 years ago

Dear Mr. Cheyenne,

Thank you for sending information regarding magicPlotMakerLight function. I tried the function you have send but it is still giving me another error.

plots <- magicPlotMakerLight(df = log2(count_df), targets = targets) Error in make_df_and_targets_great_again(df, targets) : could not find function "make_df_and_targets_great_again"

I think it is not able to to find make_df_and_targets_great_again function this time. I don't know how many other functions it might be missing. I like to know if you can fix all the functions required for the code to run.

Appreciate your help.

Sincerely,

Dilip Gosar

gabora commented 2 years ago

Dear Dilip, I am wondering why this error appears for you?

The definition of this function is in support_functions.R, which is loaded In line 48 of the 01_normalisation.Rmd: https://github.com/saezlab/transcriptutorial/blob/c03cf2c2f52264db290346d1f9c33c5a242b5360/scripts/01_normalisation.Rmd#L48

So there should be no problem using it. are you running all lines of code? best, Attila