---
title: "Create Library Demo"
author: "Witold Wolski"
date: "29 September 2015"
output: pdf_document
editor_options: 
  chunk_output_type: console
---

<!--
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Supplementary Materials}
-->


# Create decoy fasta

Create fasta file with FGCZ contaminants and decoys.


```{r}

rm(list = ls())
library(prozor)

file = file.path(system.file("extdata/uniprot_taxonomy_Oryctolagus_cuniculus.fasta.gz", package = "prozor")
res <- createDecoyDB(c(file,file))

```

# Removing signal peptides
## Homo sapiens

```{r}
library(prozor)
hsfasta <- loadHomoSapiensFasta()
hssignal <- loadHomoSapiensSignalPeptides()
length(grep("SIGNAL",hssignal$Signal.peptide))/length(hssignal$Signal.peptide)*100

noSigFasta <- removeSignalPeptide(hsfasta, hssignal)

homoNoSigFile <- tempfile(pattern = "homo", tmpdir = tempdir(), fileext = "fasta")
homoNoSigFile

writeFasta(file = homoNoSigFile, noSigFasta)
resDB <- createDecoyDB(homoNoSigFile)

homoNoSigDecoyFile <- tempfile(pattern = "homo_d_", tmpdir = tempdir(), fileext = "fasta")

writeFasta(file = homoNoSigDecoyFile, res )


```


## Mus Musculus

```{r}
library(prozor)
library(seqinr)

hsfasta <- loadMusMusculusFasta()

annot <- "zz|uniprot_20160320|mus_musculus_10090_reviewed"
dummy <-as.SeqFastaAA("CRAPCRAPCRAP", Annot=annot, name= annot)

dbname <- tempfile(pattern = "mus_musculus", tmpdir = tempdir(), fileext = "fasta")

writeFasta(file =dbname, c(dummy,hsfasta))
resDB <- createDecoyDB(dbname)
writeFasta(file= "p1687_withSignalPeptides_d_20160405.fasta" , resDB)

```


```{r}

library(prozor)
hsfasta <- loadMusMusculusFasta()
hssignal <- loadMusMusculusSignalPeptides()


head(hssignal)

hssignal[grep("*GKN2_MOUSE*",hssignal$Entry.name),]

length(grep("SIGNAL",hssignal$Signal.peptide))/length(hssignal$Signal.peptide)*100


noSigFasta <- removeSignalPeptide(hsfasta, hssignal)

hsfasta[5627]
noSigFasta[5627]

musNoSigFile <-tempfile(pattern = "mus_musculus_nosig", tmpdir = tempdir(), fileext = "fasta")


writeFasta(file = musNoSigFile, noSigFasta)
resDB <- createDecoyDB(musNoSigFile)

writeFasta(file="p1687_noSignalPeptides_d_29032016.fasta",resDB )


```

# Strange bean with id rename example

```{r}
library(prozor)
fasta <- readPeptideFasta("d:/projects/p2147/NCBI_txid3821_20160410.fasta")

for(i in seq_along(fasta)){
    attributes(fasta[[i]])$name <- gsub("gi\\|[0-9]*\\|gb","gb",attributes(fasta[[i]])$name)
    attributes(fasta[[i]])$Annot <- gsub("gi\\|[0-9]*\\|gb","gb",attributes(fasta[[i]])$Annot)
}

writeFasta(file = "d:/projects/p2147/p2147_NCBI_txid3821_20160410.fasta", fasta )
writeFasta(file="d:/projects/p2147/p2147_db1_20160421.fasta", fasta,loadContaminantsFasta())
length(c(fasta,loadContaminantsFasta()))
resDB <- createDecoyDB("d:/projects/p2147/p2147_NCBI_txid3821_20160410.fasta")
length(resDB)
writeFasta(resDB, file="d:/projects/p2147/p2147_db1_d_20160421.fasta")

```


# Read table


