问题描述:

I am struggling for creating python script in Linux terminal. I am trying to make command to analyze hundreds of files.

And there is a python program(ngCGH) which analyze bam.file. ngCGH's command is following:

ngCGH -o /mnt/data/A/B/C.txt [normal.bam] [tumor.bam]

Two .bam files have following naming role

1N-------.bam

1T-------.bam

2N-------.bam

2T-------.bam

In short, files having matched number should be analyzed.

In addition, I want to make output file name differently like in following way.

1N------.bam 1T------.bam

Result: 1NT analysis.txt

2N------.bam 2T------.bam

Result: 2NT analysis.txt

The output files should be txt files having different names.

网友答案:
import os
j = 1
files = set(x[2:len(x)-4] for x in os.listdir() if x.endswith('.bam'))

for i in files:
    command = 'ngCGH -o <path>/'+str(j)+'NT analysis.txt '+str(j)+'N'+i+'.bam '+str(j)+'T'+i+'.bam'
    os.system(command)

replace <path> with actual path.

Hope this was what you were expecting.

相关阅读:
Top