2015-04-04 36 views
0

我已经在使用windows的pyhthon shell提示符下试过这段代码。但我得到的错误如下如何使用twobitreader将hg19.bit文件转换为hg19.fa文件?

>>> python -m twobitreader hg19.2bit < example.bed 
SyntaxError: invalid syntax 

我也试图与您发送

import twobitreader 
    with open("fas.fa", "w") as output, open('example.bed') as bedfile: 
    twobit = twobitreader.TwoBitFile('hg19.2bit') 
    twobitreader.twobit_reader(twobit, input_stream=bedfile, write=output) 

当我尝试执行上面的代码我收到错误的

Traceback (most recent call last): 
File "D:/genome/sample6.py", line 3, in <module> 
with open("fas.fa", "w") as output, open('example.bed') as bedfile: 
IOError: [Errno 2] No such file or directory: 'example.bed'`Filed: 
代码

我无法准确跟踪错误。

回答

0

您正尝试在Python解释器中执行shell命令。译员是而不是一个外壳。

在shell中,你仍然可以执行命令行代码所执行的相同代码。 2bit文件输入流是需要的twobit_reader()做任何事情。所述first line of the function读取:

if input_stream is None: return 

库取hg19.2bit文件作为TwoBitFile对象;所述input_stream参数必须是在使用BED格式一个文件或其他迭代,根据文档的字符串的命令行工具:

Regions should be given in BED format on stdin

chrom start(0-based) end(0-based, not included) 

To use a BED file of regions, do

python -m twobitreader example.2bit < example.bed 

从Python脚本,所述example.bed输入应该是一个开放的文件中传递过来的input_stream

import twobitreader 

with open("fas.fa", "w") as output, open('example.bed') as bedfile: 
    twobit = twobitreader.TwoBitFile('hg19.2bit') 
    twobitreader.twobit_reader(twobit, input_stream=bedfile, write=output) 

项目文档提供了BED格式的链接:http://genome.ucsc.edu/FAQ/FAQformat#format1

+0

对于python,我使用的是windows平台。我认为命令“python -m twobitreader example.2bit CHITRA 2015-04-05 09:23:45

+0

'python -m twobitreader example.2bit 2015-04-05 09:29:46

+0

但是,我相当确定Windows支持输入重定向与Linux一样。 – 2015-04-05 09:32:15