```{r}
library(prozor)

resDB <- createDecoyDB("c:/temp/short_headers.all_concatenated.windows_linebreaks.fasta",annot = "zz|20160520PeterH|FromPeterHunziker")
writeFasta(resDB, file="c:/temp/p65_8283_carniovorus_swiss_20160520.fasta")

resDB <- createDecoyDB("c:/temp/Tryp_Leishmania_totalProt_nr_8521.fasta",annot = "zz|20160520PeterH|FromPeterHunziker")
writeFasta(resDB, file="c:/temp/p65_8521_tryp_leish_totalprot_20160520.fasta")

resDB <- createDecoyDB("Z:/p0/PH/griseus_panproteom_nr.fasta", annot="zz|20160623PeterH|FromPeterHunziker")
writeFasta(resDB, file="Z:/p0/PH/p65_griseus_panproteom_nr_d_20160623.fasta")

library(seqinr)
annot="zz|sourceOf|database"
dummy <-as.SeqFastaAA("CRAPCRAPCRAP", Annot=annot, name= annot)
dummy
```


# SRM Service

```{r}
xx <- readPeptideFasta("d:/projects/SRMServiceDB/20160804_targets.fasta")
xx_rev <- reverseSeq(xx)

all <- readPeptideFasta("d:/projects/SRMServiceDB/fgcz_srmService_db1_20160606.fasta")
sum(grepl("REV_",names(all)))
sum(!grepl("REV_",names(all)))

new <- c(all, xx, xx_rev)
length(new)
length(all)
writeFasta(new, file="d:/projects/fgcz_srmService_d_db1_20160707.fasta")

```

# p2135

```{r}
library(prozor)
resDB <- createDecoyDB("d:/projects/p2135_Hottiger/uniprot-all.fasta",annot = "zz|p2135_d_9606_20160928.fasta|Uniprot canonical 20,177 entries")
writeFasta(resDB, file="d:/projects/p2135_Hottiger/p2135_d_9606_20160928.fasta")

```



# p1511

```{r}
library(prozor)
dir<-"Z:/p1511/Proteomics/newFasta2016"
outfile <- "p1511_d_NEW_2016104.fasta"
file.remove(file.path(dir, outfile))

files<-dir(dir)
annot <- "zz|p1551_d_2016104.fasta|VariousOrg"

annot <- paste(c(annot, gsub(" ","_",files)),collapse = " ")
files <- file.path("Z:/p1511/Proteomics/newFasta2016", files )
resDB <- createDecoyDB(files, annot=paste("zz|p1551_d_NEW_2016104.fasta|VariousDatabasesfrom ",annot= annot ))

sum(duplicated(names(resDB)))
resDB <-resDB[!duplicated(names(resDB))]
length(resDB)

writeFasta(resDB, file=file.path(dir, outfile))


```

## big version

```{r}
library(prozor)
dir<-"Z:/p1511/Proteomics/newFasta2016_Large/"
outfile <- "p1511_d_LARGE_NOHUMAN_20161017.fasta"
file.remove(file.path(dir, outfile))

files <- list.files(dir)
files <- grep("fasta",files,value=TRUE)

annot <- "zz|p1511_d_LARGE_NOHUMAN_20161017.fasta|VariousOrg dbs from p1511/Proteomics/newFasta2016_Large"

annot <- paste(c(annot, gsub(" ","_",files)),collapse = " ")
files <- file.path(dir, files )

files
resDB <- createDecoyDB(files, annot=annot)
length(resDB)
writeFasta(resDB, file=file.path(dir, "output", outfile))

```


## contaminants


```{r}
cont <- loadContaminantsFasta()
cont[[1]]
tmp <- (lapply(cont, function(x){attributes(x)$Annot}))
tmp <- data.frame(oldID = names(tmp), annot= unlist(tmp))
tmp$annot <- gsub(">zz\\|ZZ_FGCZCont[0-9]+\\|","", tmp$annot)

quantable::write.tab(tmp,file="newSuggestedContaminants.txt")


```


# p1797

```{r}
library(prozor)
dir<-"d:/projects/p1797/"
#uniprot-proteomeAUP000008227.fasta"
outfile <- "p1797_d_UP000008227_20161010.fasta"

files<-dir(dir)
files <- grep("*.fasta",files,value = TRUE)
files <- file.path(dir, files )
annot <- "zz|p1797_d_AUP000008227_20161010|UP000008227 http://www.uniprot.org/proteomes/UP000008227"
resDB <- createDecoyDB(files, annot= annot)

outputdir <- file.path(dir,"output")
dir.create(outputdir)

writeFasta(resDB, file=file.path(outputdir, outfile))

annot <- "zz|p1797_AUP000008227_20161010|UP000008227 http://www.uniprot.org/proteomes/UP000008227"
outfile <- "p1797_UP000008227_20161010.fasta"

resDB <- createDecoyDB(files, annot= annot, revLab=NULL)
length(resDB)

writeFasta(resDB, file=file.path(outputdir, outfile))
```


# p1000 triple proteome


```{r}

library(prozor)
dir<-"d:/projects/p1000/databases/"
#uniprot-proteomeAUP000008227.fasta"
outfile <- "p1000_d_tripleProteomeHYE_20161011.fasta"

files<-dir(dir)
files <- grep("*.fasta",files,value = TRUE)
files <- file.path(dir, files )
annot <- "zz|p1000_d_tripleProteome|UP000000625UP000002311up000005640" 
#http://www.uniprot.org/uniprot/?query=proteome:UP000002311
#http://www.uniprot.org/uniprot/?query=proteome:up000005640
#http://www.uniprot.org/uniprot/?query=proteome:UP000000625

resDB <- createDecoyDB(files, annot= annot)

outputdir <- file.path(dir,"output")
dir.create(outputdir)

writeFasta(resDB, file=file.path(outputdir, outfile))

annot <- "zz|p1000_tripleProteome|UP000000625UP000002311up000005640" #http://www.uniprot.org/proteomes/UP000008227"
outfile <- "p1000_tripleProteomeHYE_20161011.fasta"

resDB <- createDecoyDB(files, annot= annot, revLab=NULL)
length(resDB)

writeFasta(resDB, file=file.path(outputdir, outfile))

```


# make human only database

```{r}
library(prozor)
#http://www.uniprot.org/uniprot/?query=proteome:up000005640

dir<-"d:/projects/p1000/databases/"
#uniprot-proteomeAUP000008227.fasta"

files<-dir(dir)

outfile <- "p1000_d_tripleP_HS_20161013.fasta"
files <- file.path(dir, files )
annot <- "zz|p1000_d_tripleProteome|up000005640 Homo Sapiens http://www.uniprot.org/uniprot/?query=proteome:UP000002311 http://www.uniprot.org/uniprot/?query=proteome:up000005640" 

resDB <- createDecoyDB(files[1], annot= annot)
outputdir <- file.path(dir,"output")
writeFasta(resDB, file=file.path(outputdir, outfile))

```

## make yeast only db

```{r}

#http://www.uniprot.org/uniprot/?query=proteome:UP000002311
library(prozor)
dir<-"d:/projects/p1000/databases/"
#uniprot-proteomeAUP000008227.fasta"

files<-dir(dir)

outfile <- "p1000_d_tripleP_Yest_20161013.fasta"
files <- file.path(dir, files )
annot <- "zz|p1000_d_tripleProteome|UP000002311 Yeast http://www.uniprot.org/uniprot/?query=proteome:UP000002311" 

resDB <- createDecoyDB(files[2], annot= annot)
outputdir <- file.path(dir,"output")
writeFasta(resDB, file=file.path(outputdir, outfile))

```

```{r}
#http://www.uniprot.org/uniprot/?query=proteome:UP000000625

library(prozor)
dir<-"d:/projects/p1000/databases/"
files<-dir(dir)

outfile <- "p1000_d_tripleP_EColi_20161013.fasta"
files <- file.path(dir, files )
annot <- "zz|p1000_d_tripleProteome|UP000000625 EColi http://www.uniprot.org/uniprot/?query=proteome:UP000000625" 

resDB <- createDecoyDB(files[3], annot= annot)
outputdir <- file.path(dir,"output")
writeFasta(resDB, file=file.path(outputdir, outfile))

```

# Simonas Savickas 

```{r}
library(prozor)



file <- "d:/projects/p2123/data/uniprot-proteomeUP000001075_Savitzkas.fasta"
annot <- "zz|p2123_d_UP000001075_CNL|UP000001075_CNL  UP000001075 unreviewed no isoforms"
outfile <- "p2123_d_UP000001075_CNL.fasta"

resDB <- createDecoyDB(file, annot= annot)
outputdir <- file.path(dir,"output")
writeFasta(resDB, file="d:/projects/p2123/data/p2123_d_UP000001075_CNL_13122016.fasta")

```

