fhcrc / seqmagick

An imagemagick-like frontend to Biopython SeqIO
http://seqmagick.readthedocs.org
GNU General Public License v3.0
113 stars 22 forks source link

Test suite throws "TypeError: argument of type 'int' is not iterable" #73

Closed tillea closed 6 years ago

tillea commented 6 years ago

Hi, I intend to package seqmagick for Debian. When I try to run the test suite I get 7 errors:

python3.6 -m nose
.SS......E...EESS.....S..S.................................S..................................................................................................EEEE..
======================================================================
ERROR: test_run (seqmagick.test.integration.test_convert.TestConvertFromStdin)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/test/integration/test_convert.py", line 37, in test_run
    cli.main(shlex.split(command))
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/scripts/cli.py", line 29, in main
    return action(arguments)
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/subcommands/convert.py", line 354, in action
    transform_file(src, dest, arguments)
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/subcommands/convert.py", line 318, in transform_file
    SeqIO.write(records, destination_file, destination_file_type)
  File "/usr/lib/python3/dist-packages/Bio/SeqIO/__init__.py", line 497, in write
    count = writer_class(fp).write_file(sequences)
  File "/usr/lib/python3/dist-packages/Bio/SeqIO/Interfaces.py", line 215, in write_file
    count = self.write_records(records)
  File "/usr/lib/python3/dist-packages/Bio/SeqIO/Interfaces.py", line 199, in write_records
    for record in records:
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/transform.py", line 703, in translate
    protein = seq.translate(table, to_stop=to_stop)
  File "/usr/lib/python3/dist-packages/Bio/Seq.py", line 1110, in translate
    cds, gap=gap)
  File "/usr/lib/python3/dist-packages/Bio/Seq.py", line 2390, in _translate_str
    dual_coding = [c for c in stop_codons if c in forward_table]
  File "/usr/lib/python3/dist-packages/Bio/Seq.py", line 2390, in <listcomp>
    dual_coding = [c for c in stop_codons if c in forward_table]
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/transform.py", line 663, in __getitem__
    elif '-' in codon:
TypeError: argument of type 'int' is not iterable

...

======================================================================
ERROR: test_dna_protein_nogap_stop (seqmagick.test.test_transform.TranslateTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/test/test_transform.py", line 513, in test_dna_protein_nogap_stop
    self.assertEqual(expected, [str(i.seq) for i in actual])
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/test/test_transform.py", line 513, in <listcomp>
    self.assertEqual(expected, [str(i.seq) for i in actual])
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/transform.py", line 703, in translate
    protein = seq.translate(table, to_stop=to_stop)
  File "/usr/lib/python3/dist-packages/Bio/Seq.py", line 1110, in translate
    cds, gap=gap)
  File "/usr/lib/python3/dist-packages/Bio/Seq.py", line 2390, in _translate_str
    dual_coding = [c for c in stop_codons if c in forward_table]
  File "/usr/lib/python3/dist-packages/Bio/Seq.py", line 2390, in <listcomp>
    dual_coding = [c for c in stop_codons if c in forward_table]
  File "/build/seqmagick-0.7.0/.pybuild/cpython3_3.6/build/seqmagick/transform.py", line 663, in __getitem__
    elif '-' in codon:
TypeError: argument of type 'int' is not iterable
-------------------- >> begin captured logging << --------------------
root: INFO: Applying translation generator: operation to perform is dna2proteinstop.
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 164 tests in 0.968s

FAILED (SKIP=7, errors=7)

This happens when using the Debian packaged version of BioPython 1.71. Am I missing something or is there really an issue with seqmagick. Kind regards, Andreas.

peterjc commented 6 years ago

The immediate error is here: https://github.com/fhcrc/seqmagick/blob/0.7.0/seqmagick/transform.py#L703

protein = seq.translate(table, to_stop=to_stop)

It appears in a round about way that the problem stems from Biopython 1.71's support for dual-coding codons which can be amino acids or stop codons, see https://github.com/biopython/biopython/pull/1501

i.e. The seqmagick code's own subclass CodonWarningTable appears to need updating.

--

As an aside, since I was initially looking at line 70 rather than 703, I suspect the cleanest solution (but not necessarily the fastest) for the dashes_cleanup function would be:

for c in prune_chars:
    record.seq = record.seq.ungap(c)

Currently these methods expect a single letter gap character, and will not take a tuple/list of gap characters either. Therefore currently the seqmagick code is calling the Python string translate method instead.

metasoarous commented 6 years ago

Fixed by #76.

Thanks @peterjc!

peterjc commented 6 years ago

@tillea the fix to work with Biopython 1.71 is small enough that unless there is a new seqmagick release soon, I would suggest you include it as a patch in the Debian package recipe.

matsen commented 6 years ago

I think we will cut a new release by the end of the week-- right, @metasoarous ?

tillea commented 6 years ago

On Wed, May 30, 2018 at 04:59:37AM -0700, Erick Matsen wrote:

I think we will cut a new release by the end of the week-- right, @metasoarous ? That's nice in general but not urgently needed for my purpose since I've uploaded the package into Debian new queue using Peter's patch. Thanks a lot, Andreas.

metasoarous commented 6 years ago

We should be able to get it out by the end of the week, yes. Glad you're unblocked for now @tillea.