parsing fastq files in python
I have multiple fastq files for different samples. Example : S_Rep1_R1.fastq S_Rep1_R2.fastq S_Rep2_R1.fastq S_Rep2_R2.fastq I want to choose all fastq files corresponding to say S_Rep1 and execute some functions. How can I write a python script which will choose all fastq files belonging to S_Rep1.
• 4,160 views
•
link
3 answers
#!usr/bin/env python
import glob
for file in glob.glob('*S_Rep1*.fastq'):
*do some stuff*
• 0 views
•
link
You could also use any standard file parser with python
#!usr/bin/env python
f = open("fastq_file.fastq", "r")
for i in f.readilnes():
....
• 0 views
•
link
Here you go:
# importing os module
import os
# store the path of current directory in the variable 'cwd'
cwd = os.getcwd()
# loop over all files
for files in os.listdir(cwd):
# check if file is fastq by extension
if files.endswith(".fastq"):
# check if file name contains 'S_Rep1'
if 'S_Rep1' in files:
# do something here
print files
Keep calm and program ;)
• 0 views
•
link
Log in to answer this question.