224k views
0 votes
Implement a program called genes.py that does the following: a. Reads a DNA sequence t as command-line argument b. Reads strings (one by one) representing genes from standard input until EOF (use the functions stdio.isEmpty() and stdio.readString()), and for each string s i. Constructs a Gene object g from s ii. Writes g iii. Writes whether g contains the DNA sequence t or not c. Writes the percentage of genes that contain t, up to two decimal places

1 Answer

2 votes

Answer:

Following are the code to this question:

import sys#import package sys

class Gene:#defining a class Gene

gString = ""#defining a string variable

def __init__(self, gString):#defining a constructor

self.gString = gString#defining object to hold string value

gCount = 0#defining integer variable

mCount = 0#defining integer variable

t = input();#input value from user end

for s in sys.stdin:#defining for loop to check input value

g = Gene(s)#defining g variable to pass value in class parameter

gCount +=1#incrementing the value of gCount variable

if(t in s):#defining if block to check input

mCount +=1#incrementing the matchCount value

print( g.gString,"True")#print value True

else:#else block

print( g.gString,"False")#print value False

print("{:.2f}".format(mCount*100/gCount))#print percentage value

Output:

Please find attachment file.

Step-by-step explanation:

In the code, a class Gene is declared, that defines a string variable geneString, and creates its constructor, and store the string variable value.

In the next step, a three-variable gCount, mCount, and t defined, in which variable "t" is used for an input value, and inside the for loop, it uses the conditional statement, that checks its value and increments the integer value, and print true or false as a message.

Implement a program called genes.py that does the following: a. Reads a DNA sequence-example-1
User Cryptomanic
by
5.1k points