Question

In: Computer Science

FASTQ to FASTA converter: Implement a FASTQ to FASTA file format converter in python (the input...

FASTQ to FASTA converter: Implement a FASTQ to FASTA file format converter in python (the input is a FASTQ file and the output is a FASTA file)

Solutions

Expert Solution

IF YOU HAVE ANY DOUBTS COMMENT BELOW

ANSWER:

AS FOR GIVEN DATA...

FASTQ to FASTA converter: Implement a FASTQ to FASTA file format converter in python (the input is a FASTQ file and the output is a FASTA file)

SOL::-

''' This is how you have to run the code on cmd

create one fastqToFasta.py with this code

then the fastq file with gz extension

and give the name of fasta file in the command '''

#python fastqToFasta.py fastq.gz fasta gz

import sys, subprocess, gzip
from subprocess import PIPE

infile = sys.argv[1]
fasta = sys.argv[2]
gz = sys.argv[3]

## if gz is present open it with the gzip library else normal
if '.gz' in infile:
   print("detected a .gz file")
   fastq = gzip.open(infile, 'rb')
else:
   fastq = open(infile, 'r')

## main function

def main(fastq, fasta, gz):
   line_n =0
   line_buffer = 0
   line_id = 1
   if gz: ### if gz argument is provided it will write out a gz file else normal
       outfile = gzip.open(fasta+'.gz', 'w')
   else:
       outfile = open(fasta, 'w')
   fastas = 1
   fasta_length =0
   for line in fastq:
       line_n += 1
           #line_id += 1
       if line_n == 10000:
           line_buffer += 10000
           line_n =0
           print ('processed lines ', line_buffer)
       if line_id == 4:
           line_id = 1
       elif line_id == 3:
           line_id += 1
       elif line_id == 2:
           line_id += 1
           fasta_line = line
           fasta_length += len(fasta_line.strip())
           outfile.write(fasta_line)
           fastas += 1
       else:
           if '@' not in line:
               print ('are you sure this is a fastq ??')
           else:
               fasta_header = line.replace('@', '>')
               line_id += 1
               outfile.write(fasta_header)
   outfile.close()
   print ('FASTA records written', fastas, 'average length of fasta sequences ', float(fasta_length//fastas))

if __name__ == '__main__':
   main(fastq, fasta, gz)

PLS RATE THUMBSUP....ITS HELPS ME ALOT...

THANK YOU...!!


Related Solutions

Implement in Python a script that does the following: 1) reads input from a supposed file...
Implement in Python a script that does the following: 1) reads input from a supposed file called firstnames_2.txt. 2) processes the input and writes and saves the output to a file. NOTE: Please make sure that the names are written in the outfile with one name on each line no comma ( , ) after the name in the output
[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
4.31 Implement function duplicate() that takes as input the name (a string) of a file in...
4.31 Implement function duplicate() that takes as input the name (a string) of a file in the current directory and returns True if the file contains duplicate words and False otherwise. duplicate('Duplicates.txt') True duplicate('noDuplicates.txt') False Please solve using Python Language and without using str.maketrans please. Just simple programming, Thank youuuuu!!!!!
In java please complete the following: A DNA sequence in FASTA format consists of a header...
In java please complete the following: A DNA sequence in FASTA format consists of a header line starting with a “>” sign, followed by a sequence identifier (GenBank Accession number, or clone name), and one or more lines of the sequence itself. Write a Java program to first prompt the user for a sequence identifier, such as “Enter a clone name: “, and then prompt for the DNA sequence. The program should print out a FASTA format sequence to the...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
PYTHON #What you need to do is to transform the file Mkt_data_test.txt #to the format like...
PYTHON #What you need to do is to transform the file Mkt_data_test.txt #to the format like in file in the screenshot # #Your steps to get there: #1.Create a header line with following columns: Time;Bid\Ask;Price;Volume. NOTE NO SPACES #2.Remove all of the timestamp lines, i.e ======== Data: ..... #3.Remove the 1900-01-01 from the timestamp but leave the time itself #4.Get rid of all spaces and empty lines #5.Replace 0 or 1 in the second position with Bid or Ask, Bid...
Implement an application that will read data from an input file, interpret the data, and generate...
Implement an application that will read data from an input file, interpret the data, and generate the output to the screen. - The application will have two classes, Rectangle and Lab2ADriver. - Name your Eclipse project, Lab2A. Implement the Rectangle class with the following description. Rectangle Data fields -numRows: int -numCols: int -filled: Boolean Store the number of rows in the Rectangle Store the number of columns in the Rectangle Will define either a filled or unfilled rectangle True =...
Write a python code to Design and implement a function with no input parameter which reads...
Write a python code to Design and implement a function with no input parameter which reads a number from input (like 123). Only non-decimal numbers are valid (floating points are not valid). The number entered by the user should not be divisible by 10 and if the user enters a number that is divisible by 10 (like 560), it is considered invalid and the application should keep asking until the user enters a valid input. Once the user enters a...
Python Implement function noVowel() that takes a string s as input and returns True if no...
Python Implement function noVowel() that takes a string s as input and returns True if no char- acter in s is a vowel, and False otherwise (i.e., some character in s is a vowel). >>> noVowel('crypt') True >>> noVowel('cwm') True >>> noVowel('car') False
Write a Python program called “exam.py”. The input file, “input.txt”, is given to you in the...
Write a Python program called “exam.py”. The input file, “input.txt”, is given to you in the Canvas exam instructions. Name your output file “output.txt”. Ensure the program consists of a main function and at least one other function. Ensure the program will read the input file, and will output the following information to the output file as well as printing it to the screen: output the text of the file to screen output the number of words in the file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT