Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32 address code quality issues in codacy report #33

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/unit/test_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
soft_species_probability,
hard_species_probability,
threshold_assignment_probability,
iter_threshold,
)

from unassigner.alignment import AlignedPair
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_aligned.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/test_mismatch_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
import os
import io
import tempfile
Expand All @@ -8,7 +7,6 @@
MismatchLocationApp,
main,
group_by_n,
MutableMismatchDb,
)

DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data")
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_parse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tempfile
import unittest


from unassigner.parse import parse_fasta, parse_results, load_fasta, write_fasta


Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion unassigner/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion unassigner/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
1 change: 0 additions & 1 deletion unassigner/alignment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
import operator


class AlignedPair(object):
Expand Down
1 change: 0 additions & 1 deletion unassigner/mismatch_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import collections
import itertools
import operator
import sys
import tempfile

from unassigner.parse import parse_fasta, write_fasta
Expand Down
5 changes: 2 additions & 3 deletions unassigner/parse.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging
import re
from io import StringIO


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:
Expand Down Expand Up @@ -62,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
Expand Down
2 changes: 1 addition & 1 deletion unassigner/prepare_strain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion unassigner/trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion unassigner/unassignment_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading