# programme concatenating two nexus files (alignments) # in general useful for creating general matrix composed by more matrixes # provisorial name combinex # it starts from two nexus files. more files can be added with simple modifications of the code # with a debugging and adaption of the starting idea in http://biopython.org/wiki/Category:Cookbook biopython, cookbook) by an anonymous author, User:Davidw # Provided under GPL licence # Author Alessio Papini, Department of Evolutionary Biology University of Florence Italy, Via La Pira, 4 Firenze, mail alpapiniATunifi.it import os, sys print('The program calculates a general matrix produced with two smaller matrixes: same taxa MUST have the same name in the starting matrixes, otherwise the program will consider different names as different taxa. In case of taxa present in one matrix but not in the other, the program insert in the final matrix a series of ? corresponding to the missing sequence. print('supported format nexus') # It explains what the program does m1=raw_input('Write the name of the first matrix with its path to directory if different from the current working directory: ') m2=raw_input('Write the name of the second matrix with its path to directory if different from the current working directory: ') #acquisisce i nomi delle tre matrixes m3=raw_input('Write the name of the final matrix that will result from the combination of the matrixes in input with its path to directory if different from the current working directory: ') from Bio.Nexus import Nexus # the combine function takes a list [(name, nexus instance)...], if we provide the # file handles in a list we can use a list comprehension to such a list easily handles = [open(m1, 'r'), open(m2, 'r')] nexi = [(handle.name, Nexus.Nexus(handle)) for handle in handles] combined = Nexus.combine(nexi) combined.write_nexus_data(filename=m3)