Python code and the code should be for beginners and simple and pls explain each
ID: 3592110 • Letter: P
Question
Python code and the code should be for beginners and simple and pls explain each step, try to make the code consist simple python functions
DNA Sequencing This assignment deals with DNA sequencing. A DNA sequence is a series of nucleotides: adenine (A). guanine (G), cytosine (C) and thymine (T). These sequences can be represented as strings of their first e.g., GCACTAG. Within these DNA sequences, researchers are interested in finding specific genic sequences (genes). The input we receive from DNA sequencers usually comes in a continuous stream, so the string may start with some upstream sequence (data from a previous gene), and may ontinue beyond the end of the specific gene that is of interest with a downstream sequence (the start of another gene). Fortunately, all genes start with the sequence ATG, and the sequence ATG cannot appear in the middle of a gne 1. This makes it possible to isolate and analyze a specific gene from a sequence. Your Tasks For this assignment, you will be required to build the following 5 functions: split-input: Takes in a DNA sequence (as described above) and returns a list with three elements. the upstream data, the gene (if any is found, or an empty string if no gene is found), and the downstream data, in that order .get-gene: Takes in a DNA sequence (as described above) and returns a string representation of the gene if one is present, or the string ERROR if no gene is present. validate-gene: Takes in a string representation of a gene, and returns True iff the gene presented is valid. For a gene to be valid it must satisfy the following critera: - It must start with the start codon (3 character sequence) ATG -It must contain at least one codon after the start codon - It must contain only full codons i.e, it cannot end mid-way through a 3 character codon) -It must never contain four consecutive identical nucleotides Note This isn't actually true in the real world, bat it makes our lives a lot eases, so we'll pretend is.palindromic. Takes a string representation of a gene, and returns True iff that gene is palindrome (reads the same forwards as backwards). · evaluate.sequence: Takes in a DNA sequence (as described above) and retums one of the follow ing strings as appropriate: No Gene Found, Invalid Gene, Valid Gene Found, Valid Palindromic Gene FoundExplanation / Answer
#Split the sequence
def split_input(seq):
#Declare lst
lst=[]
#find upstream position
upsPos = seq.find("ATG")
#Find uptream
upstream = seq[0:upsPos]
#Find downstream position
downPos = seq[upsPos+2:len(seq)].find("ATG")
#Find gene
gene = seq[upsPos:upsPos+downPos+2]
#Find down stream
downstream = seq[upsPos+downPos+2:len(seq)]
#Call function
if not validate_gene(gene):
#Set gene to empty
gene = ""
#append upstream
lst.append(upstream)
#append gene
lst.append(gene)
#append downstream
lst.append(downstream)
#return list
return lst
#define method to get gene from DNA sequence
def get_gene(seq):
#Call Function
lst = split_input(seq)
#check gene is not present
if not lst[1]:
#Return error
return "ERROR"
#Else
else:
#return gene
return lst[1]
#Define method to validate the gene
def validate_gene(gene):
#Find start codon
stPos = gene.find("ATG")
#check start codon is not in position
if stPos != 0:
#return false
return False
#check atleast two codon present
if len(gene)>=6:
#if full codon
if len(gene)%3==0:
#check for nucleotides
if gene.find("AAAA")!=-1:
return False
elif gene.find("GGGG")!=-1:
return False
elif gene.find("CCCC")!=-1:
return False
elif gene.find("TTTT")!=-1:
return False
else:
return True
#else
else:
#Return false
return False
#Else
else:
#Return false
return False
#define method to check for palidrome gene
def is_palindromic(gene):
#reverse the gene
revGene = gene[::-1]
#check condition
if(gene==revGene):
#Return true
return True
#return False
return False
#define method to evaluate the sequence
def evaluate_sequence(seq):
#Call Function
lst = split_input(seq)
#Check gene is not present
if not lst[1]:
return "No Gene Found"
#Validate gene
if not validate_gene(lst[1]):
return "Invalid gene"
else:
#Call Function
if is_palindromic(lst[1]):
return "Valid Palindromic Gene Found"
else:
return "Valid Gene Found"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.