- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前想按序列大小对 hudge fasta 文件(+10**8 行和序列)进行排序。 fasta 是生物学中用于存储序列(遗传或蛋白质)的明确定义的格式:
>id1
sequence 1 # 可以在几行
>id2
序列 2
...
我运行了一个以 tsv 格式提供给我的工具:
标识符、长度和标识符的字节位置。
现在我正在做的是按长度列对这个文件进行排序,然后我解析这个文件并使用 seek 来检索相应的序列,然后将它附加到一个新文件。
# this fonction will get the sequence using seek
def get_seq(file, bites):
with open(file) as f_:
f_.seek(bites, 0) # go to the line of interest
line = f_.readline().strip() # this line is the begin of the
#sequence
to_return = "" # init the string which will contains the sequence
while not line.startswith('>') or not line: # while we do not
# encounter another identifiant
to_return += line
line = f_.readline().strip()
return to_return
# simply append to a file the id and the sequence
def write_seq(out_file, id_, sequence):
with open(out_file, 'a') as out_file:
out_file.write('>{}\n{}\n'.format(id_.strip(), sequence))
# main loop will parse the index file and call the function defined below
with open(args.fai) as ref:
indice = 0
for line in ref:
spt = line.split()
id_ = spt[0]
seq = get_seq(args.i, int(spt[2]))
write_seq(out_file=args.out, id_=id_, sequence=seq)
我的问题是以下真的很慢这正常吗(需要几天)?我有另一种方法吗?我不是一个纯粹的信息学家,所以我可能会漏掉一些要点,但我相信索引文件并使用搜索是实现这一目标的最佳方式,我错了吗?
最佳答案
似乎为每个序列打开两个文件可能对运行时间有很大影响。您可以将文件句柄而不是文件名传递给您的获取/写入函数,但我建议使用已建立的 fasta 解析器/索引器,如 biopython 或 samtools。这是一个使用 samtools 的(未经测试的)解决方案:
subprocess.call(["samtools", "faidx", args.i])
with open(args.fai) as ref:
for line in ref:
spt = line.split()
id_ = spt[0]
subprocess.call(["samtools", "faidx", args.i, id_, ">>", args.out], shell=True)
关于python-3.x - 按序列大小对 fasta 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41239521/
我有一个小的 DNA 序列 fasta 文件,它看起来像这样: >NM_000016 700 200 234 ACATATTGGAGGCCGAAACAATGAGGCGTGATCAACTCAGTATAT
我想使用以下脚本从一个大的 fasta 文件中提取特定的 fasta 序列,但输出为空。 transcripts.txt 文件包含我要从 assembly.fasta 导出到 selected_tra
我有一个名为 fasta1.fasta 的多 fasta 文件,其中包含序列及其 ID。我想要的是剪切具有 ID 的序列 header 并将其减少为仅包含序列的 ID 登录号。我使用了命令行 grep
我有一个 DNA 序列的小 fasta 文件,如下所示: sequence 1 > ACATATTGGAGGCCGAAACAATGAGGCGTGATCAACTCAGTATATCAC sequence
我试图找到一个 python 解决方案,使用序列的完整 header 作为查询来提取 fasta 文件中特定序列的长度。完整的 header 作为变量存储在管道的早期(即“CONTIG”)。我想将此脚
我有数千个文件,它们是序列名称列表及其序列,每行一个单独的文件,如下所示: L.abdalai.LJAMM.14363.SanMartindeLosAndes CCCTAAGAATAAT
我有数千个文件,它们是序列名称列表及其序列,每行一个单独的文件,如下所示: L.abdalai.LJAMM.14363.SanMartindeLosAndes CCCTAAGAATAAT
我有一个 fasta 文件,其中包含序列 header 及其相应的序列,如下所示: >ID101_hg19 ATGGGTGTATCGTACCC >ID102_hg19 AGCTTTAGCGGGGTAC
我正在设计一个需要在早期阶段之一输入 .fasta 文件的代码。现在,我正在使用此函数验证输入: def file_validation(fasta): while True:
我知道有很多类似的问题,我已经通读了其中的许多问题。但我仍然无法让我的代码工作。有人可以帮我指出问题吗?谢谢! (base) $ head Sample.pep2 >M00000032072 gene
我有一个包含数千个登录号的文件: 看起来像这样.. >NC_033829.1 Kallithea virus isolate DrosEU46_Kharkiv_2014, complete genom
我想从输入 fasta 文件中检索第 nth 序列(或者最好从 nth 到 mth 序列),理想情况下使用 unix“单线”。 我知道我可以用 perl(或任何其他脚本语言)读取序列、计数,然后打印序
向全世界的 Perl 大师们问好。 我在编程方面遇到了另一个麻烦。我正在编写一个程序,该程序从具有特定输入编号的蛋白质组 fasta 文件中选择随机序列。 一般的 fasta 文件如下所示: >seq
我想根据包含新名称的文本文件更改 fasta 文件中的序列名称。我找到了几种方法,但 seqkit 给人留下了很好的印象,无论如何我无法让它运行。 通过键值文件将键替换为值 fasta 文件 seq.
我只想从多个序列的 fasta 文件中提取第一个序列。我在下面有这段代码,但我无法让循环恰到好处地相互配合。 while (my $line = ) { chomp $line;
向全世界的 Perl 大师们问好。 我在编程方面遇到了另一个麻烦。我正在编写一个程序,该程序从具有特定输入编号的蛋白质组 fasta 文件中选择随机序列。 一般的 fasta 文件如下所示: >seq
我有一个 fasta 文件,其中序列用换行符分隔。我想删除换行符。这是我的文件的示例: >accession1 ATGGCCCATG GGATCCTAGC >accession2 GATATCCATG
我想根据包含新名称的文本文件更改 fasta 文件中的序列名称。我找到了几种方法,但 seqkit 给人留下了很好的印象,无论如何我无法让它运行。 通过键值文件将键替换为值 fasta 文件 seq.
下面是我用于搜索在命令行输入的 FASTA 文件以查找用户提供的主题的代码。当我运行它并输入一个我知道在文件中的主题时,它返回“找不到主题”。我只是 Perl 的初学者,我无法弄清楚如何让它打印找到的
我有一个这样的 fasta 文件(myfasta.fasta): >aat.2.2344.a ATTGCCGGTTTAATATTA >aat.2.d2344.acc ATTGCCGGTTTAATAAA
我是一名优秀的程序员,十分优秀!