我解释我的问题。在
我实际上有一个gff文件(Augustus输出) 在这个gff文件中,我有不同支架中基因的定位,例如:
# Predicted genes for sequence number 1 on both strands
# start gene g1
scaffold_0 AUGUSTUS gene 5629 8516 0.13 + . g1
scaffold_0 AUGUSTUS transcript 5629 8516 0.13 + . g1.t1
scaffold_0 AUGUSTUS start_codon 5629 5631 . + 0 transcript_id "g1.t1"; gene_id "g1";
scaffold_0 AUGUSTUS intron 5662 7695 0.18 + . transcript_id "g1.t1"; gene_id "g1";
scaffold_0 AUGUSTUS intron 8219 8424 0.55 + . transcript_id "g1.t1"; gene_id "g1";
scaffold_0 AUGUSTUS CDS 5629 5661 0.41 + 0 transcript_id "g1.t1"; gene_id "g1";
scaffold_0 AUGUSTUS CDS 7696 8218 0.56 + 0 transcript_id "g1.t1"; gene_id "g1";
scaffold_0 AUGUSTUS CDS 8425 8516 0.59 + 2 transcript_id "g1.t1"; gene_id "g1";
scaffold_0 AUGUSTUS stop_codon 8514 8516 . + 0 transcript_id "g1.t1"; gene_id "g1";
# protein sequence = [MRVKSGNLRENNEARGTSANVALCTVSRGYGGRGARGGGVSGANSGPSGARGGSTRARSRAESVVRLPLSPRTLCAPG
# PVAGPHTGAQAQQHPQQAQSRDHHASQPLTGGAGTGSGLEDGPGSADEPMVHLERPQQAGTWICCVPCYWLRRSKAVHKALLTFAMLLVTSLLVTSPV
# LFLITTLPEAASIRHTYACLFSLSKIPLPPHMKTNGTPF]
# end gene g1
例如,这里的g1.t1位于scaffold 0中。 我还有一个包含以下信息的tab文件:
^{pr2}$我想做的是用这些信息创建一个数据框,例如,如果我有5个基因:
^{3}$这些脚手架的信息包括:
scaf_name scaf_length cov_depth GC
scaffold 6 56786 79 0.39
scaffold 256 789765 86 0.42
scaffold 890 3456 85 0.40
scaffold 1234 590 90 0.41
我想要一个这样的数据帧:
gene_name scaf_name scaf_length cov_depth GC
g3.t1 scaffold 6 56786 79 0.39
g4.t1 scaffold 6 56786 79 0.39
g1.t1 scaffold 256 789765 86 0.42
g2.t1 scaffold 890 3456 85 0.40
g5.t1 scaffold 1234 590 90 0.41
我想用Python和熊猫是有可能的,不是吗? 感谢您的帮助:)
以下是我对Ami的感谢:
import pandas as pd
gff_0042="/Users/etudiant/Desktop/Horizon_project/Augustus/Augustus_out/run_augustus_0042.out"
liste=["scaf_name","source","feature","start","end","score","strand","frame","gene"]
gene_info=pd.read_csv(gff_0042,comment='"',sep='\s+',header=None,names=liste)
scaf_info=pd.read_csv("cov_GC.tab",sep='\t')
scaf_info.scaf_name = scaf_info.scaf_name.str.replace(' ', '_')
new=pd.merge(gene_info, scaf_info, on='scaf_name')
print(new)
以下是我得到的部分输出:
scaf_name source feature start end score strand frame gene scaf_length cov_depth GC
0 scaffold_0 AUGUSTUS gene 5793 11216 0.13 + . g1 541519 79.7321515957889 0.39808760172773294
1 scaffold_0 AUGUSTUS transcript 5793 11216 0.13 + . g1.t1 541519 79.7321515957889 0.39808760172773294
2 scaffold_0 AUGUSTUS start_codon 5793 5795 . + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
3 scaffold_0 AUGUSTUS intron 5829 7371 0.41 + . transcript_id 541519 79.7321515957889 0.39808760172773294
4 scaffold_0 AUGUSTUS intron 7405 7695 0.8 + . transcript_id 541519 79.7321515957889 0.39808760172773294
5 scaffold_0 AUGUSTUS intron 8248 11054 0.37 + . transcript_id 541519 79.7321515957889 0.39808760172773294
6 scaffold_0 AUGUSTUS CDS 5793 5828 0.45 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
7 scaffold_0 AUGUSTUS CDS 7372 7404 0.81 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
8 scaffold_0 AUGUSTUS CDS 7696 8247 0.84 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
9 scaffold_0 AUGUSTUS CDS 11055 11216 0.4 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
10 scaffold_0 AUGUSTUS stop_codon 11214 11216 . + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
11 scaffold_0 AUGUSTUS gene 38793 39207 0.91 - . g2 541519 79.7321515957889 0.39808760172773294
12 scaffold_0 AUGUSTUS transcript 38793 39207 0.91 - . g2.t1 541519 79.7321515957889 0.39808760172773294
13 scaffold_0 AUGUSTUS stop_codon 38793 38795 . - 0 transcript_id 541519 79.7321515957889 0.39808760172773294
14 scaffold_0 AUGUSTUS intron 38904 39066 0.92 - . transcript_id 541519 79.7321515957889 0.39808760172773294
15 scaffold_0 AUGUSTUS CDS 38793 38903 0.95 - 0 transcript_id 541519 79.7321515957889 0.39808760172773294
16 scaffold_0 AUGUSTUS CDS 39067 39207 0.91 - 0 transcript_id 541519 79.7321515957889 0.39808760172773294
17 scaffold_0 AUGUSTUS start_codon 39205 39207 . - 0 transcript_id 541519 79.7321515957889 0.39808760172773294
18 scaffold_0 AUGUSTUS gene 50409 58153 0.07 + . g3 541519 79.7321515957889 0.39808760172773294
19 scaffold_0 AUGUSTUS transcript 50409 58153 0.07 + . g3.t1 541519 79.7321515957889 0.39808760172773294
20 scaffold_0 AUGUSTUS start_codon 50409 50411 . + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
21 scaffold_0 AUGUSTUS intron 50520 50762 0.65 + . transcript_id 541519 79.7321515957889 0.39808760172773294
22 scaffold_0 AUGUSTUS intron 50895 51080 0.91 + . transcript_id 541519 79.7321515957889 0.39808760172773294
23 scaffold_0 AUGUSTUS intron 51180 51284 0.61 + . transcript_id 541519 79.7321515957889 0.39808760172773294
24 scaffold_0 AUGUSTUS intron 51458 55603 0.47 + . transcript_id 541519 79.7321515957889 0.39808760172773294
25 scaffold_0 AUGUSTUS intron 55791 56101 0.98 + . transcript_id 541519 79.7321515957889 0.39808760172773294
26 scaffold_0 AUGUSTUS intron 56279 56384 1 + . transcript_id 541519 79.7321515957889 0.39808760172773294
27 scaffold_0 AUGUSTUS intron 56486 56573 1 + . transcript_id 541519 79.7321515957889 0.39808760172773294
28 scaffold_0 AUGUSTUS intron 56630 56952 0.97 + . transcript_id 541519 79.7321515957889 0.39808760172773294
29 scaffold_0 AUGUSTUS intron 57240 57365 0.57 + . transcript_id 541519 79.7321515957889 0.39808760172773294
30 scaffold_0 AUGUSTUS intron 57525 57736 0.81 + . transcript_id 541519 79.7321515957889 0.39808760172773294
31 scaffold_0 AUGUSTUS intron 57814 58053 0.75 + . transcript_id 541519 79.7321515957889 0.39808760172773294
32 scaffold_0 AUGUSTUS CDS 50409 50519 0.39 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
33 scaffold_0 AUGUSTUS CDS 50763 50894 0.74 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
34 scaffold_0 AUGUSTUS CDS 51081 51179 0.91 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
35 scaffold_0 AUGUSTUS CDS 51285 51457 0.57 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
36 scaffold_0 AUGUSTUS CDS 55604 55790 0.98 + 1 transcript_id 541519 79.7321515957889 0.39808760172773294
37 scaffold_0 AUGUSTUS CDS 56102 56278 0.98 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
38 scaffold_0 AUGUSTUS CDS 56385 56485 1 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
39 scaffold_0 AUGUSTUS CDS 56574 56629 0.98 + 1 transcript_id 541519 79.7321515957889 0.39808760172773294
40 scaffold_0 AUGUSTUS CDS 56953 57239 0.64 + 2 transcript_id 541519 79.7321515957889 0.39808760172773294
41 scaffold_0 AUGUSTUS CDS 57366 57524 0.81 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
42 scaffold_0 AUGUSTUS CDS 57737 57813 0.9 + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
43 scaffold_0 AUGUSTUS CDS 58054 58153 0.5 + 1 transcript_id 541519 79.7321515957889 0.39808760172773294
44 scaffold_0 AUGUSTUS stop_codon 58151 58153 . + 0 transcript_id 541519 79.7321515957889 0.39808760172773294
如果可能的话我只想得到:
scaf_name source feature start end score strand frame gene scaf_length cov_depth GC
1 scaffold_0 AUGUSTUS transcript 5793 11216 0.13 + . g1.t1 541519 79.7321515957889 0.39808760172773294
12 scaffold_0 AUGUSTUS transcript 38793 39207 0.91 - . g2.t1 541519 79.7321515957889 0.39808760172773294
19 scaffold_0 AUGUSTUS transcript 50409 58153 0.07 + . g3.t1 541519 79.7321515957889 0.39808760172773294
等等。。在
首先,使用^{} 读取gff文件。注意以下几点:
comment='"'
header=None
names=...
设置为某个表示名称的列表,第一个名为'scaf_name'
,最后一个名为'gene'
。在将其放入
gene_info
。在现在使用
read_csv
读取tab限制文件,设置sep='\t'
。将其放入scaf_info
。在跑
为了将
scaffold 6
等内容改为scaffold_6
。在现在开始吧
^{pr2}$相关问题 更多 >
编程相关推荐