Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
migale
affiliationExplorer
Commits
d66c9e1a
Commit
d66c9e1a
authored
Jan 17, 2020
by
mahendra-mariadassou
Browse files
Fix typos and add find_level to find ambiguous taxonoic ranks
parent
a9c580a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/utils.R
View file @
d66c9e1a
## Template for reading biom file
read_frogs_biom
<-
function
(
biomfile
)
{
read_frogs_biom
<-
function
(
biom
_
file
)
{
phyloseq.extended
::
import_frogs
(
biom_file
)
}
...
...
@@ -28,7 +28,7 @@ create_otu_dictionary <- function(physeq) {
dplyr
::
arrange
(
desc
(
abundance
))
## If all taxa names are long, sequences are likely to have been processed by DADA
## Move OTU names to sequence column and rename OTU with shorter names
if
(
long_taxa_names
(
otu_dictionary
$
OTU
))
{
if
(
long_taxa_names
(
otu_dictionary
$
sequence
))
{
otu_dictionary
<-
otu_dictionary
%>%
dplyr
::
mutate
(
OTU
=
paste0
(
"ASV"
,
1
:
n
()))
}
else
{
otu_dictionary
<-
otu_dictionary
%>%
dplyr
::
mutate
(
OTU
=
sequence
)
...
...
@@ -43,10 +43,10 @@ sanitize_physeq_and_affi <- function(physeq, affi) {
## Add abundance information to affiliation table
affi
<-
inner_join
(
otu_dictionary
,
affi
,
by
=
c
(
"sequence"
=
"#observation_name"
))
%>%
tidyr
::
separate
(
blast_taxonomy
,
into
=
rank_names
(
physeq
),
sep
=
";"
)
tidyr
::
separate
(
blast_taxonomy
,
into
=
phyloseq
::
rank_names
(
physeq
),
sep
=
";"
)
## Rename taxa in physeq object
taxa_names
(
physeq
)
<-
sequence_to_asv
[
taxa_names
(
physeq
)]
%>%
unname
()
phyloseq
::
taxa_names
(
physeq
)
<-
old_to_new
[
phyloseq
::
taxa_names
(
physeq
)]
%>%
unname
()
## Remove previously curated taxa from affi
affi
<-
affi
%>%
filter
(
OTU
%in%
ambiguous_taxa
(
physeq
))
...
...
@@ -69,3 +69,13 @@ extract_affiliation <- function(affi, otu) {
dplyr
::
filter
(
OTU
==
otu
)
%>%
dplyr
::
select
(
Kingdom
:
Species
)
}
## Find level of ambiguity
find_level
<-
function
(
data
)
{
not_consistent
<-
function
(
x
)
{
!
all
(
x
==
x
[
1
])
}
rank_names
<-
c
(
"Kingdom"
,
"Phylum"
,
"Class"
,
"Order"
,
"Family"
,
"Genus"
,
"Species"
)
for
(
rank
in
rank_names
)
{
rank_content
<-
data
[[
rank
]]
if
(
not_consistent
(
rank_content
))
return
(
rank
)
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment