Last updated: 2019-10-09

Checks: 7 0

Knit directory: Comparative_APA/analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.4.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(20190902) 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.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

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:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    code/chimp_log/
    Ignored:    code/human_log/
    Ignored:    data/metadata_HCpanel.txt.sb-a3d92a2d-b9cYoF/
    Ignored:    data/metadata_HCpanel.txt.sb-f4823d1e-qihGek/

Untracked files:
    Untracked:  ._.DS_Store
    Untracked:  Chimp/
    Untracked:  Human/
    Untracked:  code/._Config_chimp.yaml
    Untracked:  code/._Config_human.yaml
    Untracked:  code/._LiftOrthoPAS2chimp.sh
    Untracked:  code/._Snakefile
    Untracked:  code/._SnakefilePAS
    Untracked:  code/._SnakefilePASfilt
    Untracked:  code/._bed215upbed.py
    Untracked:  code/._bed2SAF_gen.py
    Untracked:  code/._buildStarIndex.sh
    Untracked:  code/._cleanbed2saf.py
    Untracked:  code/._cluster.json
    Untracked:  code/._extraSnakefiltpas
    Untracked:  code/._filter5percPAS.py
    Untracked:  code/._filterPASforMP.py
    Untracked:  code/._filterPostLift.py
    Untracked:  code/._fixUTRexonanno.py
    Untracked:  code/._formathg38Anno.py
    Untracked:  code/._formatpantro6Anno.py
    Untracked:  code/._intersectLiftedPAS.sh
    Untracked:  code/._liftPAS19to38.sh
    Untracked:  code/._makeSamplyGroupsHuman_TvN.py
    Untracked:  code/._maphg19.sh
    Untracked:  code/._maphg19_subjunc.sh
    Untracked:  code/._overlapapaQTLPAS.sh
    Untracked:  code/._prepareCleanLiftedFC_5perc4LC.py
    Untracked:  code/._preparePAS4lift.py
    Untracked:  code/._primaryLift.sh
    Untracked:  code/._recLiftchim2human.sh
    Untracked:  code/._revLiftPAShg38to19.sh
    Untracked:  code/._reverseLift.sh
    Untracked:  code/._runChimpDiffIso.sh
    Untracked:  code/._runHumanDiffIso.sh
    Untracked:  code/._runNuclearDifffIso.sh
    Untracked:  code/._snakemake.batch
    Untracked:  code/._snakemakePAS.batch
    Untracked:  code/._snakemakePASchimp.batch
    Untracked:  code/._snakemakePAShuman.batch
    Untracked:  code/._snakemake_chimp.batch
    Untracked:  code/._snakemake_human.batch
    Untracked:  code/._snakemakefiltPAS.batch
    Untracked:  code/._snakemakefiltPAS_chimp
    Untracked:  code/._snakemakefiltPAS_chimp.sh
    Untracked:  code/._snakemakefiltPAS_human.sh
    Untracked:  code/._submit-snakemake-chimp.sh
    Untracked:  code/._submit-snakemake-human.sh
    Untracked:  code/._submit-snakemakePAS-chimp.sh
    Untracked:  code/._submit-snakemakePAS-human.sh
    Untracked:  code/._submit-snakemakefiltPAS-chimp.sh
    Untracked:  code/._submit-snakemakefiltPAS-human.sh
    Untracked:  code/._subset_diffisopheno_Nuclear_HvC.py
    Untracked:  code/.snakemake/
    Untracked:  code/Config_chimp.yaml
    Untracked:  code/Config_human.yaml
    Untracked:  code/LiftOrthoPAS2chimp.sh
    Untracked:  code/LiftorthoPAS.err
    Untracked:  code/LiftorthoPASt.out
    Untracked:  code/Log.out
    Untracked:  code/Rev_liftoverPAShg19to38.err
    Untracked:  code/Rev_liftoverPAShg19to38.out
    Untracked:  code/SAF215upbed_gen.py
    Untracked:  code/Snakefile
    Untracked:  code/SnakefilePAS
    Untracked:  code/SnakefilePASfilt
    Untracked:  code/Upstream10Bases_general.py
    Untracked:  code/apaQTLsnake.err
    Untracked:  code/apaQTLsnake.out
    Untracked:  code/apaQTLsnakePAS.err
    Untracked:  code/apaQTLsnakePAS.out
    Untracked:  code/apaQTLsnakePAShuman.err
    Untracked:  code/bed215upbed.py
    Untracked:  code/bed2SAF_gen.py
    Untracked:  code/bed2saf.py
    Untracked:  code/bg_to_cov.py
    Untracked:  code/buildStarIndex.sh
    Untracked:  code/callPeaksYL.py
    Untracked:  code/chooseAnno2Bed.py
    Untracked:  code/chooseAnno2SAF.py
    Untracked:  code/cleanbed2saf.py
    Untracked:  code/cluster.json
    Untracked:  code/clusterPAS.json
    Untracked:  code/clusterfiltPAS.json
    Untracked:  code/convertNumeric.py
    Untracked:  code/extraSnakefiltpas
    Untracked:  code/filter5perc.R
    Untracked:  code/filter5percPAS.py
    Untracked:  code/filter5percPheno.py
    Untracked:  code/filterBamforMP.pysam2_gen.py
    Untracked:  code/filterMissprimingInNuc10_gen.py
    Untracked:  code/filterPASforMP.py
    Untracked:  code/filterPostLift.py
    Untracked:  code/filterSAFforMP_gen.py
    Untracked:  code/filterSortBedbyCleanedBed_gen.R
    Untracked:  code/filterpeaks.py
    Untracked:  code/fixFChead.py
    Untracked:  code/fixFChead_bothfrac.py
    Untracked:  code/fixUTRexonanno.py
    Untracked:  code/formathg38Anno.py
    Untracked:  code/generateStarIndex.err
    Untracked:  code/generateStarIndex.out
    Untracked:  code/intersectAnno.err
    Untracked:  code/intersectAnno.out
    Untracked:  code/intersectLiftedPAS.sh
    Untracked:  code/liftPAS19to38.sh
    Untracked:  code/liftoverPAShg19to38.err
    Untracked:  code/liftoverPAShg19to38.out
    Untracked:  code/log/
    Untracked:  code/make5percPeakbed.py
    Untracked:  code/makeFileID.py
    Untracked:  code/makePheno.py
    Untracked:  code/makeSamplyGroupsChimp_TvN.py
    Untracked:  code/makeSamplyGroupsHuman_TvN.py
    Untracked:  code/maphg19.err
    Untracked:  code/maphg19.out
    Untracked:  code/maphg19.sh
    Untracked:  code/maphg19_sub.err
    Untracked:  code/maphg19_sub.out
    Untracked:  code/maphg19_subjunc.sh
    Untracked:  code/namePeaks.py
    Untracked:  code/overlapPAS.err
    Untracked:  code/overlapPAS.out
    Untracked:  code/overlapapaQTLPAS.sh
    Untracked:  code/peak2PAS.py
    Untracked:  code/pheno2countonly.R
    Untracked:  code/prepareCleanLiftedFC_5perc4LC.py
    Untracked:  code/preparePAS4lift.py
    Untracked:  code/prepare_phenotype_table.py
    Untracked:  code/primaryLift.err
    Untracked:  code/primaryLift.out
    Untracked:  code/primaryLift.sh
    Untracked:  code/quantLiftedPAS.err
    Untracked:  code/quantLiftedPAS.out
    Untracked:  code/quantLiftedPAS.sh
    Untracked:  code/recChimpback2Human.err
    Untracked:  code/recChimpback2Human.out
    Untracked:  code/recLiftchim2human.sh
    Untracked:  code/revLift.err
    Untracked:  code/revLift.out
    Untracked:  code/revLiftPAShg38to19.sh
    Untracked:  code/reverseLift.sh
    Untracked:  code/runChimpDiffIso.sh
    Untracked:  code/runHumanDiffIso.sh
    Untracked:  code/runNuclearDifffIso.sh
    Untracked:  code/run_Chimpleafcutter_ds.err
    Untracked:  code/run_Chimpleafcutter_ds.out
    Untracked:  code/run_Humanleafcutter_ds.err
    Untracked:  code/run_Humanleafcutter_ds.out
    Untracked:  code/run_Nuclearleafcutter_ds.err
    Untracked:  code/run_Nuclearleafcutter_ds.out
    Untracked:  code/slurm-62824013.out
    Untracked:  code/slurm-62825841.out
    Untracked:  code/slurm-62826116.out
    Untracked:  code/snakePASChimp.err
    Untracked:  code/snakePASChimp.out
    Untracked:  code/snakePAShuman.out
    Untracked:  code/snakemake.batch
    Untracked:  code/snakemakePAS.batch
    Untracked:  code/snakemakePASFiltChimp.err
    Untracked:  code/snakemakePASFiltChimp.out
    Untracked:  code/snakemakePASFiltHuman.err
    Untracked:  code/snakemakePASFiltHuman.out
    Untracked:  code/snakemakePASchimp.batch
    Untracked:  code/snakemakePAShuman.batch
    Untracked:  code/snakemake_chimp.batch
    Untracked:  code/snakemake_human.batch
    Untracked:  code/snakemakefiltPAS.batch
    Untracked:  code/snakemakefiltPAS_chimp.sh
    Untracked:  code/snakemakefiltPAS_human.sh
    Untracked:  code/submit-snakemake-chimp.sh
    Untracked:  code/submit-snakemake-human.sh
    Untracked:  code/submit-snakemakePAS-chimp.sh
    Untracked:  code/submit-snakemakePAS-human.sh
    Untracked:  code/submit-snakemakefiltPAS-chimp.sh
    Untracked:  code/submit-snakemakefiltPAS-human.sh
    Untracked:  code/subset_diffisopheno.py
    Untracked:  code/subset_diffisopheno_Chimp_tvN.py
    Untracked:  code/subset_diffisopheno_Huma_tvN.py
    Untracked:  code/subset_diffisopheno_Nuclear_HvC.py
    Untracked:  data/._metadata_HCpanel.txt
    Untracked:  data/._metadata_HCpanel.txt.sb-a3d92a2d-b9cYoF
    Untracked:  data/._metadata_HCpanel.txt.sb-f4823d1e-qihGek
    Untracked:  data/._metadata_HCpanel.xlsx
    Untracked:  data/CompapaQTLpas/
    Untracked:  data/DiffIso_Nuclear/
    Untracked:  data/NuclearHvC/
    Untracked:  data/Peaks_5perc/
    Untracked:  data/Pheno_5perc/
    Untracked:  data/chainFiles/
    Untracked:  data/cleanPeaks_anno/
    Untracked:  data/cleanPeaks_byspecies/
    Untracked:  data/cleanPeaks_lifted/
    Untracked:  data/liftover_files/
    Untracked:  data/metadata_HCpanel.txt
    Untracked:  data/metadata_HCpanel.xlsx
    Untracked:  data/primaryLift/
    Untracked:  data/reverseLift/
    Untracked:  docs/figure/Nuclear_HvC.Rmd/