# p2095


```{r}
library(prozor)
files1 <- "z:/p2095/Proteomics/fasta_db/Mouse/uniprot-proteome_UP000000589_cnl.fasta"
files2 <- "z:/p2095/Proteomics/fasta_db/Mouse/irtfusion.fasta"
annot <- "zz|p2095_UP000000589_cnl|UP000000589_cnl irtfusion and contaminant 13122016"
outfile <- "p2095_UP000000589_cnl_20161213.fasta"
resDB<-createDecoyDB(c(files1,files2), revLab=NULL, useContaminants = FALSE, annot=annot)
writeFasta(resDB, file=file.path("z:/p2095/Proteomics/fasta_db/Mouse/",outfile))

files1 <- "z:/p2095/Proteomics/fasta_db/Mouse/uniprot-mouse_sp_cnl.fasta"
files2 <- "z:/p2095/Proteomics/fasta_db/Mouse/irtfusion.fasta"
annot <- "zz|p2095_uniprot-mouse_sp_cnl|uniprot-mouse_sp_cnl irtfusion and contaminant 13122016"
outfile <- "p2095_uniprot-mouse_sp_cnl_20161213.fasta"
resDB<-createDecoyDB(c(files1,files2), revLab=NULL, useContaminants = FALSE, annot=annot)
writeFasta(resDB, file=file.path("z:/p2095/Proteomics/fasta_db/Mouse/",outfile))
```

# p2242

```{r}
library(prozor)
files1 <- "z:/p2242/Proteomics/fasta_db/p2242_dog/uniprot_proteome_UP000002254_cnl.fasta"
annotation <- readLines("z:/p2242/Proteomics/fasta_db/p2242_dog/annotation.txt")
resDB <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation)
outfile <- paste(dirname(files1),".fasta", sep="")
writeFasta(resDB, file=outfile)

```



```{r}
files1 <- "z:/p2242/Proteomics/fasta_db/p2242_dog_iso/uniprot_proteome_UP000002254_cnl_iso.fasta"
annotation <- readLines("z:/p2242/Proteomics/fasta_db/p2242_dog_iso/annotation.txt")

annotation[1]
resDB <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation)
length(resDB)

outfile <- paste(dirname(files1),".fasta", sep="")
outfile
writeFasta(resDB, file=outfile)

```


# Tobi Weiss


```{r}
library(prozor)
files1 <- "d:/Dropbox/DataAnalysis/Tobi_Weiss_Lymphomproben/FASTA/31052017_HomoSapiens9606Cnl.fasta"
annotation <- readLines("d:/Dropbox/DataAnalysis/Tobi_Weiss_Lymphomproben/FASTA/Annotation.txt")
resDB <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = "DECOY_")
writeFasta(resDB, file="d:/Dropbox/DataAnalysis/Tobi_Weiss_Lymphomproben/FASTA/31052017_HomoSapiens9606Cnl_c_d.fasta")


files1 <- "d:/Dropbox/DataAnalysis/Tobi_Weiss_Lymphomproben/FASTA/31052017_HomoSapiens9606CnlIsoforms.fasta"
annotation <- readLines("d:/Dropbox/DataAnalysis/Tobi_Weiss_Lymphomproben/FASTA/Annotation.txt")
resDB <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = "DECOY_")
writeFasta(resDB, file="d:/Dropbox/DataAnalysis/Tobi_Weiss_Lymphomproben/FASTA/31052017_HomoSapiens9606CnlIsoforms_c_d.fasta")


```


# p2116


```{r}
library(prozor)
library("stringr")

x <- 'Z:/p2116/Proteomics/fasta_db/P2116_db1_Focrace2_54008/'
x <- 'Z:/p2116/Proteomics/fasta_db/P2116_db2_Fo5176/'
x <- 'Z:/p2116/Proteomics/fasta_db/P2116_db3_arabidopsis_Focrace2_54008_Fo5176/'

dbname <- basename(x)
fasta<-grep("fasta", dir(x),value = TRUE)
files1 <- file.path(x,fasta)
annot <- grep("annotation",dir(x), value=TRUE)
annotation <- readLines(file.path(x,annot))

resDBDecoy <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = "REV_")
resDB <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = NULL)

xx <- file.path(x, paste(dbname,"_d_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)
xx <- file.path(x, paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)


```


