我正在使用一个名为 Giggle 的新生物信息学工具,并且在我的系统上安装了 python 包装器。 尽管场景很具体,但我认为这个问题很普遍。 这个函数:
index = Giggle.create("index", "HMEC_hg19_BroadHMM_ALL.bed")
应该基于多个(或在本例中为一个).bed 文件创建索引。 床文件如下所示:
chr1 10000 10600 15_Repetitive/CNV 0 . 10000 10600 245,245,245
chr1 10600 11137 13_Heterochrom/lo 0 . 10600 11137 245,245,245
chr1 11137 11737 8_Insulator 0 . 11137 11737 10,190,254
chr1 11737 11937 11_Weak_Txn 0 . 11737 11937 153,255,102
chr1 11937 12137 7_Weak_Enhancer 0 . 11937 12137 255,252,4
chr1 12137 14537 11_Weak_Txn 0 . 12137 14537 153,255,102
chr1 14537 20337 10_Txn_Elongation 0 . 14537 20337 0,176,80
它基本上是一个大的制表符分隔文件,包含基因组间隔及其相应的染色体。运行上述命令时出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "giggle/giggle.pyx", line 25, in giggle.giggle.Giggle.create
TypeError: expected bytes, str found
我不知道为什么会这样,我尝试将文件转换为其他类型的编码,但没有任何效果。错误所指的代码片段如下:
def create(self, char *path, char *glob):
giggle_bulk_insert(to_bytes(glob), to_bytes(path), 1)
return Giggle(path)
我在 Windows 10 的 Linux 子系统上使用 Python 3.6。
请您参考如下方法:
问题是,在 python 3 中,字符串表示为 unicode 字符串,而不是字节字符串,就像在 python 2 中那样。当您安装 giggle 并使用 python 2 运行代码时,一切正常。但你可以这样做:
index = Giggle.create("index".encode('utf-8'), "HMEC_hg19_BroadHMM_ALL.bed".encode('utf-8'))
或者
index = Giggle.create(b"index", b"HMEC_hg19_BroadHMM_ALL.bed")
具有明确的字节串。它对我有用,直到傻笑提示 .bed 文件格式不正确(我可能在复制时弄乱了格式)
更新: 如上所述调用它时会出现另一个问题:
File type not supported 'HMEC_hg19_BroadHMM_ALL.bed'
这是由于底层libgiggle只接受.bed.gz文件造成的,可以在python-giggle/lib/giggle/src中看到/file_read.c:
if ( (strlen(i->file_name) > 7) &&
strcmp(".bed.gz", file_name + strlen(i->file_name) - 7) == 0) {
i->type = BED;
}
所以我假设自述文件位于 python-giggle网站声称您可以使用 .bed 文件调用它是不正确的。
我用 python-giggle\lib\giggle\test\data 中提供的文件之一对其进行了测试,它运行没有错误
