Converter Module

TSV to Excel conversion and formatting

File conversion module.

This module provides functionality to convert TSV files to XLSX format and append additional sheets. It now also supports producing JSON files for the HTML report.

variantcentrifuge.converter.convert_to_excel(tsv_file, cfg)[source]

Convert a TSV file to XLSX format with a single “Results” sheet.

Parameters:
  • tsv_file (str) – Path to the TSV file.

  • cfg (dict) – Configuration dictionary containing various settings.

Returns:

The path to the generated XLSX file.

Return type:

str

variantcentrifuge.converter.append_tsv_as_sheet(xlsx_file, tsv_file, sheet_name='Metadata')[source]

Append a TSV file as a new sheet to an existing XLSX file.

This function reads the TSV file and appends it as a new sheet in the existing XLSX file. Assumes the TSV file has a header row.

Parameters:
  • xlsx_file (str) – Path to the existing XLSX file.

  • tsv_file (str) – Path to the TSV file to append as a sheet.

  • sheet_name (str, optional) – Name of the new sheet to be appended. Defaults to “Metadata”.

Return type:

None

variantcentrifuge.converter.finalize_excel_file(xlsx_file, cfg)[source]

Apply final formatting to all sheets in xlsx_file.

  • Freeze the top row

  • Enable auto-filter

  • Only for the ‘Results’ sheet, generate hyperlinks from CHROM, POS, REF, ALT using cfg[“links”] (the link template dictionary).

  • Add “IGV Report Links” column with hyperlinks to IGV reports if available

Parameters:
  • xlsx_file (str) – Path to the Excel file to finalize.

  • cfg (dict) – Configuration dictionary containing links and IGV settings.

Return type:

None

variantcentrifuge.converter.produce_report_json(variant_tsv, output_dir)[source]

Produce JSON files (variants.json and summary.json) from a TSV of variants.

The TSV file is expected to have columns including GENE, CHROM, POS, REF, ALT, IMPACT. Two JSON files are produced:

  • variants.json: A list of all variants with their annotations.

  • summary.json: Aggregated counts (num_variants, num_genes, impact_distribution).

These files are used by the HTML report generator.

Parameters:
  • variant_tsv (str) – Path to the TSV file containing annotated variants.

  • output_dir (str) – Directory to write the JSON outputs (variants.json, summary.json).

Return type:

None