Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Constants MIN _ CODONS = 5 MIN _ MASS _ PERCENTAGE _ CG = 3 0 NUM _ NUCLEOTIDES = 4 NUCLEOTIDES _ PER

# Constants
MIN_CODONS =5
MIN_MASS_PERCENTAGE_CG =30
NUM_NUCLEOTIDES =4
NUCLEOTIDES_PER_CODON =3
# Function to convert a nucleotide into an index
def nucleotide_to_index(nucleotide):
nucleotide = nucleotide.upper()
nucleotide_index ={'A': 0,'C': 1,'G': 2,'T': 3}
return nucleotide_index.get(nucleotide,-1)
# Function to calculate nucleotide counts
def calculate_nucleotide_counts(sequence):
counts =[0]* NUM_NUCLEOTIDES
for nucleotide in sequence:
index = nucleotide_to_index(nucleotide)
if index !=-1:
counts[index]+=1
return counts
# Function to calculate mass percentages
def calculate_mass_percentages(sequence):
mass_values ={'A': 135.128,'C': 111.103,'G': 151.128,'T': 125.107,'-': 100.000}
# Filter out dashes ('-') before calculating total mass
total_mass = sum(mass_values[nucleotide] for nucleotide in sequence if nucleotide in mass_values)
nucleotide_counts = calculate_nucleotide_counts(sequence)
# Calculate mass percentages based on the total mass of the sequence
mass_percentages =[round((mass_values[nucleotide]* count / total_mass)*100,1) for nucleotide, count in zip("ACGT", nucleotide_counts)]
return mass_percentages, total_mass
# Function to extract codons from a sequence
def extract_codons(sequence):
valid_sequence =[nucleotide for nucleotide in sequence if nucleotide.isupper()]
codons =[''.join(valid_sequence[i:i + NUCLEOTIDES_PER_CODON]) for i in range(0, len(valid_sequence), NUCLEOTIDES_PER_CODON)]
return codons
# Function to check if a sequence is a protein
def is_protein(sequence):
start_codon = "ATG"
stop_codons =["TAA", "TAG", "TGA"]
# Check start codon
if not sequence.startswith(start_codon):
return False
# Check stop codon
if not any(sequence.endswith(stop) for stop in stop_codons):
return False
# Check minimum codons
if len(extract_codons(sequence))< MIN_CODONS:
return False
# Check minimum mass percentage of C and G
cg_mass_percentage = sum(calculate_mass_percentages(sequence)[1:3])
if cg_mass_percentage < MIN_MASS_PERCENTAGE_CG:
return False
return True
# Function to process a nucleotide sequence
def process_sequence(region_name, nucleotides):
nucleotide_counts = calculate_nucleotide_counts(nucleotides)
mass_percentages, total_mass = calculate_mass_percentages(nucleotides)
codons_list = extract_codons(nucleotides)
is_protein_result = is_protein(nucleotides)
# Print or write to the output file
print(f"Region Name: {region_name}")
print(f"Nucleotides: {nucleotides}")
print(f"Nuc. Counts: {nucleotide_counts}")
print(f"Total Mass%: {mass_percentages} of {total_mass:.1f}")
print(f"Codons List: {codons_list}")
print(f"Is Protein?: {'YES' if is_protein_result else 'NO'}
")
# Main function
def main():
print("This program reports information about DNA nucleotide sequences that may encode proteins.")
# Input file names
input_file_name = input("Input file name? ")
output_file_name = input("Output file name? ")
# Process input file
with open(input_file_name, 'r') as input_file:
# Assume each pair of lines represents a region name and nucleotide sequence
lines = input_file.readlines()
for i in range(0, len(lines),2):
region_name = lines[i].strip()
nucleotides = lines[i +1].strip().upper()
process_sequence(region_name, nucleotides)
if __name__=="__main__":
main() what is the pseudocode and flowchart for this python code?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Th ey have to wait a long time for an appointment?

Answered: 1 week ago