PYTHON
The text file motifFinding.txt contains two strings of DNA code, separated by a new-line character. Write a program that opens the file, and stores its contents into two strings, s and t, respectively. Write code that will find all instances of the string t within the string s. At the end, your program should output the number of times the sub-string t occurs within s, along with the index of the starting position of each occurrence of t within s. You should not use any built-in Python string methods except len(<string>) to complete this project, but you may use string-slicing as needed.
NOTE: Depending on how you read the data from the file, you may also need to use the string method, rstrip() to clear white space. Using this method as needed is fine for this project.
Output example:
The sub-string t occurs 4 times within the string s at starting positions indexed at 7, 19, 28 & 59.
Your code should be independent of the two strings s and t, and it should work for any two strings given in a different text file, as long as that file has the the same format as motifFinding.txt
motifFinding.txt :
CTCATGGTTTTCATGGTTCATGGTAGTTCGCCACGATCTGACTGTCATGGTTCATGGTTCATGGTGTCATGGTG
AGTCAAGTCATGGTCCCCTCATGGTATCATGGTAAAAAATAAAGCGATGATCATGGTGTCATGGTGTCATGGTG
ATCATGGTTCATGGTCTCTGTCATGGTGCGGTCATGGTGTGCCATGCTTTCATGGTTCATGGTATCATGGTTCA
TGGTTCATGGTACTGTCATCATCATGGTCAGTCATGGTTCATGGTTCTCATGGTCGATCATGGTTCATGGTTTT
GAGATCATGGTTTCATGGTGTAGTCATGGTCTGCTCATGGTTCATGGTTGTTTCATGGTAAATTCATGGTTTCA
TGGTTCATGGTGCAGCATCATGGTACGTCATGGTTGGTCATGGTATGTATCATGGTTACGATCATGGTGTTAAC
TTTCATGGTCTCATGGTGTTGCAGGGCATGTCTCTCTTATTGGCTTCATGGTATCATGGTTTATCATGGTATCC
TCCTCATGGTAGTTCATGGTCATCATGGTACCATCATGGTCGGATCATGGTTTCATGGTTCATGGTTCATCATG
GTTCATGGTCTTTATCATGGTTCATGGTGTTTCATGGTTGTCATGGTTTCATGGTCATGTCATGGTATATCATG
GTGGGCTCATGGTTCATGGTCTCATGGTATCATGGTATCATGGTCGAGTCATGGTCTTCATGGTTTTTAATCAT
GGTGATCATGGTTCATGGTGCTAAAGTTCATGGTACGTCATGGTTCATGGTTCATGGTTTGGCACGATCATGGT
CTAAATCATGGTATTCATGGT
TCATGGTTC
![Python 3.7.4 (default, Jul 9 26 [GCC 6.3.0 20170516] on linux At index 10 main.py GTGTCATGGTG AGTCAAGTCATGGTCCCCTCATGGTATCATG](http://img.homeworklib.com/questions/2182ee30-7f99-11eb-ba6e-1f9e8db91419.png?x-oss-process=image/resize,w_560)
def readFile(fName):
lines = open(fName, 'r').readlines()
lines = [l.rstrip() for l in lines]
newLineIndex = lines.index('')
s = ''.join(lines[:newLineIndex])
t = ''.join(lines[newLineIndex+1:])
return (s, t)
def countOccurrence(s, t):
count = 0
for i in range(len(s)):
if s[i:i+len(t)] == t:
print('At index', i)
count += 1
print('Pattern occurs', count, 'times')
s, t = readFile('motifFinding.txt')
countOccurrence(s, t)
My results are difference because i used a different file probably.. I am assuming that in the file, there will be one line which is blank and that separates the two strings.. If any issues, please share the link to your text file. thanks!
PYTHON The text file motifFinding.txt contains two strings of DNA code, separated by a new-line character....
python
Create a program to open a text file for reading, find the maximum number in the file, determine if that maximum number is even, and write to an output text file. You should either write Yes if the number is even, otherwise write the maximum number. You should note the following: • Your input file must be named input.txt • The input file has one integer number per line • Your output file must be named output.txt • Your...
Python code
Write a program that will ask the user to input two strings, assign the strings to variables m and n If the first or second string is less than 10 characters, the program must output a warning message that the string is too short The program must join the strings m and n with the join function The output must be displayed. Please name the program and provide at least one code comment (10)
In Python Provide me with your code file, output file and the text file Create a file having different integers than the first one. Save it as numbers1. txt . Write a program that reads all the number and calculates their average. Important: The two files that you are creating will contain different numbers.
Python Programming Write a program that counts how often a word occurs in a text file. Input: Ask the user for the name of an ASCII text file. Output: Display the numbers of top frequently appeared words and their frequencies. Pseudocode: 1) Read the file 2) Split the file into words 3) Count each word 4) Sort the words by frequencies, starting with the most frequent ones 5) Internally you should use some sort of data structure to keep track...
Description: Merge two or more text files provided by the user into a new text file where the names of the text files to join and the output text file are provided to the program using command line arguments. Purpose: This application provides experience working with command line arguments, writing files to disk, reading files from disk, working with exceptions, and writing programs in C#/.NET. Requirements: Project Name: DocumentMerger2 Target Platform: Console Programming Language: C# In a previous challenge, Document...
1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat, a recursive function that takes two alphabetically-ordered strings and merges them, leaving the letters in alphabetical order. Note that the strings may be different lengths. a main method that inputs two ordered strings and calls the orderedConcat method to return a resulting merged, ordered string. Your main method should print the two input strings and the result. Note: You may not use any of...
Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...
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...
Create a python code named LetterCount with a text file named words.txt that contains at least 100 words in any format - some words on the same line, some alone (this program involves no writing so you should not be erasing this file). Then create a program in the main.py that prompts the user for a file name then iterates through all the letters in words.txt, counting the frequency of each letter, and then printing those numbers at the end...
Python: Using your favorite text editor, write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Submit by uploading a .py file Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"...