Posted By

ishmael78 on 12/31/10


Tagged

shuffle biopython fasta bioinfomatics


Versions (?)

Shuffle fasta sequences


 / Published in: Python
 

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. """
  4. 01_shuffle_fa.py
  5.  
  6. Created by SNY of PICB on 2010/12/30 13:01:20.
  7.  
  8. """
  9.  
  10. import sys
  11. import os
  12. import string
  13. import random
  14. from Bio import SeqIO
  15. from Bio.Seq import Seq
  16.  
  17.  
  18. def main():
  19. in_name = sys.argv[1]
  20. out_name = sys.argv[2]
  21.  
  22. in_handle = open(in_name)
  23. out_handle = open(out_name, "w")
  24. for seq_record in SeqIO.parse(in_handle, "fasta"):
  25. l = list(str(seq_record.seq))
  26. random.shuffle(l)
  27. seq_record.seq = Seq(''.join(l))
  28. SeqIO.write(seq_record, out_handle, "fasta")
  29. in_handle.close()
  30. out_handle.close()
  31.  
  32.  
  33. if __name__ == '__main__':
  34. main()

Report this snippet  

You need to login to post a comment.