From 227b119c8502e655d1186010c832bc74e11b7f4c Mon Sep 17 00:00:00 2001 From: jfnavarro Date: Wed, 8 Jan 2025 16:52:18 +0100 Subject: [PATCH] Update tests --- scripts/adjust_matrix_coordinates.py | 4 ++-- scripts/convertEnsemblToNames.py | 12 +++++------- scripts/filter_gene_type_matrix.py | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/adjust_matrix_coordinates.py b/scripts/adjust_matrix_coordinates.py index d9380d5..50eee5d 100644 --- a/scripts/adjust_matrix_coordinates.py +++ b/scripts/adjust_matrix_coordinates.py @@ -40,7 +40,7 @@ def main(counts_matrix: str, coordinates_file: str, update_coordinates: bool, ou return 1 if not outfile: - outfile = "adjusted_{}".format(os.path.basename(counts_matrix)) + outfile = f"adjusted_{os.path.basename(counts_matrix)}" # Get a map of the new coordinates new_coordinates = dict() @@ -70,7 +70,7 @@ def main(counts_matrix: str, coordinates_file: str, update_coordinates: bool, ou new_x, new_y = new_coordinates[(x, y)] if not update_coordinates: new_x, new_y = x, y - new_index_values.append("{0}x{1}".format(new_x, new_y)) + new_index_values.append(f"{new_x}x{new_y}") except KeyError: counts_table.drop(index, inplace=True) diff --git a/scripts/convertEnsemblToNames.py b/scripts/convertEnsemblToNames.py index 5ad292d..c807897 100755 --- a/scripts/convertEnsemblToNames.py +++ b/scripts/convertEnsemblToNames.py @@ -29,7 +29,7 @@ def main(st_data_file: str, annotation: str, output_file: str) -> int: try: gene_map[line["gene_id"]] = line["gene_name"] except KeyError as e: - print("Error, parsing annotation file, missing key {}".format(e)) + print(f"Error, parsing annotation file, missing key {e}") return 1 assert (len(gene_map) > 0) @@ -38,14 +38,14 @@ def main(st_data_file: str, annotation: str, output_file: str) -> int: # Check that the annotation file given was valid if len(gene_map) < len(st_data.columns): - print("Error, the annotation file given is invalid or does not match the ST data") + print(f"Error, the annotation file given is invalid or does not match the ST data") return 1 # Checks that there are no duplicated genes ids in the input data gene_ids_counter = Counter(st_data.columns) for gene_id, count in gene_ids_counter.most_common(): if count > 1: - print("Error, Ensembl ID {} was found {} times in the input matrix.".format(gene_id, count)) + print(f"Error, Ensembl ID {gene_id} was found {count} times in the input matrix.") return 1 # Iterates the genes IDs to get gene names @@ -62,11 +62,9 @@ def main(st_data_file: str, annotation: str, output_file: str) -> int: # so we keep the Ensembl ID. # We assume input Ensembl ids are unique as we checked this before gene_name = gene_id - print("Warning, gene name {} was already matched so the original " - "Ensembl ID {} will be kept".format(gene_name, gene_id)) + print(f"Warning, gene name {gene_name} was already matched so the original Ensembl ID {gene_id} will be kept") except KeyError: - print("Warning, {} was not found in the annotation, " - "so the original Ensembl ID will be kept".format(gene_id)) + print(f"Warning, {gene_id} was not found in the annotation so the original Ensembl ID will be kept") gene_name = gene_id adjustedList.append(gene_name) diff --git a/scripts/filter_gene_type_matrix.py b/scripts/filter_gene_type_matrix.py index bc4d8c7..5db7cc8 100644 --- a/scripts/filter_gene_type_matrix.py +++ b/scripts/filter_gene_type_matrix.py @@ -51,7 +51,7 @@ def main(counts_matrix: str, gene_types_keep: List[str], outfile: str, annotatio if gene_types[gene] not in gene_types_keep: genes_drop.append(gene) except KeyError: - print("Warning, {} was not found in the annotation\n".format(gene)) + print(f"Warning, {gene} was not found in the annotation") if len(genes_drop) > 0: counts_table.drop(genes_drop, axis=1, inplace=True)