Unstaged changes:
    Modified:   analysis/Human_TvN.Rmd
    Modified:   analysis/annotatePAS.Rmd
    Modified:   analysis/comp2apaQTLPAS.Rmd

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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
Rmd 14a3f66 brimittleman 2019-10-09 add pca and human v chimp in nuc analysis

I want to normalize the phenotypes with the leafcutter scripts. This can be used to perform a PCA and assess the data quality. I will include, total nuclear human and chimp.

library(tidyverse)
── Attaching packages ───────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 3.1.1       ✔ purrr   0.3.2  
✔ tibble  2.1.1       ✔ dplyr   0.8.0.1
✔ tidyr   0.8.3       ✔ stringr 1.3.1  
✔ readr   1.3.1       ✔ forcats 0.3.0  
── Conflicts ──────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(reshape2)

Attaching package: 'reshape2'
The following object is masked from 'package:tidyr':

    smiths

These are the inclusive phenotypes. I will need to subset of the 5% pas.
../Human/phenotype/ALLPAS_postLift_LocParsed_Human_Pheno.txt ../Chimp/phenotype/ALLPAS_postLift_LocParsed_Chimp_Pheno.txt

The 5% pas are in ../data/Peaks_5perc/Peaks_5perc_either_bothUsage_noUnchr.txt

I will make a python script that will do this. I

python filter5percPAS.py ../Human/phenotype/ALLPAS_postLift_LocParsed_Human_Pheno.txt  ../data/Pheno_5perc/ALLPAS_postLift_LocParsed_Human_Pheno_5perc.txt

python filter5percPAS.py ../Chimp/phenotype/ALLPAS_postLift_LocParsed_Chimp_Pheno.txt  ../data/Pheno_5perc/ALLPAS_postLift_LocParsed_Chimp_Pheno_5perc.txt

Join these to normalize the phenotypes together:

humanPheno=read.table("../data/Pheno_5perc/ALLPAS_postLift_LocParsed_Human_Pheno_5perc.txt",stringsAsFactors = F, header = T)
chimpPheno=read.table("../data/Pheno_5perc/ALLPAS_postLift_LocParsed_Chimp_Pheno_5perc.txt",stringsAsFactors = F, header = T)


allPheno=humanPheno %>% full_join(chimpPheno,by="chrom")


write.table(allPheno, "../data/Pheno_5perc/ALLPAS_postLift_LocParsed_bothSpecies_pheno_5perc.txt", col.names = T, row.names = F, quote = F)
gzip ../data/Pheno_5perc/ALLPAS_postLift_LocParsed_bothSpecies_pheno_5perc.txt

#conda deactivate 
conda deactivate 
conda deactivate 
#python 2
source ~/activate_anaconda_python2.sh 
#go to directory ../data/Pheno_5perc/
python ../../code/prepare_phenotype_table.py ALLPAS_postLift_LocParsed_bothSpecies_pheno_5perc.txt.gz
cat ALLPAS_postLift_LocParsed_bothSpecies_pheno_5perc.txt.gz.phen_chr* > ALLPAS_postLift_LocParsed_bothSpecies_pheno_5perc.txt.gz.phen_AllChrom

Use these normalized phenotypes for the PCA

metaData=read.table("../data/metadata_HCpanel.txt", header = T, stringsAsFactors = F)
normPheno=read.table("../data/Pheno_5perc/ALLPAS_postLift_LocParsed_bothSpecies_pheno_5perc.txt.gz.phen_AllChrom", col.names = c('Chr', 'start',    'end',  'ID',   '18498_N',  '18498_T',  '18499_N',  '18499_T',  '18502_N',  '18502_T',  '18504_N',  '18504_T',  '18510_N',  '18510_T',  '18523_N',  '18523_T',  '18358_N',  '18358_T',  '3622_N',   '3622_T',   '3659_N',   '3659_T',   '4973_N',   '4973_T',   'pt30_N',   'pt30_T',   'pt91_N',   'pt91_T'))

normPheno_matrix=as.matrix(normPheno %>% select(-Chr, -start, -end, -ID))

Run PCA:

pca_Pheno=prcomp(normPheno_matrix, center=T,scale=T)
pca_df=as.data.frame(pca_Pheno$rotation) %>% rownames_to_column(var="ID")
eigs <- pca_Pheno$sdev^2
proportion = eigs/sum(eigs)

plot(proportion)

Plot color as species and shape as total v nuclear

top2PC=pca_df %>% select(ID, PC1, PC2) %>% inner_join(metaData, by="ID")


ggplot(top2PC,aes(x=PC1, y=PC2, col=Species, shape=Fraction)) + geom_point(size=3)

