project_creator_2.py 1.0 KB

123456789101112131415161718192021222324
  1. def copySequenceClean(fromFile,projectFolderPath):
  2. # Copy sequence and clean heads
  3. f1 = open(fromFile,"r")
  4. f2 = open(os.path.join(projectFolderPath,"sequence.fasta"),"w+")
  5. f3 = open(os.path.join(projectFolderPath,"sequence_heads.txt"),"w+")
  6. line = f1.readline()
  7. counter = 0
  8. while line!="":
  9. if(line.startswith(">")):
  10. counter += 1
  11. f3.write(">seq"+str(counter)+"\t"+line)
  12. f2.write(">seq"+str(counter)+"\n")
  13. else:
  14. f2.write(line.upper())
  15. line = f1.readline()
  16. f1.close()
  17. f2.close()
  18. f3.close()
  19. # Create reverse complement Fasta file
  20. records = map(make_rc_record, SeqIO.parse(os.path.join(projectFolderPath,"sequence.fasta"), "fasta"))
  21. SeqIO.write(records, os.path.join(projectFolderPath,"sequence_rc.fasta"), "fasta")
  22. records = map(make_rc_record, SeqIO.parse(os.path.join(projectFolderPath,"sequence_rc.fasta"), "fasta"))
  23. SeqIO.write(records, os.path.join(projectFolderPath,"sequence.fasta"), "fasta")