Skip to content

Topic 3 assignment

davidaray edited this page Jan 5, 2025 · 3 revisions

Write a python script that will accomplish the following:

  1. Take in a fasta file containing several sequences of varying length. File to be provided below.
  2. For each sequence in the file, calculate the GC content.
  3. For each sequence in the file, determine if the GC content is higher than 40%.
  4. Based on this criterion, write out two files: sequences with GC content higher than 40% and sequences with GC content less than or equal to 40%.
  5. Provide output to the screen to let the user know what's happening.

gc_fasta.fa

>seq_1
ACATACCATGAGACTTCCAGGCACCTCGCCGCGAAGGCCAGCCTTCGGGCAGCACGAGGACCGTCA
>seq_2
TCAAGACAACAATTTAAGATTTGTTTATGATTTTGAATGTATGTTAATAGAAAGTTAACTTTAGGCCAAAAATTCAGAGATTCTAATT
>seq_3
CAACGACTATCGCGATGCCCGACCCACAAAGCGCGTACCTAGTGTCGGCGACGTCCCAGC
>seq_4
TCAAGAGATACAATAAATAGAATCTGTAAAAGATATATTAATTGTAGAATAACAATAATCCAGTGTCAA
>seq_5
GCGAGGCCCTCTGGTCCGCGCGGTCGAGTGGCCCCATGGCGGCGTGAGCCATGGGCACACGGACGCGGATCT
>seq_6
AGTAATATTTTTTTGTTTTTTCGAGAATGCCTCAATTAGTTGAATAGTATGTATATTCAGTTGAACCATAAATATAGTGTGATTTTTTCTTAAGTTGT
>seq_7
CGTTGGTCCCCCTCCCCGGTGAGCCGGTCGCCGCGCCCGGCGCCGTCGCCGCCGCCAACGGGCGG
>seq_8
TTAATGTATCAATATTAAAACATTTATATTCAAGTTATACGTAGCGAATACTTCTAACAGTTACTTGTTAAATACCAGACAAATACCGTTTAACTATAAA
>seq_9
GCCAGTCTCCCCCGGGTTTCTTGCCGCCGACGGGTAGTCATTCAAGCCGGAGCGAGGCTGCCCCCAGACCCCGACCAGCTGGAAGGCCGGGGGCC
>seq_10
TGGGTCAAGAGAGTAGTAAAATTGAGCCCTTAAAATTAGGTAGCCCTTAAATTGTCGTATGAGACGGATACATTT

Potential algorithm and helpful hints:

  1. Take in a fasta file given to you in the exercise. (See week 1.)

  2. Initiate lists for sequences belonging to each category, 40+ and <=40.

  3. Initiate a for loop to read each sequence in the file.

    We haven't covered this in class. https://www.w3schools.com/python/python_for_loops.asp

  4. Calculate GC content (as a percentage) for each sequence

    Using the built-in length function might be helpful here. https://www.w3schools.com/python/ref_func_len.asp

  5. Use if, else statements to evaluate GC content. (append() will be helpful here.)

  6. Write out the lists to separate files, depending on the GC content.

  7. Upload your code to blackboard at least 24 hour prior to the next class.

Clone this wiki locally