from random import randint
def replace_base_randomly_using_names(base_seq):
"""Return a sequence with the base at a randomly selected position of base_seq
replaced by a base chosen randomly from the three bases that are not at that
position."""
position = randint(0, len(base_seq) - 1) # −1 because len is one past end
base = base_seq[position]
bases = 'TCAG'
bases.replace(base, '') # replace with empty string!
newbase = bases[randint(0,2)]
beginning = base_seq[0:position] # up to position
end = base_seq[position+1:] # omitting the base at position
return beginning + newbase + end
이것은 돌연변이를 시뮬레이트하기로되어 있습니다. doctype이 언급 한 것처럼, 기반이 실제로 변경되었는지 확인하기 위해 다른 기본 (TCAG 내에서)이 선택되는 방식을 이해하지 못합니다.문자열 내의 문자를 원래 문자가 포함 된 목록과 다른 문자로 바꾸기
편집 :
같은 일을 위의 코드의 또 다른 버전 :
def replace_base_randomly(base_seq):
position = randint(0, len(base_seq) - 1)
bases = 'TCAG'.replace(base_seq[position], '')
return (base_seq[0:position] +
bases [randint(0,2)] +
base_seq[position+1:])
명확하게하기 위해, 내 질문에 어떻게베이스가 다른 기지로 대체되고있다?
이것은 저를 위해 그것을했다.세 번째 요점은 그것을 클릭했다. 고마워. – ghal