---
title: "22-lncRNA-clean-up"
author: "Zach Bengtsson"
date: "2025-07-21"
output: html_document
---

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

# Remove Duplicates

Remove duplicates in BED file from output folder
```{bash}
awk '!seen[$0]++' ~/github/deep-dive/F-Pmea/output/02-lncRNA-discovery/Pmea_lncRNA.bed > ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA_de-duplicated.bed

```

```{bash}
wc -l ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA_de-duplicated.bed
```

12212 after removing duplicates

# Shift BED positions over by 1

```{bash}
awk '{
  $2 = $2 + 1;
  $3 = $3;
  print
}' OFS='\t' ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA_de-duplicated.bed > ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.bed

```

```{bash}
head ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.bed
tail ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.bed
```

ctrl+F in bed produced 0 occurences of -1 positions

```{bash}
echo "Negative start coordinates:" 
awk '$2 < 0' ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.bed
```

# Subset new FASTA

Download genomic fasta
```{bash}
# Navigate to your desired download directory
cd ~/github/deep-dive/F-Pmea/data/22-lncRNA-clean-up

# Use wget to download only .sorted.bam files
wget "https://owl.fish.washington.edu/halfshell/genomic-databank/Pocillopora_meandrina_HIv1.assembly.fasta"


```


Subset original genomic FASTA with new bed file to obstain FASTA of lncRNAs
```{bash}
/home/shared/bedtools2/bin/bedtools getfasta \
-fi ~/github/deep-dive/F-Pmea/data/22-lncRNA-clean-up/Pocillopora_meandrina_HIv1.assembly.fasta \
-bed ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.bed \
-fo ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.fasta

```


```{bash}
grep -c '^>' ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.fasta
head ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.fasta
tail ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.fasta
```
Ran this code and the final count is 12212, the same as the bed file.

```{bash}
cp ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.fasta ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuh_lncRNA.fasta
```

```{bash}
cp ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuahiniensis_lncRNA.bed ~/github/deep-dive/F-Pmea/output/22-lncRNA-clean-up/Ptuh_lncRNA.bed
```
