0

I am trying to write a code in Python to takes in a list of DNA sequence and return scores based on the following factors:

  • If the base is A or T, 0 should be added to the previous number
  • If the base is G, 1 should be added
  • If the base is C, 1 should be subtracted.

such that given the following DNA sequence, "CATGGGCATCGGCCATACGCC", the output should be [0 -1 -1 -1 0 1 2 1 1 1 0 1 2 1 0 0 0 0 -1 0 -1 -2]

I have tried this code

seq = "CATGGGCATCGGCCATACGCC"
def skew(seq):
  list_seq = list(seq)
  values = [0]
  for base in list_seq:
    if base == "A" or "T":
      values.append(values[-1])
    elif base == "C":
      values.append(values[-1] - 1)
    elif base == "G":
      values.append(values[-1] + 1)
    else:
      return "Invalid text"
  return values

This is the output

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
aminrd
  • 3,728
  • 3
  • 17
  • 34
Maryam
  • 1
  • 2
    `if base == "A" or "T"` is always true, because `"T"` is true regardless of whether `base == "A"` is. Change it to `if base == "A" or base == "T"`, or `if base in "AT"`. – Samwise Mar 02 '22 at 22:32

0 Answers0