Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cAmpSeqR
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Simeon Rossmann
cAmpSeqR
Commits
534b0938
Commit
534b0938
authored
1 year ago
by
Simeon
Browse files
Options
Downloads
Patches
Plain Diff
Update variant_classifier.R
parent
7223ad02
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/variant_classifier.R
+37
-21
37 additions, 21 deletions
R/variant_classifier.R
with
37 additions
and
21 deletions
R/variant_classifier.R
+
37
−
21
View file @
534b0938
...
...
@@ -15,26 +15,27 @@ variant_classifier <- function(
seqtab_file
=
file.path
(
path
,
'seqtab_nochim.rds'
),
clustered_sequences
=
myDNAStringSetList
){
# Convert seqtab into long format and calculate relative abundance per sample for each ASV
seqtab_tbl_long
<-
clean_seqtab
(
seqtab_file
,
output
=
FALSE
)
%>%
pivot_longer
(
cols
=
where
(
is.integer
),
names_to
=
'sample'
,
values_to
=
'asv_counts'
)
%>%
group_by
(
sample
)
%>%
mutate
(
sample_count_sum
=
sum
(
asv_counts
))
%>%
ungroup
()
%>%
mutate
(
rel_abundance
=
asv_counts
/
sample_count_sum
)
%>%
dplyr
::
filter
(
sample_count_sum
>
0
)
# Create a table for clustered sequences and filter out clusters with only one sequence
clustab_tbl
<-
cluster_tbl_named
(
clustered_sequences
)
%>%
left_join
(
tibble
(
seqnames
=
unlist
(
map
(
clustered_sequences
,
names
)),
seqs
=
as.character
(
unlist
(
Biostrings
::
DNAStringSetList
(
clustered_sequences
)))),
by
=
'seqnames'
)
%>%
dplyr
::
filter
(
clus_size
>
1
)
# If reference informed, add reference info and name variants
# If reference informed, add reference info and name variants
if
(
reference_informed
){
# Convert seqtab into long format and calculate relative abundance per sample for each ASV
seqtab_tbl_long
<-
clean_seqtab
(
seqtab_file
,
output
=
FALSE
)
%>%
pivot_longer
(
cols
=
where
(
is.integer
),
names_to
=
'sample'
,
values_to
=
'asv_counts'
)
%>%
dplyr
::
filter
(
!
(
ASV
%in%
names
(
refstrings
)))
%>%
group_by
(
sample
)
%>%
mutate
(
sample_count_sum
=
sum
(
asv_counts
))
%>%
ungroup
()
%>%
mutate
(
rel_abundance
=
asv_counts
/
sample_count_sum
)
%>%
dplyr
::
filter
(
sample_count_sum
>
0
)
# Create a table for clustered sequences and filter out clusters with only one sequence
clustab_tbl
<-
cluster_tbl_named
(
clustered_sequences
)
%>%
left_join
(
tibble
(
seqnames
=
unlist
(
map
(
clustered_sequences
,
names
)),
seqs
=
as.character
(
unlist
(
Biostrings
::
DNAStringSetList
(
clustered_sequences
)))),
by
=
'seqnames'
)
%>%
dplyr
::
filter
(
clus_size
>
1
)
%>%
dplyr
::
filter
(
!
(
seqnames
%in%
names
(
refstrings
)))
# Join the clustered sequences table with the long seqtab table by sequence name
master_tbl
<-
left_join
(
clustab_tbl
,
seqtab_tbl_long
,
by
=
'seqs'
)
%>%
dplyr
::
filter
(
seqnames
!=
clus_name
)
...
...
@@ -66,6 +67,23 @@ variant_classifier <- function(
# If not reference informed, join the clustered sequences table with the long seqtab table and add "x" to a new column sim_to_ref
if
(
!
reference_informed
){
# Convert seqtab into long format and calculate relative abundance per sample for each ASV
seqtab_tbl_long
<-
clean_seqtab
(
seqtab_file
,
output
=
FALSE
)
%>%
pivot_longer
(
cols
=
where
(
is.integer
),
names_to
=
'sample'
,
values_to
=
'asv_counts'
)
%>%
group_by
(
sample
)
%>%
mutate
(
sample_count_sum
=
sum
(
asv_counts
))
%>%
ungroup
()
%>%
mutate
(
rel_abundance
=
asv_counts
/
sample_count_sum
)
%>%
dplyr
::
filter
(
sample_count_sum
>
0
)
# Create a table for clustered sequences and filter out clusters with only one sequence
clustab_tbl
<-
cluster_tbl_named
(
clustered_sequences
)
%>%
left_join
(
tibble
(
seqnames
=
unlist
(
map
(
clustered_sequences
,
names
)),
seqs
=
as.character
(
unlist
(
Biostrings
::
DNAStringSetList
(
clustered_sequences
)))),
by
=
'seqnames'
)
%>%
dplyr
::
filter
(
clus_size
>
1
)
master_tbl
<-
left_join
(
clustab_tbl
,
seqtab_tbl_long
,
by
=
'seqs'
)
%>%
# Add sequence variants and major variant information to the table and group by cluster name
mutate
(
seq_var
=
paste0
(
'Sequence variant '
,
num
-2
))
%>%
...
...
@@ -92,8 +110,6 @@ variant_classifier <- function(
select
(
sample
,
ASV
)
%>%
group_by
(
sample
)
%>%
# Concatenate the top 2 most abundant sequences per sample into a single string - "profile"
mutate
(
profile
=
paste0
(
ASV
,
collapse
=
''
))
%>%
# Remove duplicates
ungroup
()
%>%
select
(
-
ASV
)
%>%
unique
()
...
...
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