---
title: "SignaltoMolecules"
date: 11-09-23
author: Julia Shangguan
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

library(readr)
library(stringr)
library(dplyr)
library(ggplot2)
library(ggpmisc)
library(patchwork)
library(plotly)
library(tidyr)
library(scales)
library(usefr)

```


```{r}

## Signal values integrated from protein gel lanes
# Signal  was integrated for full-length Myo10 (at ~250 kDa) and Myo10 aggregated in the wells.

# Cell lysates
rep1 = as.integer(645.506 + 147.314)

rep2 = 600.799

rep3 = as.integer(1596.335 + 922.092)

rep1_live = 177.142 + 15.95 + 37.95

rep2_live = as.integer(164.142 + 45.364)

rep3_live = as.integer(171.435 + 120.435)

# Halo Standard
halo1.25 = 89.314

halo2.5 = 758.506

halo5 = 1311.749

halo10 = 4009.426

halo15 = 6267.083
```


```{r}

## Convert ng of loaded Halo Standard to femtomols
# Halo Standard is 61 kDa

halo1.25_femto <- 1.25/(10^9)/61000*(10^15)

halo2.5_femto <- 2.5/(10^9)/61000*(10^15)

halo5_femto <- 5/(10^9)/61000*(10^15)

halo10_femto <- 10/(10^9)/61000*(10^15)

halo15_femto <- 15/(10^9)/61000*(10^15)

```


```{r}

## Make dataframe to get Halo Standard curve line of best fit

# For x-axis
fmol <- c(halo1.25_femto, halo2.5_femto, halo5_femto, halo10_femto, halo15_femto)

# For y-axis
halosignal <- c(halo1.25, halo2.5, halo5, halo10, halo15)

halo.df <- data.frame(fmol, halosignal, lane = "standard" )

# Cell lysates for fixed cell experiments
myosignal_fixed <- c(rep1, rep2, rep3)

# Cell lysates for live cell experiments
myosignal_live <- c(rep1_live, rep2_live, rep3_live)

# Make dataframe with both Halo Standards and Myosin signals 
signalgraph <- halo.df

```


```{r}

## Linear regression analysis on Halo Standard curve

filtered_halo <- signalgraph %>% filter(lane == "standard")
halo.lm <- lm(halosignal ~ fmol + 0, data = filtered_halo)
summary(halo.lm)

slope <- halo.lm$coefficients

# Find lower and upper bounds of 95% CI

confintHalo <- confint(halo.lm, level = 0.95)
confintHalo 

lowbound <- confintHalo[1]/slope

upperbound <- confintHalo[2]/slope

```

```{r}

## We know that mols of Halo Standard = mols of Myo10 in cell lysates

# Mol amount of Myo10 can be calculated from Halo Standard curve
# Because linear fit data is in femto, convert femto to mol with 10^-15

rep1_mol <- rep1/slope * 10^(-15)

rep2_mol <- rep2/slope * 10^(-15)

rep3_mol <- rep3/slope* 10^(-15)

rep1_live_mol <- rep1_live/slope * 10^(-15)

rep2_live_mol <- rep2_live/slope * 10^(-15)

rep3_live_mol <- rep3_live/slope * 10^(-15)

```

```{r}
# For plotting Myo10 onto the standard curve
MyoMolsF <- c(rep1_mol, rep2_mol, rep3_mol) * 10^15
MyoSignalF <- c(rep1, rep2, rep3)

MyoMolsL <- c(rep1_live_mol, rep2_live_mol, rep3_live_mol) * 10^15
MyoSignalL <- c(rep1_live, rep2_live, rep3_live)

M.df_fixed <- data.frame("fmol" = MyoMolsF, "halosignal" = MyoSignalF, lane = "MyoFix")

M.df_live <- data.frame("fmol" = MyoMolsL, "halosignal" =MyoSignalL, lane = "MyoLive")

signalgraphMYO <- full_join(M.df_fixed, M.df_live)

signalgraphfinal <- full_join(signalgraph, signalgraphMYO)
```

```{r}

## Calculate number of Myo10 molecules based on TMR signal (converted to mols) in cell lysates

# This gives us total Myo10 molecules in the cells loaded into the protein gel lanes

rep1_molecule <- rep1_mol *(6.023*10^23)

rep2_molecule <- rep2_mol *(6.023*10^23)

rep3_molecule <- rep3_mol *(6.023*10^23)

rep1_live_molecule <- rep1_live_mol *(6.023*10^23)

rep2_live_molecule <- rep2_live_mol *(6.023*10^23)

rep3_live_molecule <- rep3_live_mol *(6.023*10^23)
```

```{r}

## Calculate number of Myo10 molecules per cell ON AVERAGE 

# 50,000 cells were loaded into the protein gel lane
cellsloaded <- 50000

# Only certain amount of cells were Myo10 expressing, so account for the transfection efficiency per cell rep

rep1_live_pos <- 0.360902256

rep2_live_pos <- 0.158730159

rep3_live_pos <- 0.232758621

rep1_pos <- 0.513513514

rep2_pos <- 0.611111111

rep3_pos <- 0.473333333

# Here are the number of Myo10 molecules per cell 

rep1_avg <- rep1_molecule / (rep1_pos * cellsloaded)

rep2_avg <- rep2_molecule / (rep2_pos * 10000) # Only 10,000 cells for this rep 

rep3_avg <- rep3_molecule / (rep3_pos * cellsloaded)

rep1_live_avg <- rep1_live_molecule / (rep1_live_pos * cellsloaded)

rep2_live_avg <- rep2_live_molecule / (rep2_live_pos * cellsloaded)

rep3_live_avg <- rep3_live_molecule / (rep3_live_pos * cellsloaded)
```


```{r}

## Make scatterplot of Halo standard curve and cell reps 

ggplot(signalgraphfinal, aes(fmol, halosignal, color = lane)) +
 geom_smooth( data = signalgraph %>% filter(lane == "standard"),  method = lm,
              formula = y~x+0,se = TRUE, size = 0.5, fullrange = T) +
  geom_point(size=2) +
    labs(y = 'Signal intensity',
       x = 'Protein (femtomol)') +
  theme_bw() +
    theme(axis.line = element_line(color='black'),
    plot.background = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()) +
scale_x_continuous(expand = expansion(mult = c(0.05, 0.05))) +  scale_y_continuous(expand = expansion(mult = c(0.05, 0.05))) +
  scale_color_manual(labels = c("Cell replicates (fixed)", "Cell replicates (live)", "Standard"), values = c("red", "blue", "black")) +
  theme(legend.position = c(0.3,0.82))+
  theme(legend.title=element_blank()) +
  theme(text = element_text(size = 25), 
        axis.text = element_text(size = 20)) +
  theme(plot.margin = margin(20, 20, 20, 20)) +
   guides(color=guide_legend(override.aes=list(fill=NA)))


```

