def read(self, *args):
    ret = self.f1.read(*args)
if ret == '':
    ret = self.f2.read(*args)
return ret
fh_bam = open('output.bam', 'w')
params_0 = ['samtools', 'view', '-HS', 'header.sam']
params_1 = ['samtools', 'view', 'input.bam', '1:1-50000000']
params_2 = ['samtools', 'view', '-bS', '-']
sub_0 = subprocess.Popen(params_0, stderr=subprocess.PIPE, stdout=
    subprocess.PIPE)
sub_1 = subprocess.Popen(params_1, stderr=subprocess.PIPE, stdout=
    subprocess.PIPE)
sub_2 = subprocess.Popen(params_2, stdin=concat(sub_0.stdout, sub_1.stdout),
    stdout=fh_bam)
How to join the stdout of two subprocesses and pipe to stdin of new subprocess in python