Last updated: 2023-01-22

Checks: 5 2

Knit directory: dgrp-starve/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20221101) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
/data/morgante_lab/nklimko/rep/dgrp-starve/data/fRegress_adj.txt data/fRegress_adj.txt
/data/morgante_lab/nklimko/rep/dgrp-starve/data/f_adj.txt data/f_adj.txt
/data/morgante_lab/nklimko/rep/dgrp-starve/data/mRegress_adj.txt data/mRegress_adj.txt
/data/morgante_lab/nklimko/rep/dgrp-starve/data/m_adj.txt data/m_adj.txt

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version aee9a18. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .RData

Untracked files:
    Untracked:  analysis/gremlo.R
    Untracked:  analysis/linearReg.Rmd
    Untracked:  analysis/predict.Rmd
    Untracked:  analysis/rewrite.Rmd
    Untracked:  code/aaaTest
    Untracked:  code/analysisSR.R
    Untracked:  code/geneGO.R
    Untracked:  code/multiPrep.R
    Untracked:  code/regress.81916.err
    Untracked:  code/regress.81916.out
    Untracked:  code/regress.81918.err
    Untracked:  code/regress.81918.out
    Untracked:  code/regress.R
    Untracked:  code/regress.sbatch
    Untracked:  code/regressF.81919.err
    Untracked:  code/regressF.81919.out
    Untracked:  code/regressF.R
    Untracked:  code/regressF.sbatch
    Untracked:  code/regress_f_adj.109973.err
    Untracked:  code/regress_f_adj.109973.out
    Untracked:  code/regress_f_adj.109974.err
    Untracked:  code/regress_f_adj.109974.out
    Untracked:  code/regress_f_adj.R
    Untracked:  code/regress_f_adj.sbatch
    Untracked:  code/regress_m_adj.109971.err
    Untracked:  code/regress_m_adj.109971.out
    Untracked:  code/regress_m_adj.109972.err
    Untracked:  code/regress_m_adj.109972.out
    Untracked:  code/regress_m_adj.R
    Untracked:  code/regress_m_adj.sbatch
    Untracked:  code/snpGene.77509.err
    Untracked:  code/snpGene.77509.out
    Untracked:  code/snpGene.77515.err
    Untracked:  code/snpGene.77515.out
    Untracked:  code/snpGene.sbatch
    Untracked:  data/eQTL_traits_females.csv
    Untracked:  data/eQTL_traits_males.csv
    Untracked:  data/fMeans.txt
    Untracked:  data/fRegress.txt
    Untracked:  data/fRegress_adj.txt
    Untracked:  data/f_adj.txt
    Untracked:  data/goGroups.txt
    Untracked:  data/mMeans.txt
    Untracked:  data/mPart.txt
    Untracked:  data/mRegress.txt
    Untracked:  data/mRegress_adj.txt
    Untracked:  data/m_adj.txt
    Untracked:  data/multiReg.rData
    Untracked:  data/starve-f.txt
    Untracked:  data/starve-m.txt
    Untracked:  data/xp-f.txt
    Untracked:  data/xp-m.txt
    Untracked:  data/y_save.txt
    Untracked:  figure/
    Untracked:  lmm.R
    Untracked:  qqdum.R
    Untracked:  scoreAnalysisMulticomp.R
    Untracked:  temp.Rmd

Unstaged changes:
    Deleted:    analysis/database.Rmd
    Modified:   analysis/index.Rmd
    Modified:   analysis/linReg.Rmd
    Modified:   analysis/multiReg.Rmd
    Modified:   analysis/recap.Rmd
    Deleted:    analysis/scripts.Rmd
    Modified:   code/baseScript-lineComp.R
    Modified:   code/fourLinePrep.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


Prep

#load mgl data and custom function
load("/data/morgante_lab/data/dgrp/misc/adjustData.RData")

#read in expression data
f_data <- fread("data/fMeans.txt")

#grab starvation
y <- f_data[,starvation]

