Last updated: 2022-12-14

Checks: 6 1

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.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

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/starve.csv data/starve.csv
/data/morgante_lab/nklimko/rep/dgrp-starve/data/INPUT.txt data/INPUT.txt
/data/morgante_lab/nklimko/rep/dgrp-starve/data/CHANGE.txt data/CHANGE.txt
/data/morgante_lab/nklimko/rep/dgrp-starve/data/snpList.txt data/snpList.txt
/data/morgante_lab/nklimko/rep/dgrp-starve/data/geneHits.txt data/geneHits.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 4853114. 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:


Untracked files:
    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/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/goGroups.txt
    Untracked:  data/mMeans.txt
    Untracked:  data/mPart.txt
    Untracked:  data/mRegress.txt
    Untracked:  data/starve-f.txt
    Untracked:  data/starve-m.txt
    Untracked:  data/xp-f.txt
    Untracked:  data/xp-m.txt
    Untracked:  scoreAnalysisMulticomp.R
    Untracked:  temp.Rmd

Unstaged changes:
    Deleted:    analysis/database.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.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/scripts.Rmd) and HTML (docs/scripts.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html 88ee9ec nklimko 2022-11-29 Build site.
html 37278c9 nklimko 2022-11-22 Build site.
html f09779e nklimko 2022-11-22 Build site.
html f1d6437 nklimko 2022-11-15 Build site.
html 79e98ca nklimko 2022-11-15 Build site.
html d23d7f7 nklimko 2022-11-11 Build site.
Rmd 3a282f1 nklimko 2022-11-11 wflow_publish("analysis/*")

SR Data Prep

##### Libraries
library(dplyr)
library(tidyr)

### Function: create tibble from data path
antiNull <- function(csvPath){
  
  #Read in table
  allRaw <- tibble(read.csv(csvPath))
  
  #filter for non-null values
  starveRaw <- allRaw %>% select(line,starvation) %>% filter(!is.na(starvation))
  
  return(starveRaw)
}

#Female data
csvPathF <- "/data/morgante_lab/data/dgrp/phenotypes/eQTL_traits_females.csv"
starveF <- antiNull(csvPathF)

#Male data
csvPathM <- "/data/morgante_lab/data/dgrp/phenotypes/eQTL_traits_males.csv"
starveM <- antiNull(csvPathM)

#rename columns for combination
colnames(starveF) <- c("line", "f")
colnames(starveM) <- c("line", "m")

#Combine data
starve <- starveF %>% mutate(m = starveM$m)

#compute difference and average
starve <- starve %>% select(line, f, m) %>% mutate(dif = f - m, avg = (f+m)/2)

#Sort by difference, cosmetic
starve <- arrange(starve, starve$dif)

#Save, colnames are lin,f,m,dif,avg
write.csv(starve, "/data/morgante_lab/nklimko/rep/dgrp-starve/data/starve.csv")

SR Analysis

#Libraries and setup
library(dplyr)
library(data.table)
library(tidyr)
starve <- tibble(read.csv("/data/morgante_lab/nklimko/rep/dgrp-starve/data/starve.csv")) %>% select(-X)
x <- starve$f
y <- starve$m

#plot parameters
par(mfrow=c(1,2))

#Female Histogram
hist(x, 
     col="red",
     border="black",
     prob=TRUE,
     xlab = "Starvation Resistance",
     main = "Female Lines")

lines(density(x),
      lwd = 2,
      col = "black")

#Male Histogram
hist(y, 
     col="blue",
     border="black",
     prob=TRUE,
     xlab = "Starvation Resistance",
     main = "Male Lines")

lines(density(y),
      lwd = 2,
      col = "black")

#Summary stats
cbind(summary(x), summary(y))


# Comparative Boxplot
boxplot(x,
        y,
        col = c("red","blue"),
        names=c("Female", "Male"),
        main="Sex Comparison of Starvation Resistance",
        xlab="Starvation Resistance",
        ylab="Sex",
        horizontal = TRUE)

# Scatter Plot
plot(x,
     y,
     col="black",
     xlab="Female Starvation Resistance",
     ylab="Male Starvation Resistance",
     abline(reg=lm(y~x), 
            col="purple"))
text(x = 85, y = 25,
     "y = 14.2347x + 0.5192",
     cex = 0.75)
text(x = 85, y = 22.5,
     "R=0.4693, p-value < 2.2e-16",
     cex = 0.75)

#Trendline parameter determination
summary(lm(y~x))

# QQ Plots
#plot parameters
par(mfrow=c(1,2))

qqnorm(x, main="Female Distribution")
qqline(x)
qqnorm(y, main="Male Distribution")
qqline(y)

#Shapiro-Wilk Normality Tests
Female_Starvation <- x
Male_Starvation <- y

shapiro.test(Female_Starvation)
shapiro.test(Male_Starvation)


### Group selection

#plot parameters
par(mfrow=c(1,2))

#Difference
hist(starve$dif, 
     col="purple",
     border="black",
     xlab = "Change in Starvation Resistance",
     main = "Difference of Female and Male Lines")

#Average
hist(starve$avg, 
     col="pink",
     border="black",
     xlab = "Average Starvation Resistance",
     main = "Avg of Female and Male Lines")

### Scatter Plot
plot(starve$avg,
     starve$dif,
     col="black",
     xlab="Line Average",
     ylab="Intersex Difference",
     abline(reg=lm(starve$dif~starve$avg), 
            col="purple"))
text(x = 72, y = -12.5,
     "y = 0.3258 - 2.3984",
     cex = 0.75)
text(x = 72, y = -15,
     "R=0.1293, p-value < 1.37e-7",
     cex = 0.75)

#Trendline parameter determination
summary(lm(starve$dif~starve$avg))

Ingroup Prep

##### Libraries
library(dplyr)
library(tidyr)
library(data.table)

#Read in data
starve <- tibble(read.csv("data/starve.csv")) %>% select(-X)

#Manual inspection of data to create cutoffs for ingroups
print(arrange(starve, starve$dif), n=205)
print(arrange(starve, starve$avg), n=205)

# Lines with male SR high than female SR
difMinus <- starve %>% filter(dif < 0) %>% arrange(line) %>% select(line)
difMinus <- as.data.table(difMinus)
fwrite(difMinus, "../data/difMinus.txt")

# Lines with largest gap from male SR to female SR
difPlus <- starve %>% filter(dif >= 30) %>% arrange(line) %>% select(line)
difPlus <- as.data.table(difPlus)
fwrite(difPlus, "../data/difPlus.txt")

# Lowest average SR between males and females
avgMinus <- starve %>% filter(avg < 40) %>% arrange(line) %>% select(line)
avgMinus <- as.data.table(avgMinus)
fwrite(avgMinus, "../data/avgMinus.txt")

# Highest average SR between males and females
avgPlus <- starve %>% filter(dif >= 30) %>% arrange(line) %>% select(line)
avgPlus <- as.data.table(avgPlus)
fwrite(avgPlus, "../data/avgPlus.txt")

SNP Gathering

### Libraries
library("data.table")
library("dplyr")

##change per job
dataPath <- "/data/morgante_lab/data/dgrp/genotypes/dgrp2_tgeno_filtered_meanimputed.txt"
targetPath <- "/data/morgante_lab/nklimko/rep/dgrp-starve/data/INPUT.txt"
finalPath <- "/data/morgante_lab/nklimko/rep/dgrp-starve/data/CHANGE.txt"

#number of results to save
finalCount <- 200

#files read in
data <- fread(dataPath) 
inGroup <- fread(targetPath)

#modification of inGroup to vector type, clunky
inGroup <- inGroup[,line]

#IDs saved and removed
var_id <- data[,var_id]
data <- data[, var_id:=NULL]

#data partitioned by column
inData <- data[,colnames(data) %in% inGroup, with=FALSE]
outData <- data[,!(colnames(data) %in% inGroup), with=FALSE]

#means calculated for every row
inMean <- rowMeans(inData)
outMean <- rowMeans(outData)
  
#table constructed of marker IDs and group means
phaseA <- data.table(var_id, inMean, outMean)

#calculates difference of group means
trueData <-  phaseA[, result:=inMean - outMean]
#trueData <-  phaseA[, result:=inMean / outMean]

#orders data by absolute value of difference, largest first
trueSort <- trueData[order(-abs(result))]

#index controls number of top results to save
finalSet<- trueSort[1:finalCount]

#writes top (finalCount) to designated path
fwrite(finalSet, finalPath)

SNP to Gene

### Libraries
library(data.table)
library(dplyr)
library(stringr)

#input paths
genePath <- "/data/databases/flybase/fb-r5.57/fb-r5.57.clean.gene.bound"
snpPath <- "/data/morgante_lab/nklimko/rep/dgrp-starve/data/snpList.txt"

#read data in
genBank <- fread(genePath, col.names = c("leg","start", "stop", "strand","gene"))
snpList <- fread(snpPath)

#split SNP tag to search gene data correctly
snpList[, arm := tstrsplit(var_id, split="_",fixed = TRUE)[1]]
snpList[, pos := tstrsplit(var_id, split="_",fixed = TRUE)[2]]
snpList[, pos := as.numeric(pos)]

#set start and stop to numeric type
genBank[, ':='(start=as.numeric(start), stop=as.numeric(stop))]

#extract gene where position contained and arm matches
geneHits <- genBank[snpList, on = .(start <= pos, stop >= pos,leg==arm), .(ori, geneFind = gene)][!is.na(geneFind)]

#save file
fwrite(geneHits, "/data/morgante_lab/nklimko/rep/dgrp-starve/data/geneHits.txt")

Gene to GO

### Libraries
library(data.table)
library(dplyr)

#input paths
goPath <- "/data/databases/flybase/fb-r5.57/gene_go.table"
genePath <- "/data/morgante_lab/nklimko/rep/dgrp-starve/data/geneHits.txt"

#read data in
genList <- fread(genePath, col.names = c("ori", "gene"))
goBank <- fread(goPath, col.names = c("gene", "mf", "bp", "cc"))

#match go terms to gene
genList <- goBank[genList, on = .(gene)]

#save
fwrite(genList, "./goGroups.txt")

#No origin
table(genList[,mf])
table(genList[,cc])
table(genList[,bp])

##This one
table(genList[,gene, by=ori])
table(genList[,mf, by=ori])
table(genList[,cc, by=ori])
table(genList[,bp, by=ori])

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] workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3     highr_0.9        bslib_0.3.1      jquerylib_0.1.4 
 [5] compiler_4.0.3   pillar_1.7.0     later_1.3.0      git2r_0.30.1    
 [9] tools_4.0.3      getPass_0.2-2    digest_0.6.29    jsonlite_1.8.0  
[13] evaluate_0.15    tibble_3.1.6     lifecycle_1.0.1  pkgconfig_2.0.3 
[17] rlang_1.0.4      cli_3.3.0        rstudioapi_0.13  yaml_2.3.5      
[21] xfun_0.30        fastmap_1.1.0    httr_1.4.2       stringr_1.4.0   
[25] knitr_1.38       sass_0.4.1       fs_1.5.2         vctrs_0.4.1     
[29] rprojroot_2.0.3  glue_1.6.2       R6_2.5.1         processx_3.5.3  
[33] fansi_1.0.3      rmarkdown_2.16   callr_3.7.0      magrittr_2.0.3  
[37] whisker_0.4      ps_1.6.0         promises_1.2.0.1 htmltools_0.5.2 
[41] ellipsis_0.3.2   httpuv_1.6.5     utf8_1.2.2       stringi_1.7.6   
[45] crayon_1.5.1