7.8 LAB: Double Helix All the Way (Long)

#returns the upstream dna sequence
def find_upstream(dna_sequence):
    index = dna_sequence.find('ATG')
    return dna_sequence[0:index]

# finds and returns the gene sequence
def find_gene(dna_sequence):
    index = dna_sequence.find('ATG')
    return dna_sequence[index:]

# returns the second condon in the gene sequence
def second_condon(gene_sequence):
    return gene_sequence[3:6]

# returns the third condon in the gene sequence
def third_condon(gene_sequence):
    return gene_sequence[6:9]

# returns the complimentary nucleotide
def complementary_nucleotide(nucleotide):
    if nucleotide=='G':
        return 'C'
    elif nucleotide=='C':
        return 'G'
    elif nucleotide=='A':
        return 'T'
    elif nucleotide=='T':
        return 'A'

# returns the complimentary sequence
def complementary_sequence(dna_sequence):
    comp_seq=""
    for n in dna_sequence:
        comp_seq += complementary_nucleotide(n)
    return(comp_seq)

if __name__ == "__main__":
    # assuming string comprises only of C,T,A,G characters
    dna_sequence = input('Enter the DNA sequence:')
    print("Original sequence: "+ dna_sequence)

    gene_sequence = find_gene(dna_sequence)
    location_of_gene = dna_sequence.find(gene_sequence)+1
    print("\nATG condon at bp "+str(location_of_gene))
    print("\tfollowed by {0} at bp {1}".format(second_condon(gene_sequence),str(location_of_gene+3)))
    print("\tfollowed by {0} at bp {1}".format(third_condon(gene_sequence),str(location_of_gene+6)))

    upstream =find_upstream(dna_sequence)
    print('\nUpstream sequence: '+upstream)
    print('Upstream length:   {0} bp'.format(str(len(upstream))))

    print('\nGene sequence: '+gene_sequence)
    print('Gene length:   {0} bp'.format(str(len(gene_sequence))))
    print('[+ Strand]: '+gene_sequence)
    print('            '+'|'*len(gene_sequence))
    print('[+ Strand]: '+complementary_sequence(gene_sequence))

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source