covariate_pc_pve_heatmap <- function(pc_df, covariate_df, title) {
  # Load in data
  #pcs <- pc_df
  pcs=pca_df
  
  #covs <- covariate_df
  covs= metaData_sm


  # Remove unimportant columns
  pcs <- as.matrix(pcs[,2:dim(pcs)[[2]]])
  covs <- data.frame(as.matrix(covs[,1:dim(covs)[[2]]]))

  # Initialize PVE heatmap
  pve_map <- matrix(0, dim(covs)[2], dim(pcs)[2])
  colnames(pve_map) <- colnames(pcs)
  rownames(pve_map) <- colnames(covs)

  # Loop through each PC, COV Pair and take correlation
  num_pcs <- dim(pcs)[2]
  num_covs <- dim(covs)[2]
  for (num_pc in 1:num_pcs) {
    for (num_cov in 1:num_covs) {
      pc_vec <- pcs[,num_pc]
      cov_vec <- covs[,num_cov]
      lin_model <- lm(pc_vec ~ cov_vec)
      pve_map[num_cov, num_pc] <- summary(lin_model)$adj.r.squared
      if (pve_map[num_cov, num_pc] <0){pve_map[num_cov, num_pc]=0}
    }
  }
  pve_map
  ord <- hclust( dist(scale(pve_map), method = "euclidean"), method = "ward.D" )$order

  melted_mat <- melt(pve_map)
  colnames(melted_mat) <- c("Covariate", "PC","PVE")

  #  Use factors to represent covariate and pc name
  melted_mat$Covariate <- factor(melted_mat$Covariate, levels = rownames(pve_map)[ord])
  melted_mat$PC <- factor(melted_mat$PC)
  if (dim(pcs)[2] == 10) {
    levels(melted_mat$PC) <- c(levels(melted_mat$PC)[1],levels(melted_mat$PC)[3:10],levels(melted_mat$PC)[2])
  }
  if (dim(pcs)[2] == 21) {
    levels(melted_mat$PC) <- c(levels(melted_mat$PC)[1],levels(melted_mat$PC)[12],levels(melted_mat$PC)[15:21],levels(melted_mat$PC)[2:11], levels(melted_mat$PC)[13:14])
  }

  #  PLOT!
  heatmap <- ggplot(data=melted_mat, aes(x=Covariate, y=PC)) + geom_tile(aes(fill=PVE)) + scale_fill_gradient2(midpoint=-.05, guide="colorbar")
  heatmap <- heatmap + theme(text = element_text(size=14), panel.background = element_blank(), axis.text.x = element_text(angle = 90, vjust=.5))
  heatmap <- heatmap + labs(y="latent factor", title=title)

  # Save File
  return(heatmap)
}
metaData_sm= metaData %>% select(-ID,-FQlines,-Reads,-Mapped_wMP,-Mapped_Clean,-PerMap,-PerMapClean)
covariate_pc_pve_heatmap(pca_df,metaData_sm, title="PCs")

I need to seperate this by nuclear and total before running this.


sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Scientific Linux 7.4 (Nitrogen)

Matrix products: default
BLAS/LAPACK: /software/openblas-0.2.19-el7-x86_64/lib/libopenblas_haswellp-r0.2.19.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] reshape2_1.4.3  forcats_0.3.0   stringr_1.3.1   dplyr_0.8.0.1  
 [5] purrr_0.3.2     readr_1.3.1     tidyr_0.8.3     tibble_2.1.1   
 [9] ggplot2_3.1.1   tidyverse_1.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2       cellranger_1.1.0 pillar_1.3.1     compiler_3.5.1  
 [5] git2r_0.25.2     plyr_1.8.4       workflowr_1.4.0  tools_3.5.1     
 [9] digest_0.6.18    lubridate_1.7.4  jsonlite_1.6     evaluate_0.12   
[13] nlme_3.1-137     gtable_0.2.0     lattice_0.20-38  pkgconfig_2.0.2 
[17] rlang_0.4.0      cli_1.1.0        rstudioapi_0.10  yaml_2.2.0      
[21] haven_1.1.2      withr_2.1.2      xml2_1.2.0       httr_1.3.1      
[25] knitr_1.20       hms_0.4.2        generics_0.0.2   fs_1.3.1        
[29] rprojroot_1.3-2  grid_3.5.1       tidyselect_0.2.5 glue_1.3.0      
[33] R6_2.3.0         readxl_1.1.0     rmarkdown_1.10   modelr_0.1.2    
[37] magrittr_1.5     whisker_0.3-2    backports_1.1.2  scales_1.0.0    
[41] htmltools_0.3.6  rvest_0.3.2      assertthat_0.2.0 colorspace_1.3-2
[45] labeling_0.3     stringi_1.2.4    lazyeval_0.2.1   munsell_0.5.0   
[49] broom_0.5.1      crayon_1.3.4