2016-06-02 8 views
1

私のコードに問題があります。 プログラムは、ファイルを解析し、情報で選択してクラスのオブジェクトのリストに保存するように設計されています。オブジェクトが定義されていません

しかし、最初に正しく保存されません。実際には何も保存しません。空のレコードを返します。

私は完全に最小限のコードを作成して作業しようとしました。次に動作しません。クラスに正しく保存されているかどうかわからないオブジェクトは表示できません。私はまた、xmlをより小さなサンプルに変更して、検索が間違っているかどうかを確認しました。

私はこれを長い間考えていますが、アイデアが不足しています。私はヒントを求めています。

最小コード

from xml.dom import minidom 

class Prot(): 
    def __init__(self, name=''): 
     self.name = name 

    def addname(self, name): 
     for k in range(len(entry_list)): 
      names = entry_list[k].getElementsByTagName("Names") 
      for u in range(len(names)): 
       nam = names[u].getElementsByTagName("Name") 
       name.append(nam[u].firstChild.nodeValue) 
       print(nam[u].firstChild.nodeValue) 

xml = minidom.parse('RESIDUES.XML') 

entry_list = xml.getElementsByTagName("Entry") 
mod_list = [] 
for e in range(len(entry_list)): 
    m = Prot(e) 
    mod_list.append(m) 

XML - 一つのレコード

<Entry id="AA0003"> 
<Header> 
<Code>AA0003</Code> 
<Dates> 
<CreationDate>31-Mar-1995</CreationDate> 
<StrucRevDate>31-Mar-1995</StrucRevDate> 
<TextChngDate>30-Sep-2010</TextChngDate> 
</Dates> 
</Header> 
<Names> 
<Name>L-asparagine</Name> 
<AlternateName>2,4-bis(azanyl)-4-oxobutanoic acid</AlternateName> 
<AlternateName>2,4-diamino-4-oxobutanoic acid</AlternateName> 
<AlternateName>2-amino-3-carbamoylpropanoic acid</AlternateName> 
<AlternateName>2-amino-4-butanediamic acid</AlternateName> 
<AlternateName>2-aminosuccinamic acid</AlternateName> 
<AlternateName>2-aminosuccinic acid 4-amide</AlternateName> 
<AlternateName>alpha-amino-beta-carbamylpropionic acid</AlternateName> 
<AlternateName>alpha-aminosuccinamic acid</AlternateName> 
<AlternateName>aspartic acid 4-amide</AlternateName> 
<AlternateName>aspartic acid beta-amide</AlternateName> 
<AlternateName>beta-asparagine</AlternateName> 
<SystematicName>(2S)-2-amino-4-butanediamic acid</SystematicName> 
<Xref>CAS:70-47-3</Xref> 
<Xref>ChEBI:50347</Xref> 
<Xref>PDBHET:ASN</Xref> 
</Names> 
<FormulaBlock> 
<Formula>C 4 H 6 N 2 O 2</Formula> 
<Weight type="chemical">114.10</Weight> 
<Weight type="physical">114.042927</Weight> 
</FormulaBlock> 
<CorrectionBlock uids="AA0003" label="ASN"> 
<Formula>C 0 H 0 N 0 O 0</Formula> 
<Weight type="chemical">0.00</Weight> 
<Weight type="physical">0.000000</Weight> 
</CorrectionBlock> 
<CorrectionBlock uids="AA0004" label="ASP"> 
<Formula>C 0 H 1 N 1 O -1</Formula> 
<Weight type="chemical">-0.98</Weight> 
<Weight type="physical">-0.984016</Weight> 
</CorrectionBlock> 
<ReferenceBlock> 
<Authors> 
<Author>Vauquelin, L.N.</Author> 
<Author>Robiquet, P.J.</Author> 
</Authors> 
<Citation>Ann. Chim. 57, 88-93, 1806</Citation> 
<Title> 
Découverte d'un nouveau principe végétal dans les Asperges (Asparagus sativus, Linn.) [The discovery of a new plant principle in asparagus (Asparagus sativus, L.)]. 
</Title> 
<Note>article in French; isolation and naming</Note> 
</ReferenceBlock> 
<ReferenceBlock> 
<Authors> 
<Author>Drenth, J.</Author> 
<Author>Jansonius, J.N.</Author> 
<Author>Koekoek, R.</Author> 
<Author>Swen, H.M.</Author> 
<Author>Wolthers, B.G.</Author> 
</Authors> 
<Citation>Nature 218, 929-932, 1968</Citation> 
<Title>Structure of papain.</Title> 
<Xref>DOI:10.1038/218929a0</Xref> 
<Xref>PMID:5681232</Xref> 
<Note> 
asparagine as an active site residue in a thiol proteinase 
</Note> 
</ReferenceBlock> 
<ReferenceBlock> 
<Authors> 
<Anonymous/> 
<Group> 
IUPAC-IUB Joint Commission on Biochemical Nomenclature (JCBN) 
</Group> 
</Authors> 
<Citation>Eur. J. Biochem. 138, 9-37, 1984</Citation> 
<Title> 
Nomenclature and symbolism for amino acids and peptides. Recommendations 1983. 
</Title> 
<Xref>DOI:10.1111/j.1432-1033.1984.tb07877.x</Xref> 
<Xref>PMID:6692818</Xref> 
<Note> 
standard three-letter and one-letter symbols, and nomenclature 
</Note> 
</ReferenceBlock> 
<ReferenceBlock> 
<Authors> 
<Author>Curnow, A.W.</Author> 
<Author>Tumbula, D.L.</Author> 
<Author>Pelaschier, J.T.</Author> 
<Author>Min, B.</Author> 
<Author>Soll, D.</Author> 
</Authors> 
<Citation> 
Proc. Natl. Acad. Sci. U.S.A. 95, 12838-12843, 1998 
</Citation> 
<Title> 
Glutamyl-tRNA(Gln) amidotransferase in Deinococcus radiodurans may be confined to asparagine biosynthesis. 
</Title> 
<Xref>DOI:10.1073/pnas.95.22.12838</Xref> 
<Xref>PMID:9789001</Xref> 
<Note> 
"mischarged" aspartyl-tRNA(Asn) is amidated by glutamyl-tRNA(Gln) amidotransferase in Deinococcus radiodurans 
</Note> 
</ReferenceBlock> 
<ReferenceBlock> 
<Authors> 
<Author>Paradisi, F.</Author> 
<Author>Dean, J.L.</Author> 
<Author>Geoghegan, K.F.</Author> 
<Author>Engel, P.C.</Author> 
</Authors> 
<Citation>Biochemistry 44, 3636-3643, 2005</Citation> 
<Title> 
Spontaneous chemical reversion of an active site mutation: deamidation of an asparagine residue replacing the catalytic aspartic acid of glutamate dehydrogenase. 
</Title> 
<Xref>DOI:10.1021/bi047679u</Xref> 
<Xref>PMID:15736973</Xref> 
<Note> 
an Asp to Asn mutation at an enzyme active site seemingly has partial activity; however, the asparagine form is shown to be inactive, and enhanced spontaneous deamidation results in the partial recovery of activity 
</Note> 
</ReferenceBlock> 
<ReferenceBlock> 
<Authors> 
<Author>Kolodkin-Gal, I.</Author> 
<Author>Hazan, R.</Author> 
<Author>Gaathon, A.</Author> 
<Author>Carmeli, S.</Author> 
<Author>Engelberg-Kulka, H.</Author> 
</Authors> 
<Citation>Science 318, 652-655, 2007</Citation> 
<Title> 
A linear pentapeptide is a quorum-sensing factor required for mazEF-mediated cell death in Escherichia coli. 
</Title> 
<Xref>DOI:10.1126/science.1147248</Xref> 
<Xref>PMID:17962566</Xref> 
<Note> 
enzymatic amidation of an aspartic acid residue in a peptide; the enzyme is currently identified by an activity that is different from the new activity 
</Note> 
</ReferenceBlock> 
<Comment> 
Some bacteria or archaea incorporate asparagine produced by the amidation of aspartyl-tRNA(Asn). 
</Comment> 
<GeneratingEnzyme> 
<EnzymeName link="ASN">aspartate--tRNA(Asn) ligase (EC 6.1.1.23)</EnzymeName> 
<EnzymeName link="ASN"> 
asparaginyl-tRNA synthase (glutamine-hydrolysing) (EC 6.3.5.6) 
</EnzymeName> 
<EnzymeName link="ASP">aspartate--ammonia ligase (EC 6.3.1.1)</EnzymeName> 
</GeneratingEnzyme> 
<SequenceCode link="ASN"> 
<SequenceSpec>N</SequenceSpec> 
<Abbreviation>Asn</Abbreviation> 
<Xref>PSI-MOD:00012</Xref> 
</SequenceCode> 
<SequenceCode link="ASP"> 
<SequenceSpec>D</SequenceSpec> 
<Xref>PSI-MOD:01185</Xref> 
</SequenceCode> 
<Source>natural</Source> 
<Features> 
<Feature type="UniProt" key="act_site____n" link="ASN">ACT_SITE</Feature> 
<Feature type="UniProt" key="mod_res__amidated aspartic acid__d" link="ASP">MOD_RES Amidated aspartic acid</Feature> 
</Features> 
<Image src="/images/AA0003.GIF" alt="DUMMY.GIF"/> 
<Model src="/models/AA0003.PDB"/> 
</Entry> 
+0

あなたが結果として期待していることは不明です。 'addname'は決して呼び出されません。 'range(len(entry_list))'を繰り返すと、0,1,2、... len-1という結果になります。 –

+0

これはちょうどL-アスパラギンであるべきです。私はfunction add nameを 'for e in range(len(entry_list)): m = Prot(e) mod_list.append(m)'と呼んでいました。私は新しいオブジェクトクラスを作成する名前の追加が完了し、オブジェクトのリストに結果を追加します。正しいのですか? – tiq

+0

XMLファイルには1つのルート要素があります。あなたの例で '一つのレコード'を書くとき、これは通常のファイルですか、別のルート要素の中に複数の 'Entry'要素がありますか? –

答えて

0

私は本当に仕事のこの種のxml.etreeが好き。あなたのXMLの例を想定すると、他の要素内に複数のEntryレコードを持って、私は自分のコードをテストするには、このXMLファイルを使用:ここで

<Records> 
<Entry id="AA0003"> 
<Header> 
<Code>AA0003</Code> 
</Header> 
<Names> 
<Name>L-asparagine</Name> 
<AlternateName>2,4-bis(azanyl)-4-oxobutanoic acid</AlternateName> 
<AlternateName>2,4-diamino-4-oxobutanoic acid</AlternateName> 
</Names> 
</Entry> 
<Entry id="??????"> 
<Header> 
<Code>??????</Code> 
</Header> 
<Names> 
<Name>N-Acetylglucosamine</Name> 
</Names> 
</Entry> 
</Records> 

は、XMLファイルを解析するためのコードです:

from xml.etree import ElementTree 

tree=ElementTree.parse('RESIDUES.XML') 
for entry in tree.findall('Entry'): 
    print entry.find('Names/Name').text 

これは、その結果:

L-asparagine 
N-Acetylglucosamine 
+0

ありがとうございます、私は機能の変化を実行し、動作するかどうかを確認しようとします。 OK、それでも、結果をプリントアウトしようとすると '' list ''オブジェクトに 'name' - > 'print(mod_list.name [2]) '属性がありません。それはオブジェクトクラスのリストに保存する必要があり、私は結果を見るためにそれを印刷します。 – tiq

関連する問題