# p2501


```{r}
rm(list=ls())
library(prozor)
library("stringr")

databasedirectory <- 'Z:/p2501/Proteomics/fasta_db/p2501_db1_Acostaricensis'
databasedirectory <- 'Z:/p2501/Proteomics/fasta_db/p2501_db2_Acantonensis/'

dbname <- basename(databasedirectory)
fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annotation <- readLines(file.path(databasedirectory,annot))

resDBDecoy <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = "REV_")
resDB <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = NULL)
length(resDB)
sum(duplicated(resDB))
sum(duplicated(resDBDecoy))
head(names(resDB))
dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

xx <- file.path(databasedirectory, paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)
xx <- file.path(databasedirectory, paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```

# p2507


```{r}
rm(list=ls())
library(prozor)
library("stringr")

#databasedirectory <- 'Z:/p2507/Proteomics/fasta_db/p2507_db1_9606/'
databasedirectory <- 'Z:/p2507/Proteomics/fasta_db/p2507_db2_28285/'

dbname <- basename(databasedirectory)
fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annotation <- readLines(file.path(databasedirectory,annot))

resDBDecoy <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = "REV_")
resDB <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = NULL)

sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
sum(duplicated(names(resDB)))
sum(duplicated(resDB))


dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```


# p2122


```{r}
rm(list=ls())
library(prozor)
library("stringr")

#databasedirectory <- 'Z:/p2507/Proteomics/fasta_db/p2507_db1_9606/'
databasedirectory <- 'Z:/p2122/Proteomics/fasta_db/p2122_db1_RatProteome_BioID/'

dbname <- basename(databasedirectory)
fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annotation <- readLines(file.path(databasedirectory,annot))

resDBDecoy <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = "REV_")
resDB <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation,revLab = NULL)

sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
sum(duplicated(names(resDB)))
sum(duplicated(resDB))


dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```


# p1511

```{r}

databasedirectory <- ("Z:/p1511/Proteomics/fasta_db/p1511_db2_9species/")
dbname <- basename(databasedirectory)
fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annotation <- readLines(file.path(databasedirectory,annot))
annotation
resDBDecoy <- createDecoyDB(files1,useContaminants = TRUE, annot=annotation)
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)

```


# p2244

```{r}
library(prozor)
databasedirectory <- ("Z:/p2244/Proteomics/fasta_db/p2244_db1_HS/")
databasedirectory <- ("Z:/p2244/Proteomics/fasta_db/p2244_db1_HSIsoforms/")

dbname <- basename(databasedirectory)
fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annotation <- readLines(file.path(databasedirectory,annot))
annotation
resDB <- createDecoyDB(files1,useContaminants = loadContaminantsNoHumanFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))
length(resDB)
dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)


resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsNoHumanFasta(), annot=annotation)
length(resDBDecoy)

sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)

```


# p2569

```{r}

library(prozor)
databasedirectory <- ("Z:/p2569/Proteomics/fasta_db/p2569_db1_mouse_Generic_PXS/")
#databasedirectory <- ("Z:/p2244/Proteomics/fasta_db/p2244_db1_HSIsoforms/")
dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)


### CREATING DECOY DB

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
length(resDBDecoy)

sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)


```


# p2626


```{r}

library(prozor)
databasedirectory <- ("Z:/p2626/Proteomics/fasta_db/p2626_db1_TgondiiGT1")
databasedirectory <- ("Z:/p2626/Proteomics/fasta_db/p2626_db2_TgondiiME49/")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)


### CREATING DECOY DB

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)

sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)

```


# p2651


```{r}

library(prozor)
databasedirectory <- ("Z:/p2651/Proteomics/fasta_db/p2651_db1_BurkholdE264/")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)


### CREATING DECOY DB

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)

sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)


```

# p1000 


```{r}
library(prozor)
databasedirectory <- ("Z:/p1000/fasta_db/p1000_db01_HLAproject_Human/")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsNoHumanFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)


### CREATING DECOY DB

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsNoHumanFasta(), annot=annotation)
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)

```


