soedinglab / CCMpred

Protein Residue-Residue Contacts from Correlated Mutations predicted quickly and accurately.
http://www.ncbi.nlm.nih.gov/pubmed/25064567
GNU Affero General Public License v3.0
107 stars 25 forks source link

Update convert_alignment.py to support BioPython < 1.44 #21

Closed poliu2s closed 4 years ago

poliu2s commented 4 years ago

I have been recently using the convert_alignment.py script to convert some FASTA files, however it was failing because the tostring() method.

Update to string parsing method to conform to new Seq class - https://biopython.org/DIST/docs/api/Bio.Seq.Seq-class.html

croth1 commented 4 years ago

Hmh, the documentation says:

Note that Biopython 1.44 and earlier would give a truncated version of repr(my_seq) for str(my_seq). If you are writing code which need to be backwards compatible with really old Biopython, you should continue to use my_seq.tostring() as follows:

try:
    # The old way, removed in Biopython 1.73
    as_string = seq_obj.tostring()
except AttributeError:
    # The new way, needs Biopython 1.45 or later.
    # Don't use this on Biopython 1.44 or older as truncates
    as_string = str(seq_obj)

Doesn't that imply that this change breaks compatibility with modern versions of biopython?

poliu2s commented 4 years ago

Good point.

I have added the exception handling to accommodate as per the documentation.

sseemayer commented 4 years ago

Thanks a lot for the PR @poliu2s and thanks for pointing that out @croth1 !

Everything looks good to me, I also would have been fine with breaking backwards compatibility for Biopython versions that are > 12 years old

croth1 commented 4 years ago

I changed the title to reflect that this adds backward compatibility to very early versions of biopython. I also think this is fine now!