I am able to convert .bw files to .fq(fastq) manually in Shell, but I would like to automate the process coz I have hundreds of .bw file that I need to convert. Till now, I could think of following script, but unable to solve the problem. The .bw files are in H3K27ac folder.
import subprocess
path_bw = "~/Documents/H3K27ac"
import os
files = os.path.expanduser(path_bw)
for file in files:
if file.endswith('.gz'):
files.remove(file)
files = [x[:-3] if x.endswith('.bw') else x for x in files]
# for .bw files
for file in files:
bigwigtowig = "bigWigToWig " + path_bw + file + ".bw " + path_bw + file +".wig"
subprocess.call(bigwigtowig, shell=True)
wigtobed = "wig2bed < " + path_bw + file + ".wig > " + path_bw + file + ".bed"
subprocess.call(wigtobed, shell=True)
getfasta = "bedtools getfasta -fi " + path_bw + "hg19.fa -bed " + path_bw + file + ".bed -fo " + path_bw + file + ".fa"
subprocess.call(getfasta, shell=True)
perl = "perl " + path_bw + "fasta_to_fastq.pl" + path_bw + file + ".fa > " + path_bw + file + ".fq"
#os.system(perl)
subprocess.run(perl, shell=True)
Manually, I used the following to convert the .bw files:
# bigWigToWig file1.bw fileout.wig
# wig2bed <fileout.wig> fileout.bed
# bedtools getfasta -fi hg19.fa -bed fileout.bed -fo fileout.fa
# perl fasta_to_fastq.pl fileout.fa > file1.fq
All the above packages were preinstalled via shell and works perfectly. hg19 is the genom that i am using. fasta_to_fastq.pl is openly available in github and helps to convert .fa to .fq.
MAin thing i require is to convert all the files from .bw to .fq and this is the only way in my research that i could find. I need all the names to be the same as output. For example file1.bw shoud be file1.fq , file2.bw --> file2.fq and so on.
Do you have any ideas if this is possible or are there easier ways to convert it? It would be awesome to know your view point.