Python def 语法无效

Python def invalid syntax

我正在尝试编写代码来比较一些 covid 样本,但出现语法错误: print('Total proteins:', len(df))def conv(item):

我尝试在代码中添加“()”并更改一些 def,但我一直返回语法错误。我到底做错了什么?我是不是定义有误?

for sequence in SeqIO.parse(r'C:\Users\Downloads\archive\', "fasta"):
    print(sequence.seq)
print(len(sequence),'nucliotides')

from Bio.SeqRecord import SeqRecord
from Bio import SeqIO
DNAsequence = SeqIO.read(r'C:\Users\Downloads\archive\, "fasta")

DNA = DNAsequence.seq #Convert DNA into mRNA Sequence
mRNA = DNA.transcribe() #Transcribe a DNA sequence into RNA.
print(mRNA)
print('Size : ',len(mRNA))

Amino_Acid = mRNA.translate(table=1, cds=False)
print('Amino Acid', Amino_Acid)
print("Length of Protein:",len(Amino_Acid))
print("Length of Original mRNA:",len(mRNA))

from Bio.Data import CodonTable
print(CodonTable.unambiguous_rna_by_name['Standard'])

#Identify all the Proteins (chains of amino acids)
Proteins = Amino_Acid.split('*') # * is translated stop codon
df = pd.DataFrame(Proteins)
df.describe()

#Identify all the Proteins (chains of amino acids)
Proteins = Amino_Acid.split('*') # * is translated stop codon
df = pd.DataFrame(Proteins)
df.describe()
print('Total proteins:', len(df))def conv(item):
    return len(item)def to_str(item):
    return str(item)df['sequence_str'] = df[0].apply(to_str)
df['length'] = df[0].apply(conv)
df.rename(columns={0: "sequence"}, inplace=True)
df.head()# Take only longer than 20
functional_proteins = df.loc[df['length'] >= 20]
print('Total functional proteins:', len(functional_proteins))
functional_proteins.describe()```

正如评论所指出的,您的代码格式不正确。我认为它应该是这样的:

.
.
.
df.describe()
print('Total proteins:', len(df))
def conv(item):
    return len(item)
def to_str(item):
    return str(item)
df['sequence_str'] = df[0].apply(to_str)
df['length'] = df[0].apply(conv)
df.rename(columns={0: "sequence"}, inplace=True)
df.head()# Take only longer than 20
.
.
.

就是这样,真的...