Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genotoul-bioinfo
metagWGS
Commits
52f47579
Commit
52f47579
authored
Jun 03, 2021
by
Celine Noirot
Browse files
Add rename depth column
parent
b07b2d1f
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/quantification_by_contig_lineage.py
View file @
52f47579
...
...
@@ -27,6 +27,7 @@ try:
import
re
import
sys
import
pandas
as
pd
import
os
from
datetime
import
datetime
except
ImportError
as
error
:
print
(
error
)
...
...
@@ -58,26 +59,27 @@ with open(args.list_of_input_files) as finput_list:
# Merge results for all samples by lineage.
for
(
sample_idx
,
sample_path
)
in
enumerate
(
sample_files
):
print
(
sample_
idx
)
print
(
"Read "
+
sample_
path
)
if
(
sample_idx
==
0
):
merge
=
pd
.
read_csv
(
sample_path
,
delimiter
=
'
\t
'
,
dtype
=
str
)
sample_name
=
sample_path
if
(
'consensus_tax_id'
in
merge
.
columns
):
merge
.
drop
(
'consensus_tax_id'
,
inplace
=
True
,
axis
=
1
)
sample_name
=
os
.
path
.
splitext
(
sample_path
)[
0
]
else
:
sample_results
=
pd
.
read_csv
(
sample_path
,
delimiter
=
'
\t
'
,
dtype
=
str
)
merge
=
pd
.
merge
(
merge
,
sample_results
,
left_on
=
[
"tax_id_by_level"
,
"lineage_by_level"
],
right_on
=
[
"tax_id_by_level"
,
"lineage_by_level"
],
how
=
'outer'
,
suffixes
=
(
'_'
+
sample_name
,
''
))
sample_name
=
sample_path
if
(
'consensus_tax_id'
in
merge
.
columns
):
merge
.
drop
(
'consensus_tax_id'
,
inplace
=
True
,
axis
=
1
)
print
(
merge
.
head
())
sample_name
=
os
.
path
.
splitext
(
sample_path
)[
0
]
if
(
'consensus_tax_id'
in
merge
.
columns
):
merge
.
drop
(
'consensus_tax_id'
,
inplace
=
True
,
axis
=
1
)
# Rename columns corresponding to the last sample file.
sample_name
=
sample_path
sample_name
=
os
.
path
.
splitext
(
sample_path
)[
0
]
merge
.
rename
(
columns
=
{
'name_contigs'
:
'name_contigs_'
+
sample_name
,
\
'nb_contigs'
:
'nb_contigs_'
+
sample_name
,
\
'nb_reads'
:
'nb_reads_'
+
sample_name
},
inplace
=
True
)
'nb_reads'
:
'nb_reads_'
+
sample_name
,
\
'depth'
:
'depth_'
+
sample_name
},
inplace
=
True
)
# Fill the NaN by 0.
merge
.
fillna
(
0
,
inplace
=
True
)
print
(
"Write "
+
args
.
output_file
)
# Write merge data frame in output file.
merge
.
to_csv
(
args
.
output_file
,
sep
=
"
\t
"
,
index
=
False
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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