---
title: "04.3-miRNA-comparison-region-tests"
author: "Kathleen Durkin"
date: "2025-10-03"
output: 
  github_document:
    toc: true
    number_sections: true
  bookdown::html_document2:
    theme: cosmo
    toc: true
    toc_float: true
    number_sections: true
    code_folding: show
    code_download: true
  html_document:
    theme: cosmo
    toc: true
    toc_float: true
    number_sections: true
    code_folding: show
    code_download: true
editor_options: 
  markdown: 
    wrap: 72
---

Load packages
```{r}
library(dplyr)
library(tidyr)
library(ggplot2)
library(stringr)
library(purrr)
library(GSEABase)
library(GO.db)
library(knitr)
library(tidyverse)
```

Load and format FA tables:

```{r}
# Apul
Apul_FA <- read.csv("../../D-Apul/output/09.13-Apul-mRNA-miRNA-interactions-FE-pooled/miRNA_pooled_targets_FA.csv") %>% dplyr::select(-X)

# Peve
Peve_FA <- read.csv("../../E-Peve/output/10.14-Peve-mRNA-miRNA-interactions-FE-pooled/miRNA_pooled_targets_FA.csv") %>% dplyr::select(-X)

# Ptuh
Ptuh_FA <- read.csv("../../F-Ptuh/output/11.14-Ptuh-mRNA-miRNA-interactions-FE-pooled/miRNA_pooled_targets_FA.csv") %>% dplyr::select(-X)
```

From region (3UTR, 5UTR, and CDS) gffs, get total # nucleotides represented
```{r}
# A. pulchra
Apul_3UTR_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../D-Apul/output/15-Apul-annotate-UTRs/Apul.GFFannotation.3UTR_1kb_corrected.gff", intern = TRUE))

Apul_5UTR_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../D-Apul/output/15-Apul-annotate-UTRs/Apul.GFFannotation.5UTR_1kb_corrected.gff", intern = TRUE))

Apul_CDS_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../D-Apul/output/15-Apul-annotate-UTRs/Apulcra-genome-mRNA_only.gff", intern = TRUE))


# P. evermanni
Peve_3UTR_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../E-Peve/output/16-Peve-annotate-UTRs/Peve.GFFannotation.3UTR_1kb_corrected.gff", intern = TRUE))

Peve_5UTR_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../E-Peve/output/16-Peve-annotate-UTRs/Peve.GFFannotation.5UTR_1kb_corrected.gff", intern = TRUE))

Peve_CDS_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../E-Peve/output/16-Peve-annotate-UTRs/Peve-genome-mRNA_only.gff", intern = TRUE))



# P. tuahiniensis

Ptuh_3UTR_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../F-Ptuh/output/16-Ptuh-annotate-UTRs/Ptuh.GFFannotation.3UTR_1kb_corrected.gff", intern = TRUE))

Ptuh_5UTR_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../F-Ptuh/output/16-Ptuh-annotate-UTRs/Ptuh.GFFannotation.5UTR_1kb_corrected.gff", intern = TRUE))

Ptuh_CDS_sumlength <- as.numeric(system("awk '$1 !~ /^#/ { sum += ($5 - $4 + 1) } END { print sum }' ../../F-Ptuh/output/16-Ptuh-annotate-UTRs/Ptuh-genome-mRNA_only.gff", intern = TRUE))
```

NOTE: need to pre-filter before getting the above sums, because some genes are unexpressed, and thus inherently pre-excluded from inclusion in the binding+coexpressed lists.
