简体   繁体   English

在内存中引用类似文件的对象

[英]reference file-like object in memory

I am using python to run a terminal program call bedtools. 我正在使用python运行终端程序调用bedtools。 Bedtools takes file names as arguments. Bedtools将文件名作为参数。 However, because I can only have 256 files open at once, I am limited in my multithreading ability. 但是,由于一次只能打开256个文件,因此我的多线程功能受到限制。 I was hoping to be able to send a file in memory to the terminal, but it doesn't have a name, like a SpooledTemporaryFile(). 我希望能够将内存中的文件发送到终端,但是它没有名称,例如SpooledTemporaryFile()。 Is there a way to get around this? 有办法解决这个问题吗?

example: 例:

f=tempfile.NamedTemporaryFile(delete=True)
region=tempfile.SpooledTemporaryFile()
region.write(b'chr1\t1090917\t1136917\n')
region.seek(0)
subprocess.call(['/usr/local/bin/shuffleBed', '-incl',str(region),'-i','temp'+chromosome+'ShuffleMutations.bed','-g','hg19.genome'],stdout=f)

is there a away to give region a name so the terminal can find it? 有没有给区域命名的名称,以便终端可以找到它?

Use NamedTemporaryFile to create the input file. 使用NamedTemporaryFile创建输入文件。 If you close it, there should be no drain on file descriptors. 如果您将其关闭,则文件描述符应该不会浪费。

f=tempfile.NamedTemporaryFile(delete=True)
region=tempfile.NamedTemporaryFile(delete=False)
region.write(b'chr1\t1090917\t1136917\n')
region.close()
subprocess.call(['/usr/local/bin/shuffleBed', '-incl',region.name,'-i','temp'+chromosome+'ShuffleMutations.bed','-g','hg19.genome'],stdout=f)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM