首页 > 解决方案 > Julia - AttributeError("'PyCall.jlwrap' 对象没有属性 'encode'")

问题描述

我正在尝试使用 julia 内部 python 的包 mappy,但出现此错误:AttributeError("'PyCall.jlwrap' object has no attribute 'encode'")。我不明白这个错误。

这是我的代码:

using PyCall
using FASTX
using CodecZlib

py"""
import mappy as mp

def aligner(name,preset,threads):
    aligner = mp.Aligner(name,preset=preset,n_threads = threads)
    return aligner

def mappy(seq,aligner):
    try:
        line = next(aligner.map(seq))
        return False
    except StopIteration:
        return True
"""
aligner = py"aligner"("genome.idx","sr",4)
for record in FASTQ.Reader(GzipDecompressorStream(open("data_file.fastq.gz")))
    check = py"mappy"(sequence(record),aligner)
    
end
close(reader)

标签: pythonjulia

解决方案


问题在于发送到 mappy 的数据类型。序列(记录)不是字符串类型,因此无法处理数据。我不知道为什么返回的错误是这个奇怪的错误。更正后的代码应该是:

for record in FASTQ.Reader(GzipDecompressorStream(open("data_file.fastq.gz")))
    seq = string(sequence(record))
    check = py"mappy"(seq,aligner)
    
end
close(reader)

推荐阅读