batch script in python

#!/usr/bin/env python
import os,re,sys,string,commands,getopt,subprocess,glob
from os import path
#/disk/rdisk08/mhyleung/loreal_shotgun2/NovaSeq_new/decontam_output_genome/paired_completed/szy_test
#LOR294C_S130_R1_001_kneaddata_paired_1_decontaminated.fastq.paired.fq.gz

#LOR294C_S130_R1_001_kneaddata_paired_1.fastq.gz
#metawrap binning -o /home/mhyleung/workspace/loreal_shotgun2/NovaSeq_new/metawrap_assembly_R2/LOR303C -t 16 -a /home/mhyleung/workspace/loreal_shotgun2/NovaSeq_new/metawrap_assembly_R2/LOR303C_S134_R1_001_kneaddata_paired/LOR303C_final_assembly.fasta –maxbin2 –metabat2 –concoct /disk/rdisk08/mhyleung/loreal_shotgun2/NovaSeq_new/decontam_output_genome/paired_completed/szy_test/LOR303C_S134_R1_001_kneaddata_paired_*.fastq
#host = subprocess.Popen([‘host’, target], stdout = subprocess.PIPE).communicate()[0]
#p1 = subprocess.Popen([‘ping’, ‘-c 2′, host], stdout=subprocess.PIPE)

 

 

def main():
for d in os.listdir(‘/disk/rdisk08/mhyleung/loreal_shotgun2/NovaSeq_new/decontam_output_genome/paired_completed/szy_test’):
#print(d)
if re.search(“_1.fastq”, d):
a = []
a = re.split(“_”,d)
b = re.split(“kneaddata_paired”, d)
outputfile = “/home/mhyleung/workspace/loreal_shotgun2/NovaSeq_new/metawrap_assembly_R2/” + a[0]
assemfasta_file = “/home/mhyleung/workspace/loreal_shotgun2/NovaSeq_new/metawrap_assembly_R2/”+a[0]+”_”+a[1]+”_”+a[2]+”_”+a[3]+”_”+a[4]+”_”+a[5]+”/”+a[0]+”_final_assembly.fasta”
fastq_file = “/disk/rdisk08/mhyleung/loreal_shotgun2/NovaSeq_new/decontam_output_genome/paired_completed/szy_test/” + b[0] +”kneaddata_paired_*.fastq”
fastq_file1 = “/disk/rdisk08/mhyleung/loreal_shotgun2/NovaSeq_new/decontam_output_genome/paired_completed/szy_test/” + b[0] +”kneaddata_paired_1.fastq”
fastq_file2 = “/disk/rdisk08/mhyleung/loreal_shotgun2/NovaSeq_new/decontam_output_genome/paired_completed/szy_test/” + b[0] +”kneaddata_paired_2.fastq”
fastq_file1_gz = “/disk/rdisk08/mhyleung/loreal_shotgun2/NovaSeq_new/decontam_output_genome/paired_completed/szy_test/” + b[0] +”kneaddata_paired_1.fastq.gz”
fastq_file2_gz = “/disk/rdisk08/mhyleung/loreal_shotgun2/NovaSeq_new/decontam_output_genome/paired_completed/szy_test/” + b[0] +”kneaddata_paired_2.fastq.gz”
command_line = ” metawrap binning -o ” + outputfile + ” -t 10 -a ” + assemfasta_file + ” –maxbin2 –metabat2 ” + fastq_file
print command_line
#tar_command_line1 = “–remove-files -zcvf ” + fastq_file1_gz + ” ” + fastq_file1
#tar_command_line2 = fastq_file2_gz + ” ” + fastq_file2
subprocess.Popen([‘gunzip’, fastq_file1_gz], stdout = subprocess.PIPE).communicate()[0]
subprocess.Popen([‘gunzip’, fastq_file2_gz], stdout = subprocess.PIPE).communicate()[0]
subprocess.Popen([‘metawrap’,’binning’,’-o’, outputfile,’-t 10′,’-a’, assemfasta_file, ‘–maxbin2′, ‘–metabat2′, fastq_file], stdout = subprocess.PIPE).communicate()[0]
subprocess.Popen([‘tar’, ‘–remove-files’, ‘-zcvf’, fastq_file1_gz, fastq_file1], stdout = subprocess.PIPE).communicate()[0]
subprocess.Popen([‘tar’, ‘–remove-files’, ‘-zcvf’, fastq_file2_gz, fastq_file2], stdout = subprocess.PIPE).communicate()[0]

work_files_path = outputfile + “/work_files”
subprocess.Popen([‘rm’,’-rf’, work_files_path], stdout = subprocess.PIPE).communicate()[0]

# os.system(‘gunzip newname’)
#for file in glob.glob(“*.fasta”):
# os.rename(“final_assembly.fasta”, newname)
#os.chdir(‘/home/mhyleung/workspace/loreal_shotgun2/NovaSeq_new/metawrap_assembly_R2/’)
#change_dir = os.system(‘pwd’)
#print change_dir
#os.chdir(change_dir)

if __name__== ‘__main__':
main()

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>