fork download
  1. def AT(seq):
  2. at = sum(seq.count(x) for x in ["a", "t", "A", "T"])
  3. try:
  4. c = round(at / len(seq), 2)
  5. return c
  6. except ZeroDivisionError:
  7. return 0.0
  8.  
  9. def GC(seq):
  10. gc = sum(seq.count(h) for h in ["g", "c", "G", "C"])
  11. try:
  12. y = round((gc / len(seq))*100, 2)
  13. return y
  14. except ZeroDivisionError:
  15. return 0.0
  16.  
  17. dna_seq = "GTCTCTACCTTGACAGACCTCCAGCCGTACATGCGACAGTTCGTGGCTCACCTGCAGGAGACCAGCCCGCTGAGGGATGCCGTCGTCATCGAGCAG"
  18. at_content = AT(dna_seq)
  19. print(at_content)
  20. gc_content = GC(dna_seq)
  21. print(gc_content)
Success #stdin #stdout 0.02s 9148KB
stdin
Standard input is empty
stdout
0.39
61.46