---
title: "Tip density analysis"
date: 03-1-24
author: Ron Rock, Julia Shangguan
format: html
editor: visual
---

```{r}
#| label: setup
library(tidyverse)
```

```{r}
df <- read_csv("TipConcentration.csv",
               show_col_types = FALSE)

```

# Actin occupancy

Create a function that returns the number of accessible sites on the fascin-actin bundle, as a function of the bundle length (or equivalently, the length of the M10-occupied spot on the bundle). Use this function to create the phase diagram boundary.

From the supplementary materials: "Here, the blue filaments (16/30) are potentially accessible to myosin. In those filaments, only 4/13 actin subunits are oriented out, and truly accessible to Myo10." Those 4/13 subunits occupy 36 nm of filament / bundle length.

```{r}
accessible_actin <- function(len_um) {
    16 * 4 * (1000 / 36) * len_um
}
```

That slope turns out to be 1777.778. Don't need to use that function at all, if using geom_abline(). 

```{r}
# Plotting actin accessibility 

df |> ggplot(aes(Length_um, CorrectedMolecules, color = Molarity > 96)) +
    geom_point() +
    geom_abline(slope = 1777.778) +
    annotate(geom = "text", x = 1.5, y = 1000, label = "Excess actin", size = 6, color = "#F8766D", fontface =2) +
    annotate(geom = "text", x = 0.5, y = 9000, label = "Excess Myo10", size = 6, color = "#00BFC4", fontface =2) +
    labs(x = "Length (µm)", y = "Myo10 Molecules") +
   guides(color = FALSE, size = FALSE) +
   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.0, 0.0))) + 
 scale_y_continuous(expand = expansion(mult = c(0.01, 0.05))) +
   coord_cartesian(xlim = c(0,1.8))  +
  theme(text = element_text(size = 25), axis.text = element_text(size = 16)) +
         theme(plot.margin = margin(20, 20, 20, 20)) 
```

# Membrane occupancy

Estimates of membrane occupancy from supplementary materials:

Low estimate of Myo10 membrane area occupancy : 5.94 \* 2.82 = 16.75 nm^2^

High estimate of Myo10 membrane area occupancy: 13.17 \* 6.99 = 92 nm^2^

Start with the cylinder model with the hemispherical cap:

```{r}
accessible_membrane_cyl <- function(len_um) {
    2 * pi * 100^2 +  # spherical cap, with r = 100 nm
        2 * pi * 100 * (len_um * 1000 - 100)  # Assume 100 nm spherical cap is part of total length
}

mem_df <- tibble(
    Length_um = seq(0, 1.75, length.out = 100),
    small_footprint_count = accessible_membrane_cyl(Length_um) / 16.75,
    large_footprint_count = accessible_membrane_cyl(Length_um) / 92
)
```


```{r}
# Plotting membrane accessibility 

df |> 
  ggplot( aes(x=Length_um, y=CorrectedMolecules, color = df$CorrectedMolecules > (accessible_membrane_cyl(Length_um))/92)) +
    #geom_point(aes(color = Width_um)) +
    geom_point() +
  geom_line(data = mem_df, aes(Length_um, large_footprint_count), color = "black") +
    annotate(geom = "text", x = 1.4, y = 2100, label = "Excess membrane", size = 6, color = "#F8766D", fontface =2) +
    annotate(geom = "text", x = 0.32, y = 10000, label = "Excess Myo10", size = 6, color = "#00BFC4", fontface =2) +
    #xlim(0, NA) +
    labs(x = "Length (µm)", y = "Myo10 Molecules") +
    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.0, 0.0))) + 
  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
  theme(text = element_text(size = 25), axis.text = element_text(size = 16)) +
         theme(plot.margin = margin(20, 20, 20, 20)) +
  guides(color = FALSE, size = FALSE) 

```

