-
Notifications
You must be signed in to change notification settings - Fork 0
/
figX_plexDistanceCorrelation.Rmd
121 lines (81 loc) · 3.8 KB
/
figX_plexDistanceCorrelation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
title: "Plex Analysis"
author: "Sara Gosline"
date: "`r Sys.Date()`"
output: html_document
---
```{r setup, include=FALSE}
library(dplyr)
library(purrr)
library(devtools)
#library(MSnSet.utils)
if(!require(MSnSet.utils))
devtools::install_github('PNNL-Comp-Mass-Spec/MSnSet.utils')
library(ggplot2)
library(ggfortify)
library(cowplot)
library(leapR)
source('loadHumanPancData.R')
```
## Plex analysis
Each plex is labeled with a heavy isotope that is not 100% pure, as such an isotope with a similar molecular weight can be detected in a different plex. As such, we use the difference in molecular weight to see if this correlates with similarity between plexes.
```{r labels}
print(tidyr::pivot_wider(labels,names_from='OtherPlex',values_from='mwDist'))
```
## Correlation between samples
We can now do a pairwise correlation between samples to see if we observe any bias in correlation between samples that share plexes. We verify the labels of the plexes and then map them, along with the distnaces, to the correlation values
```{r map plex labels to correlatioon values}
plexLabels <- isletMeta%>%
tibble::rownames_to_column('Orig')%>%
dplyr::select(Orig,Plex,IsletStatus,IsletOrNot,Image='Islet Number')%>%
distinct()
print(plexLabels)
otherLabels <- plexLabels
names(otherLabels)<-paste0('Other',names(plexLabels))
norm.cor <- cor(crosstab,use='pairwise.complete.obs',method='spearman')%>%
as.data.frame(row.names=colnames(crosstab))%>%
tibble::rownames_to_column('Orig')%>%
tidyr::pivot_longer(2:(ncol(crosstab)+1),names_to='OtherOrig',values_to='corVal')%>%
left_join(plexLabels)%>%
left_join(otherLabels)%>%
left_join(labels)%>%
mutate(labelStatus=ifelse(mwDist==0,'Same',ifelse(mwDist==1,'OneAWay','Other')))%>%
mutate(ImageStatus=Image==OtherImage)%>%
mutate(Image=as.factor(Image))
library(ggplot2)
ggplot(norm.cor,aes(x=mwDist,y=corVal,col=mwDist))+
geom_jitter()+geom_boxplot()+ggtitle("Corrected pixel correlations")+facet_grid(Image~OtherImage)
ggplot(norm.cor,aes(x=mwDist,y=corVal,col=Image))+
geom_jitter()+geom_boxplot()+ggtitle("Corrected pixel correlations")+facet_grid(Plex~OtherPlex)
ggplot(subset(norm.cor,ImageStatus),aes(x=mwDist,y=corVal,col=Image,))+
geom_jitter()+geom_boxplot()+ggtitle("Corrected pixel correlations")
orig.cor <- cor(crosstab2,use='pairwise.complete.obs',method='spearman')%>%
as.data.frame(row.names=colnames(crosstab))%>%
tibble::rownames_to_column('Orig')%>%
tidyr::pivot_longer(2:(ncol(crosstab)+1),names_to='OtherOrig',values_to='corVal')%>%
left_join(plexLabels)%>%
left_join(otherLabels)%>%
left_join(labels)%>%
mutate(labelStatus=ifelse(mwDist==0,'Same',ifelse(mwDist==1,'OneAWay','Other')))%>%
mutate(ImageStatus=Image==OtherImage)%>%
mutate(Image=as.factor(Image))
ggplot(subset(orig.cor,ImageStatus),aes(x=mwDist,y=corVal,col=Image))+
geom_jitter()+
geom_boxplot()+ggtitle('Uncorrected pixel correlations')
```
It doesn't look very different? We can try to calculate means of all the data.
```{r correlation values per image}
norm.cor%>%subset(ImageStatus)%>%
group_by(Image,mwDist)%>%summarize(meanCor=mean(corVal))%>%
ggplot(aes(x=mwDist,y=meanCor,col=Image))+geom_jitter()
norm.cor%>%subset(ImageStatus)%>%
group_by(Image,labelStatus)%>%summarize(meanCor=mean(corVal))%>%
ggplot(aes(x=labelStatus,y=meanCor,col=Image))+geom_jitter()
orig.cor%>%subset(ImageStatus)%>%
group_by(Image,mwDist)%>%summarize(meanCor=mean(corVal))%>%
ggplot(aes(x=mwDist,y=meanCor,col=Image))+geom_jitter()
orig.cor%>%subset(ImageStatus)%>%
group_by(Image,labelStatus)%>%summarize(meanCor=mean(corVal))%>%
ggplot(aes(x=labelStatus,y=meanCor,col=Image))+geom_jitter()
```
So this isnt' really behaving as expected? Or is it?