Can You Download A Sequence From Genbank By Species Name In R
I realized the other mean solar day that using ape::read.Genbank() does non piece of work for downloading protein sequences in batch from Genbank.
This mail service volition cover how to utilize the rentrez package to download protein sequences from GenBank while also recapping how read.Genbank() can do a similar thing for a set of Deoxyribonucleic acid seqs. I'll actually start with the Deoxyribonucleic acid example because I doubtable it's the more common use example.
Both pipelines generate FASTA files, which tin and then be used for multiple sequence alignment etc etc.
Get the ape and rentrez packages
We'll be using functions from ape and rentrez, so we'll kickoff get these packages and load them.
As explained here the code below first checks to see if you take these packages. If you do, they're simply loaded. If non, the missing packages are installed from CRAN and and then loaded.
# Showtime load | install&load packages we'll need packages = c ( "ape" , "rentrez" ) packet.bank check <- lapply ( packages , FUN = office ( ten ) { if ( ! require ( x , character.simply = TRUE )) { install.packages ( ten , dependencies = Truthful ) library ( x , character.only = True ) } } ) ## Loading required package: ape ## Loading required package: rentrez Downloading Dna sequences from GenBank
OK, DNA sequences first. We'll apply the list of COI accession IDs from Baliga and Constabulary (2016) as an example.
You shouldn't demand to run library(ape) later on running the chunk to a higher place, simply please make sure y'all have ape loaded or the stuff that follows won't work.
## import the sequence list from a CSV file ## NO "strings as factor" coi <- read.table ( "https://raw.githubusercontent.com/vbaliga/vbaliga.github.io/principal/images/2019-eleven-26/COI_BaligaLaw2016.csv" , quote = "\"" , stringsAsFactors = Fake ) ## catechumen to character lists as.list ( coi ) $ V1 -> coi_list ## see how it's formatted str ( coi_list ) ## chr [i:282] "AY662765" "KF434769.one" "GQ341585.1" "EF609278.1" ... At that place are 282 GenBank accession IDs in the file, each of which corresponds to a COI sequence from a species of wrasse or parrotfish or outgroup taxon. These accession IDs were determined beforehand equally existence appropriate for the study.
The code is a chip old-school; at that place's a more than elegant way to do import a character list via tidyverse, merely I'm opting to keep it this way to reduce the number of dependencies in this post.
Anyway, we're gear up for ape::read.Genbank():
## employ read.GenBank to learn the sequences coi_gen <- read.GenBank ( coi_list , species.names = Truthful ) ## but notation that these are named according to the sequence ID coi_gen ## 282 Deoxyribonucleic acid sequences in binary format stored in a list. ## ## Mean sequence length: 647.986 ## Shortest sequence: 526 ## Longest sequence: 712 ## ## Labels: ## AY662765 ## KF434769.1 ## GQ341585.i ## EF609278.1 ## AY662764 ## DQ119198 ## ... ## ## Base limerick: ## a c thou t ## 0.229 0.291 0.187 0.292 ## (Total: 182.73 kb) And so the read.Genbank() part is super handy for automating the download and organization of sequences, but annotation from the code higher up that the names given to the sequences follow the GenBank accession IDs.
In the the cake below, we'll extract the species' names and use them instead.
## now use species names, every bit found inside the GenBank entry names_coi <- data.frame ( species = attr ( coi_gen , "species" ), accs = names ( coi_gen )) ## have a look at how this is organized head ( names_coi ) ## species accs ## 1 Abudefduf_saxatilis AY662765 ## 2 Abudefduf_vaigiensis KF434769.1 ## three Acantholabrus_palloni GQ341585.1 ## 4 Achoerodus_viridis EF609278.1 ## 5 Amblyglyphidodon_leucogaster AY662764 ## 6 Amphilophus_citrinellus DQ119198 ## add these names names ( coi_gen ) <- attr ( coi_gen , "species" ) ## take a acme at the names to verify coi_gen ## 282 Deoxyribonucleic acid sequences in binary format stored in a list. ## ## Hateful sequence length: 647.986 ## Shortest sequence: 526 ## Longest sequence: 712 ## ## Labels: ## Abudefduf_saxatilis ## Abudefduf_vaigiensis ## Acantholabrus_palloni ## Achoerodus_viridis ## Amblyglyphidodon_leucogaster ## Amphilophus_citrinellus ## ... ## ## Base composition: ## a c m t ## 0.229 0.291 0.187 0.292 ## (Full: 182.73 kb) Noice!
We're now ready for export, which we tin do via ape::write.deoxyribonucleic acid().
## export the file to your working directory ## commenting out the line below so this mail service knits properly ## be certain to un-comment it so it actually runs: #write.dna(coi_gen, "my_COI_seqs.fasta", format = "fasta") You lot should at present accept an exported .fasta file that is set up for alignment or other analyses.
If you import it into a multiple sequence alignment program like MEGA, you should see something similar this:
Using your own accession IDs
If you want to switch to your ain set of accession IDs, yous can supply your own .csv file or a character vector.
Here's some examples with a character vector:
## brand a character vector of accession IDs my_coi_IDs <- c ( "AY662765" , "KF434769.1" , "GQ341585.1" , "EF609278.1" , "AY662764" ) ## i way #coi_gen_chars <- read.GenBank(my_coi_IDs, species.names = True) #coi_gen_chars ## or merely dump the character vector right in to read.GenBank() coi_gen_chars_two <- read.GenBank ( c ( "AY662765" , "KF434769.one" , "GQ341585.1" , "EF609278.one" , "AY662764" ), species.names = TRUE ) coi_gen_chars_two ## 5 DNA sequences in binary format stored in a list. ## ## Mean sequence length: 624.4 ## Shortest sequence: 587 ## Longest sequence: 678 ## ## Labels: ## AY662765 ## KF434769.1 ## GQ341585.1 ## EF609278.1 ## AY662764 ## ## Base of operations limerick: ## a c g t ## 0.233 0.291 0.184 0.293 ## (Total: three.12 kb) Downloading protein sequences from GenBank
We'll exercise a similar song and dance here, but annotation that we can't utilize read.Genbank() for this use case.
Instead, rentrez::entrez_fetch() does the fob. Once more, please notation that if you ran the showtime clamper in this post successfully, you shouldn't demand to run library(rentrez). But practise make certain that package is loaded!
I don't really piece of work with proteins myself, so I'm going to catch a couple random accretion IDs simply for sake of example.
We'll jump right into it:
## make a graphic symbol vector of accretion IDs my_protein_IDs <- c ( "AAF73255.ane" , "P04573.three" , "ACF39884.one" ) ## OR if you want to import a listing of accession IDs from a CSV # my_protein_IDs <- read.table("./my_protein_accessions.csv", # quote="\"", stringsAsFactors=FALSE) # ## and convert to character listing # as.listing(my_protein_IDs)$V1 -> prot_list ## use entrez_fetch() to become the protein FASTAs ## set `db = "poly peptide"` to specify the database type every bit poly peptide prot_gen <- entrez_fetch ( id = my_protein_IDs , db = "protein" , rettype = "fasta" ) ## the resultant object isn't as corking as what read.GenBank() constructs ## information technology'south basically just a grapheme. meh. str ( prot_gen ) ## chr ">AAF73255.ane alcohol dehydrogenase class three [Branchiostoma lanceolatum]\nMAETAGKPITCRAAVAWEAKKPLVIETIEVAPPRAHEVRI"| __truncated__ ## to write to file: #write(prot_gen, file="my_proteins.fasta") There you go! I'k not as big a fan of rentrez::entrez_fetch() as I am of ape::read.GenBank because of how the objects are handled, but the power to grab sequences from nearly any of the GenBank databases is handy.
That'due south all!
🐢
DOWNLOAD HERE
Posted by: wolfjoically.blogspot.com

0 Komentar
Publicar un comentario