Skip to content

Commit

Permalink
minor changes in excel_generator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Shettland authored and saramonzon committed Feb 1, 2024
1 parent 43d2ac5 commit 0e2c9af
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions bu_isciii/templates/viralrecon/RESULTS/excel_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import List, Dict

# conda activate viralrecon_report
"""Usage: python excel_generator.py ./reference.tmp"""
"""Single csv to excel Usage: python excel_generator.py -s csv_file.csv"""
"""Standard usage: python excel_generator.py -r ./reference.tmp"""
"""Single csv to excel usage: python excel_generator.py -s csv_file.csv"""
parser = argparse.ArgumentParser(
description="Generate excel files from viralrecon results"
)
Expand All @@ -22,17 +22,8 @@
default="",
help="Transform a single csv file to excel format. Omit rest of processes",
)
parser.add_argument(
"-l",
"--merge_lineage_files",
type=str,
default="",
help="Merge pangolin and nextclade lineage tables",
)

args = parser.parse_args()


def concat_tables_and_write(csvs_in_folder: List[str], merged_csv_name: str):
"""Concatenate any tables that share the same header"""
if len(csvs_in_folder) == 0:
Expand Down Expand Up @@ -112,7 +103,7 @@ def excel_generator(csv_files: List[str]):
except pd.errors.EmptyDataError:
print("Could not parse table from ", str(file))
continue
table.drop(["index"], axis=1, errors="ignore")
table = table.drop(["index"], axis=1, errors="ignore")
table.to_excel(output_name, index=False)
return

Expand Down Expand Up @@ -143,7 +134,7 @@ def main(args):
ref: str("ref_samples/samples_" + ref + ".tmp") for ref in references
}

if args.merge_lineage_files:
if len(references) > 1:
# Merge pangolin and nextclade csv files separatedly and create excel files for them
merge_lineage_tables(reference_folders, samples_ref_files)
for reference, folder in reference_folders.items():
Expand All @@ -162,7 +153,8 @@ def main(args):
csvs_in_folder=variants_tables, merged_csv_name="variants_long_table.csv"
)
except FileNotFoundError as e:
print("Not variants_long_table found for ", str(e))
print(str(e))
print("Merged variants_long_table.csv might be empty")

# Create excel files for individual tables
valid_extensions = [".csv", ".tsv", ".tab"]
Expand Down

0 comments on commit 0e2c9af

Please sign in to comment.