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

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


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

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




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

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

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


```{r}
comb <- left_join(cdslist, uniprot, by = "V1") %>% 
  left_join(spur, by = "V1") %>%
  left_join(cel, by = "V1") %>%
  left_join(dmel, by = "V1") %>%
  select(V1, V2.x, V11.x, V2.y, V11.y, V2.x.x, V11.x.x, V2.y.y, V11.y.y) %>%
  rename(cdsID = V1, uniprot = V2.x, u_ev = V11.x, spur = V2.y, s_ev = V11.y, cel = V2.x.x, cel_ev = V11.x.x, dmel = V2.y.y, dmel_ev = V11.y.y) %>%
  left_join(giles, by = c("cdsID" = "ID"))
```

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

```


# 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}
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, by = c("V1" = "cdsID"))
```

