Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带回流的管道破裂_Python_Python 2.7 - Fatal编程技术网

Python 带回流的管道破裂

Python 带回流的管道破裂,python,python-2.7,Python,Python 2.7,新手问题在这里 我有以下两个函数——第一个“read_fq_entry”,从subprocess.Popen(系统调用zcat并对其进行管道处理)读取行,并以列表的形式一次返回四行 第二个“stream_fq”从第一个获取返回的输出,并暂时打印它。(最终,我将随机抽取一组行并将它们写入文件 问题是,第一个函数中的返回破坏了管道-知道如何不这样做吗 def read_fq_entry( process ): while ( True ): name

新手问题在这里

我有以下两个函数——第一个“read_fq_entry”,从subprocess.Popen(系统调用zcat并对其进行管道处理)读取行,并以列表的形式一次返回四行

第二个“stream_fq”从第一个获取返回的输出,并暂时打印它。(最终,我将随机抽取一组行并将它们写入文件

问题是,第一个函数中的返回破坏了管道-知道如何不这样做吗

 def read_fq_entry( process ):

        while ( True ):
            name   = process.stdout.readline()       
            seq    = process.stdout.readline()
            strand = process.stdout.readline()
            qual   = process.stdout.readline()

            if ( not name or name == '') :
                return []

            return [name, seq, strand, qual]


 def stream_fq(infile1, infile2, Nr_of_reads):


        proc1 = subprocess.Popen("zcat " + infile1, stdout=subprocess.PIPE, shell=True)
        proc2 = subprocess.Popen("zcat " + infile2, stdout=subprocess.PIPE, shell=True)

        while ( True ):

            fq_1_entry = read_fq_entry(proc1)
            fq_2_entry = read_fq_entry(proc2)
            print fq_1_entry
            print fq_2_entry

返回[name,seq,strand,qual]
循环中,而True:
循环。您应该将其上移一级,或者也许可以将
return
语句改为
yield
语句。

这没有帮助。OP需要一个生成器,但这是一个主要的重写。Define generator-可以在需要时重写,寻找最佳的解决方案ons。这可能与您的问题无关,但
not name或name==''
是多余的,因为
not name
name
为空字符串时计算结果为True。如果不是name:将其缩短为
,则会产生相同的效果。感谢Kevin-优秀的tipWrite
stream_fq
send
行如果我在我的办公桌上,我会举个例子来回答,希望这能帮助你。