```{bash}
cd /home/shared/8TB_HDD_02/cnmntgna/Applications/bioinfo/
curl -O https://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/LATEST/ncbi-blast-2.13.0+-x64-linux.tar.gz
tar -xf ncbi-blast-2.13.0+-x64-linux.tar.gz
```

```{bash}
ls /home/shared/8TB_HDD_02/cnmntgna/Applications/bioinfo/

# trying to remove macos copy, receive an error message
# made the removal happen over in the 'Terminal' access tab
# rm -r ncbi-blast-2.13.0+-x64-macosx.tar.gz
```

```{bash}
/home/shared/8TB_HDD_02/cnmntgna/Applications/bioinfo/ncbi-blast-2.13.0+/bin/blastx -h
```

```{bash}
cd ../data
curl -O https://ftp.uniprot.org/pub/databases/uniprot/current_release/knowledgebase/complete/uniprot_sprot.fasta.gz
mv uniprot_sprot.fasta.gz uniprot_sprot_r2023_01.fasta.gz
gunzip -k uniprot_sprot_r2023_01.fasta.gz
ls ../data
```

```{bash}
# add r engine/ false echo code for rendering in 1.1
/home/shared/8TB_HDD_02/cnmntgna/Applications/bioinfo/ncbi-blast-2.13.0+/bin/makeblastdb \
-in /home/shared/8TB_HDD_02/cnmntgna/data/uniprot_sprot_r2023_01.fasta \
-dbtype prot \
-out /home/shared/8TB_HDD_02/cnmntgna/output/blastdb/uniprot_sprot_r2023_01
```

```{bash}
curl https://eagle.fish.washington.edu/cnidarian/Ab_4denovo_CLC6_a.fa \
-k \
> /home/shared/8TB_HDD_02/cnmntgna/data/Ab_4denovo_CLC6_a.fa
```

```{bash}
head /home/shared/8TB_HDD_02/cnmntgna/data/Ab_4denovo_CLC6_a.fa
echo "How many sequences are there?"
grep -c ">" /home/shared/8TB_HDD_02/cnmntgna/data/Ab_4denovo_CLC6_a.fa
```

```{bash}
#fix my paths for reproducibility purposes, the full path is incorrect for that purpose
/home/shared/8TB_HDD_02/cnmntgna/Applications/bioinfo/ncbi-blast-2.13.0+/bin/blastx \
-query /home/shared/8TB_HDD_02/cnmntgna/data/Ab_4denovo_CLC6_a.fa \
-db /home/shared/8TB_HDD_02/cnmntgna/output/blastdb/uniprot_sprot_r2023_01 \
-out /home/shared/8TB_HDD_02/cnmntgna/output/Ab_4-uniprot_blastx.tab \
-evalue 1E-20 \
-num_threads 20 \
-max_target_seqs 1 \
-outfmt 6

#code throws the following warning: Warning: [blastx] Examining 5 or more matches is recommended
```

```{bash}
head -2 /home/shared/8TB_HDD_02/cnmntgna/output/Ab_4-uniprot_blastx.tab
wc -l /home/shared/8TB_HDD_02/cnmntgna/output/Ab_4-uniprot_blastx.tab
```

```{bash}
curl -O "Accept: text/plain; format=tsv" "https://rest.uniprot.org/uniprotkb/search?query=reviewed:true+AND+organism_id:9606"

```

```{bash}
#THIS CODE CAUSES ERROR
curl -O -H "Accept: text/plain; format=tsv" "https://rest.uniprot.org/uniprotkb/stream?compressed=true&fields=accession%2Creviewed%2Cid%2Cprotein_name%2Cgene_names%2Corganism_name%2Clength%2Cgo_f%2Cgo%2Cgo_p%2Cgo_c%2Cgo_id%2Ccc_interaction%2Cec%2Cxref_reactome%2Cxref_unipathway%2Cxref_interpro&format=tsv&query=%28%2A%29%20AND%20%28reviewed%3Atrue%29"


#this is the reference table with GO terms and protein names to join with my blast output terms. I can use the second gannet url to bypass. This is an easy confuse becasue my first DB is named the same but is just so I can reference. Note I am aligning, not comparing the sequences.
```

```{bash}
head -2 /home/shared/8TB_HDD_02/cnmntgna/output/Ab_4-uniprot_blastx.tab
wc -l /home/shared/8TB_HDD_02/cnmntgna/output/Ab_4-uniprot_blastx.tab
```

```{bash}

#not sure what broken pipe means, google says it is a mismatch of tasks, but i need to look further to understand what that means.
tr '|' '\t' < /home/shared/8TB_HDD_02/cnmntgna/output/Ab_4-uniprot_blastx.tab | head -2
```

```{bash}
tr '|' '\t' < /home/shared/8TB_HDD_02/cnmntgna/output/Ab_4-uniprot_blastx.tab \
> /home/shared/8TB_HDD_02/cnmntgna/output/Ab_4-uniprot_blastx_sep.tab
```

```{bash}
head -2 /home/shared/8TB_HDD_02/cnmntgna/data/uniprot_table_r2023_01.tab
wc -l /home/shared/8TB_HDD_02/cnmntgna/data/uniprot_table_r2023_01.tab
```

```{r}
library(tidyverse)
install.packages("kableExtra")
library("kableExtra")
```

```{r}
bltabl <- read.csv("../output/Ab_4-uniprot_blastx_sep.tab", sep = '\t', header = FALSE)
spgo <- read.csv("../data/uniprot_table_r2023_01.tab", sep = '\t', header = TRUE)
str(spgo)
```

```{r}
kbl(
head(
  left_join(bltabl, spgo,  by = c("V3" = "Entry")) %>%
  select(V1, V3, V13, Protein.names, Organism, Gene.Ontology..biological.process., Gene.Ontology.IDs) %>% mutate(V1 = str_replace_all(V1, 
            pattern = "solid0078_20110412_FRAG_BC_WHITE_WHITE_F3_QV_SE_trimmed", replacement = "Ab"))
)
) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
```

```{r}
left_join(bltabl, spgo,  by = c("V3" = "Entry")) %>%
  select(V1, V3, V13, Protein.names, Organism, Gene.Ontology..biological.process., Gene.Ontology.IDs) %>% mutate(V1 = str_replace_all(V1, 
            pattern = "solid0078_20110412_FRAG_BC_WHITE_WHITE_F3_QV_SE_trimmed", replacement = "Ab")) %>%
  write_delim("../output/blast_annot_go.tab", delim = '\t')
```

```{r}
annot_tab <- read.csv("../output/blast_annot_go.tab", sep = '\t', header = TRUE)
```


