希望の出力を得る方法は?
Nov 24 2020
私は次のコマンドを使用してプロジェクトに取り組んでいますnano
:
from Bio import SeqIO
import sys
import re
fasta_file = (sys.argv[1])
for myfile in SeqIO.parse(fasta_file, "fasta"):
if len(myfile) > 250:
gene_id = myfile.id
mylist = re.match(r"H149xcV_\w+_\w+_\w+", gene_id)
print (">"+mylist.group(0)) # edited from list to mylist
そして、次のアウトアウトを提供します。
>H149xcV_Fge342_r3_h2_d1
>H149xcV_bTr423_r3_h2_d1
>H149xcV_kN893_r3_h2_d1
>H149xcV_DNp021_r3_h2_d1
>H149xcV_JEP3324_r3_h2_d1
>H149xcV_SRt424234_r3_h2_d1
コマンドを変更して、目的の形式とUNIQUE遺伝子IDのみを提供するにはどうすればよいですか。
>H149xcV_Fge342_r3_h2
>H149xcV_bTr423_r3_h2
>H149xcV_kN893_r3_h2
>H149xcV_DNp021_r3_h2
>H149xcV_JEP3324_r3_h2
>H149xcV_SRt424234_r3_h2
回答
2 M__ Nov 24 2020 at 05:18
簡単に置き換えるmatch
ことsub
ができlist
ますが、変数としての使用はやめてください... mylistは問題ありません。
これはうまくいくかもしれません
mylist = re.sub(r'H149xcV_\w+_\w+_\w+', gene_id)
そうでなければ
myregex = re.compile('_\w+\s+.*')
fastaid = myregex.sub('', myfile)
または@MaximilianPressから
myregex2 = re.compile('_\w+\n') # or myregex2 = re.compile('_\w+$')
fastaid2 = myregex.sub('\n', myfile) # or fasaid2 = myregex.sub('', myfile)
上記は機能します...私のすべてのコードと同様に、私はそれを証明することはありません..
pippo1980 Dec 16 2020 at 16:37
from Bio import SeqIO
import sys
import re
unique = []
fasta_file = (sys.argv[1])
for myfile in SeqIO.parse(fasta_file, "fasta"):
if len(myfile) > 250:
gene_id = myfile.id
if gene.id not in unique:
unique.append(gene.id)
mylist = re.match(r"H149xcV_\w+_\w+_\w+", gene_id)
print (">"+mylist.group(0))
それがうまくいくかどうか私に知らせてください私も学んでいます