Skip to content

Instantly share code, notes, and snippets.

@BjornFJohansson
Created September 6, 2021 15:11
Show Gist options
  • Save BjornFJohansson/7c3caa7e521e64a32e274df573fefa34 to your computer and use it in GitHub Desktop.
Save BjornFJohansson/7c3caa7e521e64a32e274df573fefa34 to your computer and use it in GitHub Desktop.
Unicode in Dseqrecord description
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ITS-Account
Copy link

Might be a Windows thing. I get:

Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydna
>>> pydna.__version__
'4.0.0a12'
>>> from pydna.dseqrecord import Dseqrecord
>>> from pydna.readers import read
>>> out_pydna = Dseqrecord("aaa")
>>> out_pydna.description = '30-506915946-NGS000053 with BβaI, GTGT/AGCC'
>>> out_pydna.format()
'LOCUS       name                       3 bp    DNA     linear   UNK 01-JAN-1980\nDEFINITION  30-506915946-NGS000053 with BβaI, GTGT/AGCC.\nACCESSION   id\nVERSION     id\nKEYWORDS    .\nSOURCE      .\n  ORGANISM  .\n            .\nFEATURES             Location/Qualifiers\nORIGIN\n        1 aaa\n//'
>>> out_pydna.write("out_pydna.gb", f="gb")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\_________\AppData\Local\Programs\Python\Python39\lib\site-packages\pydna\dseqrecord.py", line 531, in write
    fp.write(self.format(f))
  File "C:\Users\_________\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u03b2' in position 122: character maps to <undefined>

I tried on Linux running through WSL and it works there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment