Question

Objective: Practice Displaying Output with print Function, Comments, Variable, Reading Input from the Keyboard, format output

Example of motifs.txt: SLR ADSS GLGE SSSID Your task is to search for each motif in the motifs.txt file and 1. Create an outp

# of Sequences: head motifADSS.txt >ENSG00000115275 ENSTO0000233616 WVLAWYRARRAVTLHSAPPVLP ADSS SPAVAPDLFWGTYRPHVYFGMKTRSPKPL

in Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Open the Motifs file - Give the correct file name for Motifs  here.
motiffile=open("C:\Tmp\Motifs.txt","r")

#list to store the motifs file pointers
motiflist=[]

#list to store the motifs names
motifnames=[]

#list to store counts of each motif
motifcounts=[]

#read motifs file
for motif in motiffile:
    motif=motif.rstrip("\n")
    if (motif and motif.strip()):
        ## change path as you wish
        fname="C:\Tmp\motif"+motif.rstrip("\n")+".txt"
        motiflist.append(open(fname,"w+"))
        motifnames.append(motif)

# close the motiflist file now
motiffile.close()
motifcounts=[0]*len(motifnames)


# Read the sequence file
seqfile = open("/nfshome/raltobasei/public_html/1170/public/human_aa_chr2_partial.txt","r")

# for each line check if the pattern matches the motif
for line in seqfile:
    line=line.rstrip("\n")
    if line.startswith(">"):
       seqline=line
       continue
    else:
        i=0
        for motif in motifnames:
                pos=line.find(motif)
                # if motif is found then write sequences and the line
                j=motifcounts[i]
                if (pos!=-1):
                    nline = line[0:pos - 1] + " " + motif + " " + line[pos + len(motif):]
                    fname = motiflist[i];
                    fname.write(seqline + "\n")
                    fname.write(nline+"\n")
                    j=j+1
                motifcounts[i] = j    # update counts
                i=i+1


## write counts to files
k=0
for motiffile in motiflist:
    motiffile.write("# of motifs for " + motifnames[k] +" :" + str(motifcounts[k]))
    k=k+1
    motiffile.close()

## close the sequential file 
seqfile.close()




Add a comment
Know the answer?
Add Answer to:
in Python Objective: Practice Displaying Output with print Function, Comments, Variable, Reading Input from the Keyboard,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Programming help, please include comments to help me understand the code. Thank you for helping....

    C++ Programming help, please include comments to help me understand the code. Thank you for helping. Task C: Substitution and Hamming Distance For this task, we will explore mutations that occur by substitution. Your task is to write a program called hamming.cpp that calculates the Hamming distance between two strings. Given two strings of equal length, the Hamming distance is the number of positions at which the two strings differ. e. g.: Hamming("aactgc", "atcaga") would output 3. Notice that certain...

  • Write a function template that receives a priority queue and an output stream as parameters. Lab 48 Due Date: See Blackboard Source File: /2336/48/1ab48.cpp Input: Output:under control of main functio...

    Write a function template that receives a priority queue and an output stream as parameters. Lab 48 Due Date: See Blackboard Source File: /2336/48/1ab48.cpp Input: Output:under control of main function Waol under control of main function Write a function template that receives a priority queue and an output stream as parameters. The function determines the distribution of the elements in the priority queue; that is, the function counts the number of occurrences of each element. The format of the output...

  • C++: Translating mRNA sequence help Homework Description Codon 1 You are working in a bioinformatics lab...

    C++: Translating mRNA sequence help Homework Description Codon 1 You are working in a bioinformatics lab studying messenger RNA (mRNA) sequences. mRNA is a sequence of the nucleotide bases (Adenine, Cytosine, Guanine, and Uracil) that conveys information stored in DNA to Ribosomes for translation into proteins. The bases in the sequences are denoted by the first letters of the nucleotide bases (e.g. A, C, G, and U). A sequence of mRNA is made up of hundres to thousands of nucleotide...

  • C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the r...

    C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything.     Your function should be named...

  • Using c 3 File Input & Data Processing Reading data from a file is often done in order to pro...

    using c 3 File Input & Data Processing Reading data from a file is often done in order to process and aggregate it to get ad- ditional results. In this activity you will read in data from a file containing win/loss data from the 2011 Major League Baseball season. Specifically, the file data/mlb_nl_2011.txt contains data about each National League team. Each line contains a team name fol- lowed by the number of wins and number of losses during the 2011...

  • Write a program, called wordcount.c, that reads one word at a time from the standard input....

    Write a program, called wordcount.c, that reads one word at a time from the standard input. It keeps track of the words read and the number of occurrences of each word. When it encounters the end of input, it prints the most frequently occurring word and its count. The following screenshot shows the program in action: adminuser@adminuser-VirtualBox~/Desktop/HW8 $ wordCount This is a sample. Is is most frequent, although punctuation and capitals are treated as part of the word. this is...

  • The following code uses a Scanner object to read a text file called dogYears.txt. Notice that...

    The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...

  • 2. A dominant allele H reduces the number of body bristles that Drosophila flies have, giving...

    2. A dominant allele H reduces the number of body bristles that Drosophila flies have, giving rise to a “hairless” phenotype. In the homozygous condition, H is lethal. An independently assorting dominant allele S has no effect on bristle number except in the presence of H, in which case a single dose of S suppresses the hairless phenotype, thus restoring the "hairy" phenotype. However, S also is lethal in the homozygous (S/S) condition. What ratio of hairy to hairless flies...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT