Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
metastatistics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joris van Steenbrugge
metastatistics
Commits
0c514631
Commit
0c514631
authored
5 years ago
by
Joris van Steenbrugge
Browse files
Options
Downloads
Patches
Plain Diff
updates
parent
f6711dfd
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
DESCRIPTION
+13
-0
13 additions, 0 deletions
DESCRIPTION
NAMESPACE
+9
-0
9 additions, 0 deletions
NAMESPACE
R/Filter.R
+100
-0
100 additions, 0 deletions
R/Filter.R
R/Satistics.R
+27
-0
27 additions, 0 deletions
R/Satistics.R
with
149 additions
and
0 deletions
DESCRIPTION
0 → 100644
+
13
−
0
View file @
0c514631
Package: metastatistics
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <yourself@somewhere.net>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
Imports: vegan, ggplot2, magrittr, ggalt
This diff is collapsed.
Click to expand it.
NAMESPACE
0 → 100644
+
9
−
0
View file @
0c514631
# Generated by roxygen2: do not edit by hand
export(Filter_abundance)
export(Filter_goods)
export(Filter_kingdom)
export(Generate_tree)
export(Goods_cov)
export(PCOA)
export(Remove_kingdom)
This diff is collapsed.
Click to expand it.
R/Filter.R
0 → 100644
+
100
−
0
View file @
0c514631
#' @export
Filter_goods
<-
function
(
data_raw
,
cutoff
=
0.9
){
# Goods
cov_matrix
<-
Goods_cov
(
data_raw
)
good_samples
<-
cov_matrix
[
cov_matrix
[,
"Good's coverage"
]
%>%
as.numeric
%>%
`>=`
(
cutoff
)
%>%
which
,
1
]
bad_samples
<-
colnames
(
data_raw
@
otu_table
@
.Data
)[
-
which
(
colnames
(
data_raw
@
otu_table
@
.Data
)
%in%
good_samples
)]
data_raw
@
otu_table
@
.Data
<-
data_raw
@
otu_table
@
.Data
[,
which
(
colnames
(
data_raw
@
otu_table
@
.Data
)
%in%
good_samples
)]
return
(
data_raw
)
}
#' @export
Filter_abundance
<-
function
(
data_raw
,
cutoff
=
0.005
){
#Abundance
total_abundance
<-
data_raw
@
otu_table
@
.Data
%>%
sum
filter_low_abundance
<-
function
(
otu
,
threshold
=
0.005
){
rsum
<-
sum
(
otu
)
perc
<-
rsum
/
total_abundance
*
100
if
(
perc
<
threshold
){
return
(
F
)
}
else
{
return
(
T
)
}
}
abundances
<-
apply
(
data_raw
@
otu_table
@
.Data
,
1
,
filter_low_abundance
)
old_table
<-
data_raw
@
otu_table
@
.Data
keep
<-
rownames
(
old_table
[
abundances
,])
data_new
<-
prune_taxa
(
keep
,
data_raw
)
return
(
data_new
)
}
#' @export
Filter_kingdom
<-
function
(
data_raw
,
col_name
,
desired_kingdom
){
good_kingdoms
<-
apply
(
data_raw
@
tax_table
@
.Data
,
1
,
function
(
otu
){
if
(
is.na
(
otu
[
col_name
])){
return
(
F
)
}
if
(
otu
[
col_name
]
==
desired_kingdom
){
return
(
T
)
}
else
{
return
(
F
)
}
})
only_good
<-
good_kingdoms
[
which
(
good_kingdoms
==
T
)]
%>%
names
available_good
<-
only_good
[
which
(
only_good
%in%
rownames
(
data_raw
@
otu_table
@
.Data
))]
data_raw
@
otu_table
@
.Data
<-
data_raw
@
otu_table
@
.Data
[
available_good
,]
return
(
data_raw
)
}
#' @export
Remove_kingdom
<-
function
(
data_raw
,
col_name
,
undesired_kingdom
){
keep
<-
which
(
data_raw
@
tax_table
@
.Data
[,
col_name
]
!=
undesired_kingdom
)
%>%
names
return
(
prune_taxa
(
keep
,
data_raw
))
}
#' @export
Generate_tree
<-
function
(
phy_obj
,
otu_fasta
,
n_proc
=
4
){
library
(
seqinr
)
library
(
DECIPHER
)
library
(
phangorn
)
if
(
missing
(
otu_fasta
)){
print
(
"True"
)
if
(
phy_obj
@
otu_table
@
taxa_are_rows
){
seqs_vec
<-
rownames
(
phy_obj
@
otu_table
@
.Data
)
}
else
{
seqs_vec
<-
colnames
(
phy_obj
@
otu_table
@
.Data
)
}
names
(
seqs_vec
)
<-
seqs_vec
}
else
{
seqs
<-
read.fasta
(
otu_fasta
)
seqs_vec
<-
sapply
(
names
(
seqs
),
function
(
otu
){
s
<-
seqs
[[
otu
]]
paste0
(
s
,
collapse
=
''
)
})
}
alignment
<-
DECIPHER
::
AlignSeqs
(
DNAStringSet
(
seqs_vec
),
anchor
=
NA
,
processors
=
n_proc
)
phang.align
<-
phyDat
(
as
(
alignment
,
"matrix"
),
type
=
"DNA"
)
dm
<-
dist.ml
(
phang.align
)
treeNJ
<-
NJ
(
dm
)
# Note, tip order != sequence order
fit
=
pml
(
treeNJ
,
data
=
phang.align
)
itGTR
<-
update
(
fit
,
k
=
4
,
inv
=
0.2
)
fitGTR
<-
optim.pml
(
fitGTR
,
model
=
"GTR"
,
optInv
=
TRUE
,
optGamma
=
TRUE
,
rearrangement
=
"stochastic"
,
control
=
pml.control
(
trace
=
0
))
phy_obj
@
phy_tree
<-
phy_tree
(
fitGTR
$
tree
)
return
(
phy_obj
)
}
This diff is collapsed.
Click to expand it.
R/Satistics.R
0 → 100644
+
27
−
0
View file @
0c514631
#' @export
Goods_cov
<-
function
(
data_raw
){
cov_matrix
<-
matrix
(
ncol
=
2
,
nrow
=
0
)
for
(
sample
in
colnames
(
data_raw
@
otu_table
@
.Data
)){
sample_col
<-
data_raw
@
otu_table
@
.Data
[,
sample
]
total_individuals
<-
sample_col
%>%
sum
total_singletons
<-
sample_col
[
which
(
sample_col
==
1
)]
%>%
sum
goods_cov
<-
1
-
(
total_singletons
/
total_individuals
)
cov_matrix
<-
rbind
(
cov_matrix
,
c
(
sample
,
goods_cov
))
}
colnames
(
cov_matrix
)
<-
c
(
"Sample"
,
"Good's coverage"
)
return
(
cov_matrix
)
}
#' @export
PCOA
<-
function
(
data_phylo
,
title
,
color
,
shape
){
ordination
<-
ordinate
(
data_phylo
,
method
=
"PCoA"
,
distance
=
"bray"
)
if
(
missing
(
shape
)){
return
(
plot_ordination
(
data_phylo
,
ordination
,
color
=
color
,
title
=
title
)
+
stat_ellipse
())
}
else
{
return
(
plot_ordination
(
data_phylo
,
ordination
,
color
=
color
,
shape
=
shape
,
title
=
title
)
+
stat_ellipse
())
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment