---
title: "14.1-joining-annotations"
output: html_document
---
---
title: "14-joining-annotations"
output: html_document
---

```{r}
library(tidyverse)
```
```{bash}
pwd
```

Bringing in the list of 46753 CDS IDs

```{r}
cdslist <- read.csv("../analyses/GCF_000297895_cdslist.tab", header = FALSE)
```

UNIPROT (but need to redo!!! - end premature)
 
```{r}
suniprot <- read.csv("../analyses/Cg-uniprot_blastx_02.tab", header = FALSE, sep="\t") %>%
  distinct(V1, .keep_all = TRUE)
```


SPUR Protein hits

```{r}
spur <- read.csv("../analyses/Cg-ProteinsSpur5.0_blastx.tab", header = FALSE, sep="\t") %>%
  distinct(V1, .keep_all = TRUE)
```

SPUR nucleotide
```{r}
spurn <- read.csv("../analyses/Cg-SpurCDS_blastn.tab", header = FALSE, sep="\t") %>%
  distinct(V1, .keep_all = TRUE)
```


Drosophila

```
!{bldir}blastn \
-task blastn \
-query ../data/GCF_000297895.1_oyster_v9_cds_from_genomic.fna \
-db ../blastdb/dmel-all-gene-r6.37  \
-out ../analyses/Cg-dmel-gene_blastn_02.tab \
-evalue 1E-05 \
-num_threads 1 \
-max_target_seqs 1 \
-max_hsps 1 \
-outfmt "6 qaccver saccver evalue"
```


```{r}
dmel <- read.csv("../analyses/Cg-dmel-gene_blastn_02.tab", header = FALSE, sep="\t")  %>%
  distinct(V1, .keep_all = TRUE)
```


Celg Gene symbols

```{r}
celsym <- read.csv("../analyses/Cg_Ce-genesym.tab", header = FALSE, sep="\t")
```

JOIN

```{r}
comb <- left_join(cdslist, uniprot, by = "V1") %>%
left_join(spur, by = "V1") %>%
left_join(spurn, by = "V1") %>%
left_join(dmel, by = "V1") %>%
left_join(celsym, by = c("V1" = "V2")) %>%
select(V1, V2.x, V11.x, V2.y, V11.y, V2.x.x, V3.x.x, V2.y.y, V3.y.y, V1.y, V3, V4) %>%
rename(cdsID = V1, uniprot = V2.x, u_ev = V11.x, spur = V2.y, s_ev = V11.y, spurN = V2.x.x, spurN_ev = V3.x.x, dmel = V2.y.y, dmel_ev = V3.y.y, cel_ID = V1.y, cel_ev = V3, cel_sym = V4)
```


# GOing back to Giles Blast

../data/bestblast_/bestblast.tab

```{r}
giles <- read.csv("../data/bestblast_/bestblast.tab", header = TRUE, sep = "\t") %>%
  select(ID, HitAcc, HitDesc, E.Value)
```


```{r}
comb_g <- left_join(comb, giles, by = c("cdsID" = "ID"))
```


```{r}
loc <- read.csv("../data/bestblast_/LOC_seqID_key.tab", header = FALSE, sep = "\t")
```


```{r}
loc_dt <- left_join(loc, comb_g, by = c("V1" = "cdsID"))
```

```{r}
write_tsv(
  loc_dt,
  "../analyses/Cg-annot-join-V1.1.tab"
)

```


JOining Marker file


```{r}
top <- read.csv("../data/topmarker_bla_mitov7_top10perCluster.txt", header = TRUE, sep = "\t")
```


```{r}
annot <- read.csv("../analyses/Cg-annot-join-V1.1.tab", header = TRUE, sep = "\t")
```

```{r}
library(tidyverse)
```


```{r}
top.annotv1.1 <- left_join(top, annot, by = c("gene_id" = "V2"))
```


```{r}
write_tsv(
  top.annotv1.1,
  "../analyses/top.annotv1.1.tab"
)

```
