Merging list of bam files with samtools merge
1
0
Entering edit mode
6.7 years ago
Bella_p ▴ 70

Hi,

I want to merge list of bam files (after I already sorted them previously) using samtools merge. I have a list of bam files that I want to sent from python to the following command in bash:

${samtools} merge - ${bam_source}/${sample_name}.merged.bam

Will samtools work with list from python as input? is the above scrips in general OK?

Thanks!

python bash samtools • 8.3k views
ADD COMMENT
1
Entering edit mode

I don't see python code in your example.

ADD REPLY
0
Entering edit mode
6.7 years ago
h.mon 35k

No, it won't work, because you are swapping input and output:

samtools merge <out.bam> <in1.bam> [<in2.bam> ... <inN.bam>]

Besides, venu has a point, you don't show how you plan to use python.

ADD COMMENT
0
Entering edit mode

my python script is:

bam_files_list = [file for file in os.listdir(bam_file_path) if file.endswith(".bam")]
subprocess.call([".merge_and_remove_dup.sh", bam_files_list, sample_name],shell=False)

Then the bash command. So you say I need to convert the list to sequence of strings (names of the files)?

ADD REPLY
0
Entering edit mode

So you say I need to convert the list to sequence of strings (names of the files)?

Don't put words on my mouth! ;-)

I really don't know python, all I said is:

1) you asked how you could do something with python, but didn't show any python code,
2) it appears to me your command is samtools merge input output, whereas the correct is samtools merge output input.

What I will say, though, is that I don't understand why do you need to wrap a simple samtools merge around a bash script, then wrap this bash script around python.

ADD REPLY
0
Entering edit mode

Thanks, it won't solve my problem, but it seems that I did confused the output input. The python script is long, so I wrote only the relevant lines from it. It does other things then just merge, so it's easier for me to send from it to simple bash script for merge, and the rest, with python.

ADD REPLY

Login before adding your answer.

Traffic: 1673 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6