Advertisement
Guest User

ik ben kk mude hierdoor

a guest
Sep 25th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import sys
  4.  
  5. filename = sys.argv[1]
  6.  
  7. totfile = open(filename).read()
  8.  
  9. contains_aminoacid = False
  10. header = ''
  11. type_file = ''
  12.  
  13. for header in totfile:
  14.     if header.startswith('>'):
  15.         print(header,'/n')
  16.  
  17. for line in totfile:
  18.     if not line.startswith('>'):
  19.         pass
  20.         stripped = line.strip()
  21.         for characters in stripped:
  22.             if characters not in ['A','T','C','G','U']
  23.                 contains_aminoacid = True
  24.                 if contains_aminoacid == True:
  25.                     type_file = "aminoacid"
  26.                     print(type_file)
  27.                         break
  28.  
  29. start_num = input("On what character would you like to start the translation?\n")
  30. start_num = int(start_num)
  31.  
  32. count = 1
  33. templist = []
  34.  
  35. if contains_aminoacid == False:
  36.     for char in stripped:
  37.         count += 1
  38.         templist.append(char)
  39.         if count == start_num:
  40.             tempstring = ''.join(templist)
  41.             string_ready = stripped.replace(tempstring, '')
  42.         elif count > start_num:
  43.             break
  44.  
  45. tripletlist = []
  46. templist = []
  47.  
  48. if contains_aminoacid == False:
  49.     for char in string_ready:
  50.         templist.append(char)
  51.         if len(templist) == 3:
  52.             triplet = "".join(templist)
  53.             tripletlist.append(triplet)
  54.             templist = []
  55.         else:
  56.             continue
  57.  
  58.  
  59. aminoacid_codons = {"GCT":"A", "GCC":"A", "GCA":"A", "GCG":"A", "CGT":"R",
  60.                     "CGC":"R", "CGA":"R", "CGG":"R", "AGA":"R", "AGG":"R",
  61.                     "AAT":"N", "AAC":"N", "GAT":"D", "GAC":"D", "TGT":"C",
  62.                     "TGC":"C", "CAA":"Q", "CAG":"Q", "GAA":"E", "GAG":"E",
  63.                     "GGT":"G", "GGC":"G", "GGA":"G", "GGG":"G", "CAT":"H",
  64.                     "CAC":"H", "ATT":"I", "ATC":"I", "ATA":"I", "TTA":"L",
  65.                     "TTG":"L", "CTT":"L", "CTC":"L", "CTA":"L", "CTG":"L",
  66.                     "AAA":"K", "AAG":"K", "ATG":"M", "TTT":"F", "TTC":"F",
  67.                     "CCT":"P", "CCC":"P", "CCA":"P", "CCG":"P", "TCT":"S",
  68.                     "TCC":"S", "TCA":"S", "TCG":"S", "ATG":"S", "AGC":"S",
  69.                     "ACT":"T", "ACC":"T", "ACA":"T", "ACG":"T", "TGG":"W",
  70.                     "TAT":"Y", "TAC":"Y", "GTT":"V", "GTC":"V", "GTA":"V",
  71.                     "GTG":"V"}
  72.  
  73. protein_file = open("proteinseq.fasta", 'r+')
  74.  
  75. for item in tripletlist:
  76.     if item in aminoacid_codons:
  77.         protein_file.write(aminoacid_codons[item])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement