Created
May 19, 2015 19:56
-
-
Save rachelss/27f03dc7dac25a91a32e to your computer and use it in GitHub Desktop.
filter for variable sites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2 | |
| from Bio import AlignIO | |
| import sys | |
| fformat=sys.argv[1].split('.')[-1] | |
| align = AlignIO.read(open(sys.argv[1]), fformat) #load file | |
| outname = sys.argv[1].split('.')[:-1]+'.filtered.phylip-relaxed' | |
| #find variable sites | |
| info=[] | |
| for i in range(len(align[0])): | |
| site=[a for a in list(align[:, i])] | |
| if len(list(set(site)))>1: | |
| info.append(i) | |
| #include only these sites | |
| for i,record in enumerate(align): | |
| sp_data=[record.seq[j] for j in info] | |
| align[i].seq="".join(sp_data) | |
| AlignIO.write(align, outname, "phylip-relaxed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment