Can you specify what versions of python
and biopython
you are using?
I've just attempted to run the documented examples, with their example files as at: https://biopython.org/wiki/Concatenate_nexus
It works fine for me on Python 3.7.3
and BioPython 1.74
:
Downloading test data:
$ curl https://biopython.org/examples/btCOI.nex > btCOI.nex
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 151 100 151 0 0 2745 0 --:--:-- --:--:-- --:--:-- 2745
$ curl https://biopython.org/examples/btCOII.nex > btCOII.nex
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 151 100 151 0 0 766 0 --:--:-- --:--:-- --:--:-- 762
$ curl https://biopython.org/examples/btITS.nex > btITS.nex
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 151 100 151 0 0 1078 0 --:--:-- --:--:-- --:--:-- 1086
In python:
$ python
Python 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from Bio.Nexus import Nexus
>>> file_list = ['btCOI.nex', 'btCOII.nex', 'btITS.nex']
>>> nexi = [(fname, Nexus.Nexus(fname)) for fname in file_list]
>>> combined = Nexus.combine(nexi)
>>> combined.write_nexus_data(filename=open('btCOMBINED.nex', 'w'))
<_io.TextIOWrapper name='btCOMBINED.nex' mode='w' encoding='UTF-8'>
>>> [x for x in os.listdir() if x.endswith("nex")]
[''btCOMBINED.nex', 'btCOI.nex', 'btCOII.nex', 'btITS.nex']
>>> exit()
Check file:
$ cat btCOMBINED.nex
#NEXUS
begin data;
dimensions ntax=4 nchar=32;
format datatype=dna missing=? gap=-;
matrix
bt1 GGGGGGGGGGGGAAAAAAAAAAAA-TTTTTTT
bt2 GGGGGGGGGGGGAAAAAAAAAAAA-TTTTTTT
bt3 GGGGGGGGGGGGAAAAAAAAAAAA-TTTTTTT
bt4 ????????????????????????-TTTTTTT
;
end;
begin sets;
charset btCOI.nex = 1-12;
charset btCOII.nex = 13-24;
charset btITS.nex = 25-32;
charpartition combined = btCOI.nex: 1-12, btCOII.nex: 13-24, btITS.nex: 25-32;
end;
Please use the formatting bar (especially the
code
option) to present your post better. You can use backticks for inline code (`text` becomestext
), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.Did
combined.write_nexis_data()
threw an error? Was the file created? It might be in a directory you don't expect it to be in, try giving it an absolute path maybe.No file created in the working directory and no error thrown.
I've not used this bit of the module before, but if I had to guess, I'd say the documentation is probably just out of date relative to the codebase.
Looking at https://biopython.org/DIST/docs/api/Bio.Nexus.Nexus-pysrc.html#Nexus.write_nexus_data
There appears to be a 'append' flag to that method, so perhaps they've refactored the code to have one write method which serves all purposes (again, total guess).
Okay, I tried also using
write_nexus_data(filename=open('btCOMBINED.nex', 'w'))
but then got that error which I am unsure how I am using the command wrong.