-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathREADME.Rmd
177 lines (123 loc) · 4.1 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
---
output:
github_document:
html_preview: false
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
[](https://travis-ci.org/gschofl/biofiles)
[](https://ci.appveyor.com/project/gschofl/biofiles)
[](http://cran.r-project.org/web/packages/biofiles/index.html)
[](https://cran.r-project.org/package=biofiles)
# biofiles - an interface to GenBank/GenPept files in R
biofiles provides interfacing to GenBank/GenPept or Embl flat
file records. It includes utilities for reading and writing GenBank
files, and methods for interacting with annotation and sequence data.
## Installation
Install the latest stable release of the `biofiles` package from CRAN:
```{r cran-installation, eval = FALSE}
install.packages("biofiles")
```
Install the development version from `github` using the `devtools` package.
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("gschofl/biofiles")
```
## Basic functionality
Let's download a small bacterial genome, _Chlamydophila psittaci_ DC15
(GenBank acc. CP002806; GI 334693792) from NCBI.
```{r chunk1}
# install.packages("reutils")
gb_file <- reutils::efetch("CP002806", "nuccore", rettype = "gbwithparts", retmode = "text")
gb_file
```
Next, we parse the `efetch` object into a `gbRecord` instance.
```{r chunk2}
rec <- biofiles::gbRecord(gb_file)
rec
```
The `summary` function provides an overview over the object:
```{r chunk3}
biofiles::summary(rec)
```
Various getter methods provide access to the data contained in a GenBank record;
for instance:
```{r chunk4}
biofiles::getAccession(rec)
```
```{r chunk5}
biofiles::getGeneID(rec)
```
```{r chunk6}
biofiles::getDefinition(rec)
```
```{r chunk7}
biofiles::getOrganism(rec)
```
```{r chunk8}
biofiles::getSequence(rec)
```
```{r chunk9}
biofiles::getReference(rec)
```
The function `uniqueQualifs()` provides an overview over the feature qualifiers used
in a record:
```{r chunk10}
biofiles::uniqueQualifs(rec)
```
### Genbank Features
The important part of a GenBank record will generally be the list of annotions
or features.
We can access the `gbFeatureList` of a `gbRecord` using `getFeatures()` or `ft()`:
```{r chunk11}
f <- biofiles::ft(rec)
f
```
We can extract features either by numeric subsetting:
```{r chunk12}
f[[1]]
```
or we can subset by feature key:
```{r chunk13}
f["CDS"]
```
A more versatile method to narrow down the list of features of interest is the
function `filter()`.
For instance, we can filter for all coding sequences (CDS) with the
annotation "hypothetical" in the product qualifiers:
```{r chunk14}
hypo <- biofiles::filter(rec, key = "CDS", product = "hypothetical")
biofiles::summary(hypo)
```
or we can filter for all elongation factors,
```{r chunk15}
elong <- biofiles::filter(rec, key = "CDS", product = "elongation factor")
biofiles::summary(elong)
```
now let's extract the sequence for all elongation factors, and using the tools
from the `Biostrings` packages, translate them into protein sequences. Note, that
in order to do so, we first get the `gbFeatureTable` from the `gbRecord`, as otherwise
we'd just extract the complete sequence associated with the GenBank record.
```{r chunk16}
dna <- biofiles::getSequence(biofiles::ft(elong))
dna
```
```{r chunk17}
str <- biofiles::strand(elong)
dna_revcomp <- c(Biostrings::reverseComplement(dna[str == -1]), dna[str == 1])
aa <- Biostrings::translate(dna_revcomp)
names(aa) <- names(dna_revcomp)
aa
```
We can use the `ranges()` method to extract `GRanges` objects defined in the
Bioconductor package `GenomicRanges`:
```{r chunk18}
elong_ranges <- biofiles::ranges(elong, include = c("locus_tag", "protein_id", "product"))
elong_ranges
```