Commit 52f47579 authored by Celine Noirot's avatar Celine Noirot
Browse files

Add rename depth column

parent b07b2d1f
......@@ -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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment