DK: Thanks for the reply! While I get an error with the first portion ("TypeError: sort() got an unexpected keyword argument 'key'") the second option seems to be working fine.
Is There A Way To Sort A Biopython Alignment By A Feature Other Then Id?
I would like to know if there is there a way to sort a biopython alignment by a feature other then ID? In the biopython cookbook (http://www.bio-cloud.info/Biopython/en/ch6.html) there is a way to sort the alignment by ID. Is it possible to sort the sequence records in the alignment by another feature such as description or name?
• 5,366 views
•
link
2 answers
I am not sure if the alignment object is same as a python iterable array. You can try:
myAligment.sort(key = lambda x : x[column you want to sort by])
If that doesn't work, you can always restructure your alignment into an array of tuples:
newArray = [(x[column you want to sorty by], x) for x in myAlignment]
Then sort by the first element of the tuple which contain data of the column you want to sorty by:
newArray.sort(key = lambda x : x[0])
• 1 views
•
link
• 0 views
•
link
Log in to answer this question.
Note the official tutorial is http://biopython.org/DIST/docs/tutorial/Tutorial.html - what you are looking at is an out of dae experimental reformatting.