Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_length(dna):
- """ (str) -> int
- Return the length of the DNA sequence dna.
- >>> get_length('ATCGAT')
- 6
- >>> get_length('ATCG')
- 4
- """
- return len(dna)
- def is_longer(dna1, dna2):
- """ (str, str) -> bool
- Return True if and only if DNA sequence dna1 is longer than DNA sequence
- dna2.
- >>> is_longer('ATCG', 'AT')
- True
- >>> is_longer('ATCG', 'ATCGGA')
- False
- """
- return len(dna1) > len(dna2)
- def count_nucleotides(dna, nucleotide):
- """ (str, str) -> int
- Return the number of occurrences of nucleotide in the DNA sequence dna.
- >>> count_nucleotides('ATCGGC', 'G')
- 2
- >>> count_nucleotides('ATCTA', 'G')
- 0
- """
- return dna.count(nucleotide)
- def contains_sequence(dna1, dna2):
- """ (str, str) -> bool
- Return True if and only if DNA sequence dna2 occurs in the DNA sequence
- dna1.
- >>> contains_sequence('ATCGGC', 'GG')
- True
- >>> contains_sequence('ATCGGC', 'GT')
- False
- """
- return dna1.count(dna2) > 0
- def is_valid_sequence(dna):
- """
- (str) -> bool
- Return True if and only if the DNA sequence is valid
- >>> is_valid_sequence('ACCGT')
- True
- >>> is_valid_sequence('ACCDT')
- Fale
- """
- for nucleotide in dna:
- if nucleotide not in "ATCG":
- return False
- return True
- def insert_sequence(dna1, dna2, loc):
- """
- (str, str, int) -> str
- Return the DNA sequence obtained by inserting the second DNA sequence into
- the first DNA sequence at the given index.
- precondition: You can assume that the index is valid.
- >>> insert_sequence('ATGC', 'GG', 2)
- 'ATGGGC'
- >>> insert_sequence('ATGCCGTA', 'CCGGAA', 5)
- 'ATGCCCCGGAAGTA'
- """
- return dna1[0:loc] + dna2 + dna1[loc:]
- def get_complement(nucleotide):
- """
- (str) -> str
- Return the nucleotide's complement.
- >>> get_complement('A')
- 'T'
- >>> get_complement('a')
- 'a'
- """
- if nucleotide == 'A':
- return 'T'
- elif nucleotide == 'T':
- return 'A'
- elif nucleotide == 'G':
- return 'C'
- elif nucleotide == 'C':
- return 'G'
- return nucleotide
- def get_complementary_sequence(dna):
- """
- (str) -> str
- Return the DNA sequence that is complementary to the given DNA sequence.
- >>> get_complementary_sequence('TACG')
- 'ATGC'
- >>> get_complementary_sequence('AtGD')
- 'TtCD'
- """
- sequence = ''
- for nucleotide in dna:
- sequence += get_complement(nucleotide)
- return sequence
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement