unmap2virus_bams = extract_bam(sorted_bams,'unmap',seqType,thread) # [file.sort.unmap2host.sort.unmap.bam] # rename files for f in map2virus_bams: os.rename(f,f[:-29]+'.only2virus.bam') map2virus_bams = [f[:-29]+'.only2virus.bam' for f in map2virus_bams] # [file.only2virus.bam] for f in unmap2virus_bams: os.rename(f,f[:-31]+'.map2neither.bam') # [file.map2neither.bam] unmap2virus_bams = [f[:-31]+'.map2neither.bam' for f in unmap2virus_bams] print 'extract map and unmap2virus_bams succeed' print 'map2virus_bams is: ',map2virus_bams,'unmap2virus_bams is: ',unmap2virus_bams remove(sorted_bams) except: print 'extract map and unmap2virus_bams failed' Message('extract map and unmap2virus_bams failed',email) raise #======== (4) transfer the mapped and unmapped to virus bam to fastq ======= try: map2virus_fq_gzs = sam2fastq(picard,map2virus_bams,seqType) # [[file.only2virus.fq.gz]] unmap2virus_fq_gzs = sam2fastq(picard,unmap2virus_bams,seqType) # [[file.map2neither.fq.gz]] print 'transfer from bam to fq succeed' print 'map2virus_fq_gzs is: ',map2virus_fq_gzs,'unmap2virus_fq_gzs',unmap2virus_fq_gzs remove(map2virus_bams);remove(unmap2virus_bams) except: print 'transfer from bam to fq failed' Message('transfer from bam to fq failed',email) raise #======== (5) transfer the unmapped to virus fastq to fasta ================= try: only2virus_faFiles = fq2fa(map2virus_fq_gzs) # [file.only2virus.fa.gz] map2neither_faFiles = fq2fa(unmap2virus_fq_gzs) # [file.map2neither.fa.gz] print 'fq files to fa files succeed' print 'only2virus_faFiles is: ',only2virus_faFiles,'map2neither_faFiles is: ',map2neither_faFiles remove(map2virus_fq_gzs); remove(unmap2virus_fq_gzs)
#======== (5) extract unmapped reads ============================= try: unmap2host_bams = extract_bam(sorted_bams,'unmap',seqType,thread) # [file.sort.unmap.bam] print 'extract unmap2host_bams succeed' print 'unmap2host_bams is: ',unmap2host_bams remove(sorted_bams) # rename files for f in unmap2host_bams: os.rename(f,f[:-4]+'2host.bam') unmap2host_bams = [f[:-4]+'2host.bam' for f in unmap2host_bams] # [file.sort.unmap2host.bam] except: print 'extract unmap2host_bams failed' Message('extract unmap2host_bams failed',email) raise #======== (6) unmap2host_bams to fastq ============================ try: unmap2host_fqs = sam2fastq(picard,unmap2host_bams,seqType) # [[file.sort.unmap2host.fq.gz]] print 'unmap2host_fq succeed' print 'unmap2host_fqs is: ',unmap2host_fqs remove(unmap2host_bams) except: print 'unmap2host_fq failed' Message('unmap2host_fq failed',email) raise #=========================================================================== # 2. Map to virus reference genome #=========================================================================== #======== (1) align unmap2host_fq to virus ========================= try: if aligner == 'gsnap': map_files = gsnap(unmap2host_fqs,virus_alignerDb, virus_gsnapDbName,virus_gsnapAnnotation,thread) else: