Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scripts
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
UNLOCK
scripts
Commits
eb7ced6e
Commit
eb7ced6e
authored
3 years ago
by
Bart
Browse files
Options
Downloads
Patches
Plain Diff
general statistics about read mapping of bins and the assembly
parent
db081f1f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
metagenomics/assembly_bins_readstats.py
+78
-0
78 additions, 0 deletions
metagenomics/assembly_bins_readstats.py
with
78 additions
and
0 deletions
metagenomics/assembly_bins_readstats.py
0 → 100755
+
78
−
0
View file @
eb7ced6e
#!/bin/python3
'''
Generates a table of the metagenomic assembly mapping and binning statistics:
input:
1. binContigsFile, format: bin_name<tab>contig
2. samtools idxstats output file
3. BBMap mapping stats stdErr file
4. An identifier (string)
standard out:
ID
Reads
Mapped reads %
Assembly size
Bins
Total bin size
Binned %
Reads mapped to bins %
'''
import
os
import
sys
import
re
binContigsFile
=
sys
.
argv
[
1
]
samstatsFile
=
sys
.
argv
[
2
]
bbmap
=
sys
.
argv
[
3
]
identifier
=
sys
.
argv
[
4
]
# Get total reads from BBmap stats
for
line
in
open
(
bbmap
,
"
r
"
).
readlines
():
hit
=
re
.
search
(
"
^Reads:
"
,
line
)
if
hit
:
total_reads
=
int
(
line
.
strip
().
split
()[
-
1
])
# Get totals bins and all contigs with in bin from binContigsFile
binContigs
=
set
()
bins
=
0
prev_bin
=
""
for
line
in
open
(
binContigsFile
).
readlines
():
if
line
.
split
()[
0
]
!=
prev_bin
:
bins
+=
1
binContigs
.
add
(
line
.
strip
().
split
()[
1
])
prev_bin
=
line
.
split
()[
0
]
total_assembly_size
=
0
mapped_reads
=
0
total_bin_size
=
0
mapped_bin_reads
=
0
# Read through the samtools idxstats file
for
line
in
open
(
samstatsFile
,
"
r
"
).
readlines
():
sline
=
line
.
split
()
contig
=
sline
[
0
]
contigLen
=
int
(
sline
[
1
])
contigReads
=
int
(
sline
[
2
])
total_assembly_size
+=
contigLen
mapped_reads
+=
contigReads
if
contig
in
binContigs
:
total_bin_size
+=
contigLen
mapped_bin_reads
+=
contigReads
mapped_reads_perc
=
round
(
mapped_reads
/
total_reads
*
100
,
2
)
mapped_bin_reads_perc
=
round
(
mapped_bin_reads
/
mapped_reads
*
100
,
2
)
binned_perc
=
round
(
total_bin_size
/
total_assembly_size
*
100
,
2
)
print
(
"
ID
"
+
"
\t
"
+
identifier
)
print
(
"
Reads
"
+
"
\t
"
+
str
(
total_reads
))
print
(
"
Mapped reads
"
+
"
\t
"
+
str
(
mapped_reads_perc
)
+
"
%
"
)
print
(
"
Assembly size
"
+
"
\t
"
+
str
(
total_assembly_size
)
+
"
bp
"
)
print
(
"
Bins
"
+
"
\t
"
+
str
(
bins
))
print
(
"
Total bin size
"
+
"
\t
"
+
str
(
total_bin_size
)
+
"
bp
"
)
print
(
"
Binned
"
+
"
\t
"
+
str
(
binned_perc
)
+
"
%
"
)
print
(
"
Reads mapped to bins
"
+
"
\t
"
+
str
(
mapped_bin_reads_perc
)
+
"
%
"
)
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