#store starvation with id
dat <- data.frame(id=f_data[,line], y=y)

#adjust data with given function
f_adjPheno <- adjustPheno(dat, "starvation")
Type III ANOVA table for covariates: starvation
                 Df Sum of Sq   RSS    AIC F value  Pr(>F)  
<none>                        28767 1009.8                  
factor(wolba)     1    483.10 29250 1011.1  3.1236 0.07881 .
factor(In_2L_t)   2     60.22 28827 1006.2  0.1947 0.82325  
factor(In_2R_NS)  2    300.22 29067 1007.8  0.9706 0.38078  
factor(In_3R_P)   2     85.92 28853 1006.4  0.2778 0.75777  
factor(In_3R_K)   2    959.43 29726 1012.3  3.1017 0.04731 *
factor(In_3R_Mo)  2    416.65 29184 1008.6  1.3470 0.26255  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Estimated effects
                    Estimate Std. Error    t value     Pr(>|t|)
(Intercept)       58.7465186   1.553929 37.8051442 3.103130e-89
factor(wolba)y     3.2450739   1.836101  1.7673724 7.880567e-02
factor(In_2L_t)1  -0.8506378   3.101713 -0.2742477 7.841986e-01
factor(In_2L_t)2  -1.8583916   3.151661 -0.5896547 5.561378e-01
factor(In_2R_NS)1  0.8630221   4.621570  0.1867379 8.520697e-01
factor(In_2R_NS)2  6.7057598   4.825270  1.3897169 1.662760e-01
factor(In_3R_P)1  -1.8513843   5.206148 -0.3556150 7.225319e-01
factor(In_3R_P)2   4.0596759   6.331413  0.6411959 5.221847e-01
factor(In_3R_K)1   7.4870256   4.084124  1.8332024 6.837092e-02
factor(In_3R_K)2  15.5762633   8.948152  1.7407240 8.338564e-02
factor(In_3R_Mo)1 -5.4712766   4.279569 -1.2784644 2.026787e-01
factor(In_3R_Mo)2 -3.6074434   3.224295 -1.1188318 2.646547e-01
#overwrite starvation column
f_adj <- f_data[,starvation:=f_adjPheno]

#save to txt file
fwrite(f_adj, "data/f_adj.txt")
#load mgl data and custom function
load("/data/morgante_lab/data/dgrp/misc/adjustData.RData")

#read in expression data
m_data <- fread("data/mMeans.txt")

#grab starvation
y <- m_data[,starvation]

#store starvation with id
dat <- data.frame(id=m_data[,line], y=y)

#adjust data with given function
m_adjPheno <- adjustPheno(dat, "starvation")
Type III ANOVA table for covariates: starvation
                 Df Sum of Sq   RSS    AIC F value Pr(>F)
<none>                        15975 893.32               
factor(wolba)     1     3.041 15978 891.35  0.0354 0.8509
factor(In_2L_t)   2   299.141 16274 892.99  1.7415 0.1781
factor(In_2R_NS)  2   243.044 16218 892.31  1.4149 0.2455
factor(In_3R_P)   2   230.105 16205 892.15  1.3396 0.2645
factor(In_3R_K)   2   288.050 16263 892.85  1.6770 0.1898
factor(In_3R_Mo)  2   207.445 16182 891.87  1.2077 0.3012


Estimated effects
                    Estimate Std. Error    t value     Pr(>|t|)
(Intercept)       45.6614374   1.157976 39.4321227 2.909220e-92
factor(wolba)y    -0.2574606   1.368248 -0.1881681 8.509500e-01
factor(In_2L_t)1   1.7198329   2.311372  0.7440744 4.577704e-01
factor(In_2L_t)2  -3.7780449   2.348592 -1.6086422 1.093906e-01
factor(In_2R_NS)1 -1.0811449   3.443957 -0.3139252 7.539297e-01
factor(In_2R_NS)2  5.8594026   3.595753  1.6295343 1.048923e-01
factor(In_3R_P)1  -2.0731924   3.879580 -0.5343858 5.937128e-01
factor(In_3R_P)2   7.1994131   4.718118  1.5259077 1.287315e-01
factor(In_3R_K)1   5.3513957   3.043456  1.7583284 8.033635e-02
factor(In_3R_K)2   3.7673764   6.668091  0.5649857 5.727643e-01
factor(In_3R_Mo)1 -3.0569154   3.189101 -0.9585510 3.390293e-01
factor(In_3R_Mo)2 -3.0977753   2.402719 -1.2892793 1.989020e-01
#overwrite starvation column
m_adj <- m_data[,starvation:=m_adjPheno]

#save to txt file
fwrite(m_adj, "data/m_adj.txt")

Correlations

In order to save time, I used secretariat’s computational resources to perform the correlation calculations in parallel. The following two sections of code were submission scripts performed in secretariat.

library(dplyr)
library(data.table)
library(doParallel)

registerDoParallel(cores = 12)

# file path for final table
filePath <- "/data/morgante_lab/nklimko/rep/dgrp-starve/data/fRegress_adj.txt"

# gene expression data from earlier bound to line and starvation
f_adj <- fread("/data/morgante_lab/nklimko/rep/dgrp-starve/data/f_adj.txt")

start <- 3
end <- 11340
#f 11340
#m 13577

# foreach creates a list with index indicating position in loop
# function grabs the p-value from correlation of starvation to expression of trait
pvalList <- foreach(i=start:end) %dopar% {  
  temp <- summary(lm(f_adj[,c(2,i), with=FALSE], na.action=na.omit))[[4]][8]  
}

# converts list to vector
part <- unlist(pvalList, use.names = FALSE)

# binds p-vals to column index 
id <- start:end
part <- data.table(id,pvalList)

# write table to file
fwrite(part, filePath)

Both of these are available by clicking the drop down buttons on the right ->

library(dplyr)
library(data.table)
library(doParallel)

registerDoParallel(cores = 12)

# file path for final table
filePath <- "/data/morgante_lab/nklimko/rep/dgrp-starve/data/mRegress_adj.txt"

# gene expression data from earlier bound to line and starvation
m_adj <- fread("/data/morgante_lab/nklimko/rep/dgrp-starve/data/m_adj.txt")

start <- 3
end <- 13577
#f 11340
#m 13577

# foreach creates a list with index indicating position in loop
# function grabs the p-value from correlation of starvation to expression of trait
pvalList <- foreach(i=start:end) %dopar% {  
  temp <- summary(lm(m_adj[,c(2,i), with=FALSE], na.action=na.omit))[[4]][8]  
}

# converts list to vector
part <- unlist(pvalList, use.names = FALSE)

# binds p-vals to column index 
id <- start:end
part <- data.table(id,pvalList)

# write table to file
fwrite(part, filePath)

QQ and Manthattan Data Prep ->

# Female qq prep

#f 11340
#m 13577

gg <- vector(mode='list', length=4)

#read in results from compute node
fReg <- fread("data/fRegress_adj.txt")

#number of data points
n <- dim(fReg)[1]

#Theoretical Quantiles
uniform <- 1:n/(n+1)

#sorted p values
empirical <- sort(fReg[,pvalList])

#-log 10
logPlot <- -log10(fReg[,pvalList])

#table for qqplot
qqdata <- data.table(uniform, empirical, logPlot)

qqdataF <- qqdata

# ggplot of data to fpr, qqplot
if(FALSE){
gg[[1]] <- ggplot(qqdata, aes(x=uniform, y=empirical)) +
  geom_point(color="red") +  
  geom_segment(aes(x=0,y=0,xend=1,yend=1)) + 
  xlab("Theoretical Quantiles") +
  ylab("Sorted p-values") +
  ggtitle("Female Expression QQ Plot")
}

gg[[2]] <- ggplot(qqdata, aes(x=uniform, y=logPlot)) +
  geom_point(color="red") + 
  geom_hline(yintercept= -log10(0.05/n), color="magenta") +
  xlab("Theoretical Quantiles") +
  ylab("-log10 p-values") +
  ggtitle("Female Expression Manhattan Plot")



## Code for looking at specific genes
#fMeans <- fread("data/fMeans.txt")
#genes <- colnames(fMeans)
#genes <- genes[3:length(genes)]
#fReg <- fReg[, gene:=genes]
# Male qq prep

#read in results from compute node
mReg <- fread("data/mRegress_adj.txt")

#number of data points
n <- dim(mReg)[1]

#Theoretical Quantiles
uniform <- 1:n/(n+1)

#sorted p values
empirical <- sort(mReg[,pvalList])

#-log 10
logPlot <- -log10(mReg[,pvalList])

#table for qqplot
qqdata <- data.table(uniform, empirical, logPlot)

qqdataM <- qqdata


# ggplot of data to fpr, qqplot
if(FALSE){
gg[[3]] <- ggplot(qqdata, aes(x=uniform, y=empirical)) +
  geom_point(color="blue") +  
  geom_segment(aes(x=0,y=0,xend=1,yend=1), linewidth=1) + 
  xlab("Theoretical Quantiles") +
  ylab("Sorted p-values") +
  ggtitle("Male Expression QQ Plot")
}


gg[[4]] <- ggplot(qqdata, aes(x=uniform, y=logPlot)) +
  geom_point(color="blue") + 
  geom_hline(yintercept= -log10(0.05/n), color="cyan") +
  xlab("Theoretical Quantiles") +
  ylab("-log10 p-values") +
  ggtitle("Male Expression Manhattan Plot")

## Code for looking at specific genes
#mMeans <- fread("data/mMeans.txt")
#genes <- colnames(mMeans)
#genes <- genes[3:length(genes)]
#mReg <- mReg[, gene:=genes]

QQ Plots

par(mfrow=c(1,2))

qq(qqdataF[,empirical], main="Female Gene p-values")
qq(qqdataM[,empirical], main="Male Gene p-values")

Manhattan Plots

par(mfrow=c(1,2))

plot_grid(gg[[2]],gg[[4]], ncol=2)

Part of the reason both plots deviate from linearity because we did not account for genes that were correlated with each other.


sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /opt/ohpc/pub/Software/openblas_0.3.10/lib/libopenblas_haswellp-r0.3.10.dev.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] qqman_0.1.8       cowplot_1.1.1     ggplot2_3.3.5     data.table_1.14.2
[5] dplyr_1.0.8      

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.2 xfun_0.30        bslib_0.3.1      purrr_0.3.4     
 [5] colorspace_2.0-3 vctrs_0.4.1      generics_0.1.2   htmltools_0.5.2 
 [9] yaml_2.3.5       utf8_1.2.2       rlang_1.0.4      jquerylib_0.1.4 
[13] later_1.3.0      pillar_1.7.0     glue_1.6.2       withr_2.5.0     
[17] DBI_1.1.2        calibrate_1.7.7  lifecycle_1.0.1  stringr_1.4.0   
[21] munsell_0.5.0    gtable_0.3.0     workflowr_1.7.0  evaluate_0.15   
[25] labeling_0.4.2   knitr_1.38       fastmap_1.1.0    httpuv_1.6.5    
[29] fansi_1.0.3      highr_0.9        Rcpp_1.0.8.3     promises_1.2.0.1
[33] scales_1.2.0     jsonlite_1.8.0   farver_2.1.0     fs_1.5.2        
[37] digest_0.6.29    stringi_1.7.6    rprojroot_2.0.3  grid_4.0.3      
[41] cli_3.3.0        tools_4.0.3      magrittr_2.0.3   sass_0.4.1      
[45] tibble_3.1.6     crayon_1.5.1     pkgconfig_2.0.3  ellipsis_0.3.2  
[49] MASS_7.3-56      assertthat_0.2.1 rmarkdown_2.16   rstudioapi_0.13 
[53] R6_2.5.1         git2r_0.30.1     compiler_4.0.3