I am trying to unzip fasta.gz files in order to work with them. I have created a script using cmd base on something I have done before but now I cannot manage to work the newly created function. See below:
import glob import sys import os import argparse import subprocess import gzip #import gunzip def decompressed_files(): print ('starting decompressed_files') #files where the data is stored input_folder=('/home/me/me_files/PB_assemblies_for_me') #where I want my data to be output_folder=input_folder + '/fasta_files' if os.path.exists(output_folder): print ('folder already exists') else: os.makedirs(output_folder) print ('folder has been created') for f in input_folder: fasta=glob.glob(input_folder + '/*.fasta.gz') #print (fasta[0]) #sys.exit() cmd =['gunzip', '-k', fasta, output_folder] my_file=subprocess.Popen(cmd) my_file.wait decompressed_files() print ('The programme has finished doing its job') But this give the following error:
TypeError: execv() arg 2 must contain only strings
If I write fasta, the programme looks for a file an the error becomes:
fasta.gz: No such file or directory
If I go to the directory where I have the files and I key gunzip, name_file_fasta_gz, it does the job beautifully but I have a few files in the folder and I would like to create the loop. I have used 'cmd' before as you can see in the code below and I didn't have any problem with it. Code from the past where I was able to put string, and non-string.
cmd=['velveth', output, '59', '-fastq.gz', '-shortPaired', fastqs[0], fastqs[1]] #print cmd my_file=subprocess.Popen(cmd)#I got this from the documentation. my_file.wait() I will be happy to learn other ways to insert linux commands within a python function. The code is for python 2.7, I know it is old but it is the one is install in the server at work.