From 93f287d9e4126b02c163f0719ec3af8ee15575b7 Mon Sep 17 00:00:00 2001 From: Ulthran Date: Thu, 26 Sep 2024 15:05:57 -0400 Subject: [PATCH 1/4] Remove unused imports --- tests/unit/test_algorithm.py | 1 - tests/unit/test_mismatch_db.py | 2 -- tests/unit/test_parse.py | 2 +- unassigner/align.py | 2 +- unassigner/alignment.py | 1 - unassigner/mismatch_db.py | 1 - unassigner/parse.py | 1 - 7 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/unit/test_algorithm.py b/tests/unit/test_algorithm.py index 044c4a6..52967a7 100644 --- a/tests/unit/test_algorithm.py +++ b/tests/unit/test_algorithm.py @@ -9,7 +9,6 @@ soft_species_probability, hard_species_probability, threshold_assignment_probability, - iter_threshold, ) from unassigner.alignment import AlignedPair diff --git a/tests/unit/test_mismatch_db.py b/tests/unit/test_mismatch_db.py index a5d1e99..dd0c8f1 100644 --- a/tests/unit/test_mismatch_db.py +++ b/tests/unit/test_mismatch_db.py @@ -1,4 +1,3 @@ -import collections import os import io import tempfile @@ -8,7 +7,6 @@ MismatchLocationApp, main, group_by_n, - MutableMismatchDb, ) DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data") diff --git a/tests/unit/test_parse.py b/tests/unit/test_parse.py index 131457d..bbfc494 100644 --- a/tests/unit/test_parse.py +++ b/tests/unit/test_parse.py @@ -1,7 +1,7 @@ import tempfile import unittest -from unassigner.parse import parse_fasta, parse_desc, load_fasta, write_fasta +from unassigner.parse import parse_fasta, load_fasta, write_fasta class FastaTests(unittest.TestCase): diff --git a/unassigner/align.py b/unassigner/align.py index b2270d3..29502da 100644 --- a/unassigner/align.py +++ b/unassigner/align.py @@ -4,7 +4,7 @@ import tempfile from Bio import pairwise2 -from unassigner.parse import write_fasta, load_fasta, parse_fasta +from unassigner.parse import write_fasta, parse_fasta from unassigner.alignment import AlignedPair BLAST_FMT = ( diff --git a/unassigner/alignment.py b/unassigner/alignment.py index b1bec09..e8d1222 100644 --- a/unassigner/alignment.py +++ b/unassigner/alignment.py @@ -1,5 +1,4 @@ import itertools -import operator class AlignedPair(object): diff --git a/unassigner/mismatch_db.py b/unassigner/mismatch_db.py index e46023f..e3762be 100644 --- a/unassigner/mismatch_db.py +++ b/unassigner/mismatch_db.py @@ -6,7 +6,6 @@ import collections import itertools import operator -import sys import tempfile from unassigner.parse import parse_fasta, write_fasta diff --git a/unassigner/parse.py b/unassigner/parse.py index 445881a..8ffbebf 100644 --- a/unassigner/parse.py +++ b/unassigner/parse.py @@ -1,5 +1,4 @@ import logging -import re from io import StringIO From 32c38dd2f261c7b8bf3b3ec4e56253219c2614ac Mon Sep 17 00:00:00 2001 From: Ulthran Date: Thu, 26 Sep 2024 15:13:11 -0400 Subject: [PATCH 2/4] Fix region alignment tests to use from_query object --- tests/unit/test_aligned.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_aligned.py b/tests/unit/test_aligned.py index 87d64f8..0f391b5 100644 --- a/tests/unit/test_aligned.py +++ b/tests/unit/test_aligned.py @@ -53,17 +53,17 @@ def test_region_subject_to_query_no_endgaps(self): r = AlignedRegion.from_subject(a, 0, 3) self.assertEqual(r.in_alignment(), (0, 3)) rq = AlignedRegion.from_query(a, 0, 3) - self.assertEqual(r.in_alignment(), (0, 3)) + self.assertEqual(rq.in_alignment(), (0, 3)) r = AlignedRegion.from_subject(a, 1, 5) self.assertEqual(r.in_alignment(), (1, 5)) rq = AlignedRegion.from_query(a, 1, 5) - self.assertEqual(r.in_alignment(), (1, 5)) + self.assertEqual(rq.in_alignment(), (1, 5)) r = AlignedRegion.from_subject(a) self.assertEqual(r.in_alignment(), (0, 6)) rq = AlignedRegion.from_query(a) - self.assertEqual(r.in_alignment(), (0, 6)) + self.assertEqual(rq.in_alignment(), (0, 6)) def test_region_subject_to_query_with_endgaps(self): a = AlignedPair(("a", "--ABC-EF---"), ("b", "HIJKLMNOPQR")) From 70d39e7c20dca0b5f201d154dd7dfebea0c5a3cf Mon Sep 17 00:00:00 2001 From: Ulthran Date: Thu, 26 Sep 2024 15:19:17 -0400 Subject: [PATCH 3/4] Remove/comment out unused variables --- tests/unit/test_trim.py | 6 +++--- unassigner/algorithm.py | 2 +- unassigner/parse.py | 4 ++-- unassigner/prepare_strain_data.py | 2 +- unassigner/trim.py | 2 +- unassigner/unassignment_probability.py | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/test_trim.py b/tests/unit/test_trim.py index 60c0944..2a241f8 100644 --- a/tests/unit/test_trim.py +++ b/tests/unit/test_trim.py @@ -153,7 +153,7 @@ def test_alignment_match_subj_left(self): ) m = AlignmentMatcher(self.test_dir) alignment_matches = list(m.find_in_seqs(s)) - match_id, matchobj = alignment_matches[0] + _, matchobj = alignment_matches[0] self.assertEqual(matchobj.start, 0) self.assertEqual(matchobj.end, 3) @@ -167,7 +167,7 @@ def test_alignment_match_middle(self): ) m = AlignmentMatcher(self.test_dir) alignment_matches = list(m.find_in_seqs(s)) - match_id, matchobj = alignment_matches[0] + _, matchobj = alignment_matches[0] self.assertEqual((matchobj.start, matchobj.end), (7, 12)) def test_alignment_match_middle_gaps(self): @@ -180,7 +180,7 @@ def test_alignment_match_middle_gaps(self): ) m = AlignmentMatcher(self.test_dir) alignment_matches = list(m.find_in_seqs(s)) - match_id, matchobj = alignment_matches[0] + _, matchobj = alignment_matches[0] self.assertEqual((matchobj.start, matchobj.end), (7, 11)) def test_trim_right(self): diff --git a/unassigner/algorithm.py b/unassigner/algorithm.py index d42a807..f5bdea9 100644 --- a/unassigner/algorithm.py +++ b/unassigner/algorithm.py @@ -78,7 +78,7 @@ def load_database(cls, f): line = line.rstrip() toks = line.split("\t") typestrain_id = toks[0] - ref_seq_id = toks[1] + # ref_seq_id = toks[1] mismatch_positions = [int(x) for x in toks[2:]] cls.db[typestrain_id].append(mismatch_positions) diff --git a/unassigner/parse.py b/unassigner/parse.py index 8ffbebf..c08b9e5 100644 --- a/unassigner/parse.py +++ b/unassigner/parse.py @@ -3,7 +3,7 @@ def parse_species_names(f): - for desc, seq in parse_fasta(f): + for desc, _ in parse_fasta(f): vals = desc.split("\t", maxsplit=1) accession = vals[0] if len(vals) == 2: @@ -61,7 +61,7 @@ def parse_desc(desc): # This is the old way of parsing the description, 01_2022 # accession = re.findall(r"\[accession=(.*?)\]", desc)[0] # species_name = re.findall(r"\[organism=(.*?)\]", desc)[0] - except IndexError as e: + except IndexError: logging.error(f"Couldn't find accession and/or organism identifier in {desc}") logging.error(f"Skipping this sequence...") return None, None diff --git a/unassigner/prepare_strain_data.py b/unassigner/prepare_strain_data.py index 3e3246e..5a65826 100755 --- a/unassigner/prepare_strain_data.py +++ b/unassigner/prepare_strain_data.py @@ -77,7 +77,7 @@ def main(argv=None): clean(db_dir) sys.exit(0) - ltp_metadata_fp = use_or_download(args.ltp_metadata_fp, LTP_METADATA_URL, db_dir) + use_or_download(args.ltp_metadata_fp, LTP_METADATA_URL, db_dir) ltp_seqs_fp = use_or_download(args.ltp_seqs_fp, LTP_SEQS_URL, db_dir) process_ltp_seqs(ltp_seqs_fp, db_dir) diff --git a/unassigner/trim.py b/unassigner/trim.py index af77051..e787dd2 100644 --- a/unassigner/trim.py +++ b/unassigner/trim.py @@ -140,7 +140,7 @@ def find_match(self, seq): else: msg = "Complete, {0} mismatches".format(n_mismatches) end_idx = start_idx + len(query) - obs_primer = seq[start_idx:end_idx] + # obs_primer = seq[start_idx:end_idx] return PrimerMatch(start_idx, end_idx, 0, msg) diff --git a/unassigner/unassignment_probability.py b/unassigner/unassignment_probability.py index bde4cf5..33c36ad 100644 --- a/unassigner/unassignment_probability.py +++ b/unassigner/unassignment_probability.py @@ -5,7 +5,7 @@ def species_probability(self, species_alignment, refseq_alignments): start = species_alignment.start_pos end = species_alignment.end_pos for r in refseq_alignments: - refseq_id = r.subject_id + # refseq_id = r.subject_id a, b = r.count_matches(start, end) c, d = r.count_matches() yield query_id, species_id, a, b, r.subject_id, c, d From e50bdaefa07699a9db67c543e9c815884fc3e8db Mon Sep 17 00:00:00 2001 From: Ulthran Date: Thu, 26 Sep 2024 15:25:25 -0400 Subject: [PATCH 4/4] Remove codacy cli run in tests --- .github/workflows/test.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 864c1c2..be2c0a4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -90,14 +90,4 @@ jobs: - name: Lint Code Base run: | - black --check . - - codacy-analysis-cli: - name: Codacy Analysis CLI - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Run Codacy Analysis CLI - uses: codacy/codacy-analysis-cli-action@master \ No newline at end of file + black --check . \ No newline at end of file