# p2447 


```{r}
library(prozor)
databasedirectory <- ("Z:/p2447/Proteomics/fasta_db/p2447_db1_mus_uniprot_20180531/")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)


### CREATING DECOY DB

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDBDecoy, file=xx)

```





# p2799

## p2799_db1_PAO1

```{r}
library(prozor)
databasedirectory <- ("Z:/p2799/Proteomics/fasta_db/p2799_db1_PAO1/")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)


### CREATING DECOY DB

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))

writeFasta(resDBDecoy, file=xx)

```


## p2799_db4_KT2440_Piso

### Create forward db

```{r}

library(prozor)
databasedirectory <- ("Z:/p2799/Proteomics/fasta_db/p2799_db4_KT2440_Piso")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)
```


### CREATING DECOY DB

```{r}
resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))

writeFasta(resDBDecoy, file=xx)

```


## p2971_db1_Wheat_Zymoseptoria

### Create forward db

```{r}
library(prozor)
databasedirectory <- ("Z:/p2971/Proteomics/fasta_db/p2971_db1_Wheat_Zymoseptoria")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)
```


### CREATING DECOY DB

```{r}
resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))

writeFasta(resDBDecoy, file=xx)

```


## p2558_db2_rat

### Create forward db

```{r}
library(prozor)
databasedirectory <- ("Z:/p2558/Proteomics/fasta_db/p2558_db2_rat/")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```


### CREATING DECOY DB

```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))

writeFasta(resDBDecoy, file=xx)

```



## p2558_db1_mouse

### Create forward db

```{r}
library(prozor)
databasedirectory <- ("Z:/p2558/Proteomics/fasta_db/p2558_db1_mouse/")

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
sum(duplicated(names(resDB)))
sum(duplicated(resDB))

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```


### CREATING DECOY DB

```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))

writeFasta(resDBDecoy, file=xx)

```




## p1511_db11_d_co_culture



### Create forward db

```{r}
library(prozor)
databasedirectory <- ("Z:/p1511/Proteomics/fasta_db/p1511_db11_d_co_culture")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```

### CREATING DECOY DB


```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
resDBDecoy <- resDBDecoy[!duplicated(names(resDBDecoy))]
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
xx
writeFasta(resDBDecoy, file=xx)

```

## p2953_db1_d_drosophila_2species



Y:\p2953\Proteomics\fasta_db\p2953_db1_d_drosophila_2species


### Create forward db

```{r}
library(prozor)
databasedirectory <- ("Z:/p2953/Proteomics/fasta_db/p2953_db1_d_drosophila_2species")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```

### CREATING DECOY DB


```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
resDBDecoy <- resDBDecoy[!duplicated(names(resDBDecoy))]
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
xx
writeFasta(resDBDecoy, file=xx)

```




## p2433_db1_PphyPvul



Z:\p2433\Proteomics\fasta_db


### Create forward db

```{r}
library(prozor)
databasedirectory <- ("Z:/p2433/Proteomics/fasta_db/p2433_db1_PphyPvul")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```

### CREATING DECOY DB


```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
resDBDecoy <- resDBDecoy[!duplicated(names(resDBDecoy))]
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
xx
writeFasta(resDBDecoy, file=xx)

```



## p3166_db1_CopCin

### Create forward db

```{r}
library(prozor)
databasedirectory <- ("Z:/p3166/Proteomics/fasta_db/p3166_db1_CopCin")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```



```{r}
library(prozor)
databasedirectory <- ("Z:/p3166/Proteomics/fasta_db/p3166_db2_CopCinPr")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```


```{r}
library(prozor)
databasedirectory <- ("Z:/p3166/Proteomics/fasta_db/p3166_db3_CopCinPe")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```

```{r}
library(prozor)
databasedirectory <- ("Z:/p3166/Proteomics/fasta_db/p3166_db4_CopCinAl")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```




## p3166_db1_CopCin



### Create forward db


```{r}
library(prozor)
databasedirectory <- ("D:/TEMP/fgcz_databases/fgcz_349741_A_municiniphila")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annotation <- readLines(file.path(databasedirectory,annot))

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep = ""))
writeFasta(resDB, file=xx)

```


### CREATING DECOY DB


```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot=annotation)
resDBDecoy <- resDBDecoy[!duplicated(names(resDBDecoy))]
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
xx
writeFasta(resDBDecoy, file=xx)

```


## p3273


### Create forward db


```{r}
library(prozor)
databasedirectory <- ("D:/Dropbox/DataAnalysis/p3273_Manuela/data/p3273_db1_Human_GFP")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annotation <- readLines(file.path(databasedirectory,annot))

resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta2019(), annot=annotation, revLab = NULL)
length(resDB)
resDB <- resDB[!duplicated(names(resDB))]
length(resDB)

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
writeFasta(resDB, file=xx)

```


### CREATING DECOY DB


```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta2019(), annot=annotation)
resDBDecoy <- resDBDecoy[!duplicated(names(resDBDecoy))]
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist(strsplit(dbname,"_"))
dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep=""))
xx
writeFasta(resDBDecoy, file=xx)

```


## p2799_db9


### Create forward db

```{r}
library(prozor)
databasedirectory <- ("Z:/p2799/Proteomics/fasta_db/p2799_db9_Planktothrix/")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory,fasta)
files1

annot <- grep("annotation",dir(databasedirectory), value=TRUE)
annot
annotation <- readLines(file.path(databasedirectory,annot))
annotation

resDB <- createDecoyDB(files1, useContaminants = loadContaminantsFasta(), annot = annotation, revLab = NULL)
resDB <- resDB[!duplicated(names(resDB))]

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep = ""))
writeFasta(resDB, file=xx)

```


### CREATING DECOY DB


```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(),
                            annot = annotation)
resDBDecoy <- resDBDecoy[!duplicated(names(resDBDecoy))]
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

dbname_decoy <- unlist( strsplit(dbname,"_") )
dbname_decoy <- paste(c(dbname_decoy[1], "d", dbname_decoy[2:length(dbname_decoy)]), collapse = "_")

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep = ""))

writeFasta(resDBDecoy, file = xx)

```




## p65_Human_Covid 


### Create forward db

```{r}
library(prozor)
databasedirectory <- ("c:/Users/wewol/p65/fgcz_9606_SARS_CoV_reviewed_cnl/")
dir.exists(databasedirectory)

dbname <- basename(databasedirectory)

fasta <- grep("fasta", dir(databasedirectory),value = TRUE)
files1 <- file.path(databasedirectory, fasta)

annot <- grep("annotation",dir(databasedirectory), value = TRUE)
annotation <- readLines(file.path(databasedirectory,annot))


resDB <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(), annot = annotation, revLab = NULL)
resDB <- resDB[!duplicated(names(resDB))]

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep = ""))
print(xx)
writeFasta(resDB, file = xx)

```


### CREATING DECOY DB


```{r}

resDBDecoy <- createDecoyDB(files1,useContaminants = loadContaminantsFasta(),
                            annot = annotation)
resDBDecoy <- resDBDecoy[!duplicated(names(resDBDecoy))]
sum(duplicated(names(resDBDecoy)))
sum(duplicated(resDBDecoy))
length(resDBDecoy)

#dbname_decoy <- unlist(strsplit(dbname,"_"))
#dbname_decoy <- paste(c(dbname_decoy[1],"d",dbname_decoy[2:length(dbname_decoy)]),collapse="_")
dbname_decoy <- paste0(dbname,"_d")

dirname(databasedirectory)
xx <- file.path(dirname(databasedirectory), paste(dbname_decoy,"_",format(Sys.time(), "%Y%m%d"),".fasta" ,sep = ""))

writeFasta(resDBDecoy, file = xx)

```



## p3562_Anabaena_PCC_7120 


### Create forward db

```{r}
library(prozor)
library(seqinr)
databasedirectory <- "C:/Users/wewol/Dropbox/DataAnalysis/p3562/fasta_db/p3562_Anabaena_PCC_7120/"
source("R/create_fgcz_fasta_db.R")
resDB <- create_fgcz_fasta_db(databasedirectory, revLab = NULL)
cat(resDB$summary)

```

### CREATING DECOY DB

```{r}
resDB <- create_fgcz_fasta_db(databasedirectory)
cat(resDB$summary)
```

## fgcz_83332_MYCTU 


```{r}
library(prozor)

databasedirectory <- "C:/Users/wewol/Dropbox/DataAnalysis/p65/fgcz_83332_MYCTU/"

resDB <- create_fgcz_fasta_db(databasedirectory)
cat(resDB$summary)
print(resDB$mcall)

resDB <- create_fgcz_fasta_db(databasedirectory, revLab = NULL)
resDB$filepath
library(ssh)

session <- ssh_connect("wolski@fgcz-r-021.uzh.ch")
file.exists(resDB$filepath)
scp_upload(session, resDB$filepath, to = "/srv/www/htdocs/FASTA")
ssh_disconnect(session)

#install.packages("reticulate")


library(reticulate)
use_python("c:/Program Files/Python38")
bfabricpy <- import("bfabric.scripts.bfabric_save_fasta")
bfabricpy$save_fasta

```



## fgcz_Chlorella


```{r}
library(prozor)
databasedirectory <- "C:/Users/wewol/Dropbox/DataAnalysis/p65/fgcz_3071_Chlorella/"
resDB <- create_fgcz_fasta_db(databasedirectory)

cat(resDB$summary)
resDB$filepath


library(ssh)
session <- ssh_connect("wolski@fgcz-r-021.uzh.ch")
file.exists(resDB$filepath)
scp_upload(session, resDB$filepath, to = "/srv/www/htdocs/FASTA")
#ssh_disconnect(session)


resDB <- create_fgcz_fasta_db(databasedirectory, revLab = NULL)
session <- ssh_connect("wolski@fgcz-r-021.uzh.ch")
file.exists(resDB$filepath)
scp_upload(session, resDB$filepath, to = "/srv/www/htdocs/FASTA")
ssh_disconnect(session)


# TBD.

summary <- paste( resDB$summary , collapse = "" )
library(reticulate)
use_python("c:/Program Files/Python38")
bfabricpy <- import("bfabric.scripts.bfabric_save_fasta")
bfabricpy$save_fasta(projectid = 65,
                     fasta_file = resDB$filepath,
                     description_resource =  paste(resDB$summary, collapse = ""),
                     description_workunit = paste(resDB$summary, collapse = "")
                     )


resDB <- create_fgcz_fasta_db(databasedirectory, revLab = NULL)

```





## fgcz_Chlorella

```{r}

```


```{r}

library(prozor)
databasedirectory <- "C:/Users/wewol/Dropbox/DataAnalysis/p65/p3553_935293_Yersinia_entomophaga/"
resDBRev <- create_fgcz_fasta_db(databasedirectory,useContaminants = loadContaminantsFasta2019())
cat(resDBRev$summary)
scp_copy(resDBRev$filepath)
bfabric_save_fasta(project_id = 3553, resDBRev)

resDB <- create_fgcz_fasta_db(databasedirectory, revLab = NULL)
cat(resDB$summary)



library(ssh)

file.exists(resDB$filepath)
scp_upload(session, resDB$filepath, to = "/srv/www/htdocs/FASTA")
ssh_disconnect(session)


# TBD.

summary <- paste( resDB$summary , collapse = "" )
cat(summary)



resDB <- create_fgcz_fasta_db(databasedirectory, revLab = NULL)

```

# 3511

```{r}
library(prozor)
databasedirectory <- "z:/p3511/Proteomics/fasta_db/p3511_db1_Araport_Fusarium/"
#debug(create_fgcz_fasta_db)
resDBRev <- create_fgcz_fasta_db(databasedirectory,useContaminants = loadContaminantsFasta2019(), revLab = NULL)

cat(resDBRev$summary)
#scp_copy(resDBRev$filepath)
bfabric_save_fasta(project_id = 3511, resDBRev$filepath, resDBRev$summary, python_path = "c:/Python37")

python_path = "c:/Python37"
filepath = resDBRev$filepath
summary = resDBRev$summary
project_id = 3511

reticulate::use_python(python_path)
bfabricpy <- reticulate::import("bfabric.scripts.bfabric_save_fasta")
bfabricpy$save_fasta(projectid = project_id, fasta_file = filepath, description_resource = paste(summary, collapse=""), description_workunit = paste(summary, collapse=""))

```



