Bonjour,
étant totalement novice en découpage de fichier XML à l'aide du langage Perl (j'assume), je me retrouve confrontée à un problème de taille : je n'arrive pas à récupérer le jour, le mois et l'année contenu dans mon fichier XML. J'ai beau chercher, XML::Twig veut absolument me retourner les informations sous une forme non lisible.
Je vous fournis une portion de mon fichier XML (il est assez gros à lire) :
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 <!DOCTYPE Entrezgene-Set PUBLIC "-//NLM//DTD NCBI-Entrezgene, 21st January 2005//EN" "http://www.ncbi.nlm.nih.gov/data_specs/dtd/NCBI_Entrezgene.dtd"> <Entrezgene-Set> <Entrezgene> <Entrezgene_track-info> <Gene-track> <Gene-track_geneid>119</Gene-track_geneid> <Gene-track_status value="live">0</Gene-track_status> <Gene-track_create-date> <Date> <Date_std> <Date-std> <Date-std_year>1998</Date-std_year> <Date-std_month>7</Date-std_month> <Date-std_day>27</Date-std_day> </Date-std> </Date_std> </Date> </Gene-track_create-date> <Gene-track_update-date> <Date> <Date_std> <Date-std> <Date-std_year>2011</Date-std_year> <Date-std_month>1</Date-std_month> <Date-std_day>30</Date-std_day> <Date-std_hour>1</Date-std_hour> <Date-std_minute>11</Date-std_minute> <Date-std_second>47</Date-std_second> </Date-std> </Date_std> </Date> </Gene-track_update-date> </Gene-track> </Entrezgene_track-info>
Comme vous pouvez le constater, les dates sont découpées en année, mois et jour ou en année, mois, jour, heure, minute et seconde. Et pour une raison que j'ignore, je n'arrive pas du tout à récupérer l'information d'intérêt, alors que j'ai pu récupérer sans difficulté l'identifiant (Gene-track_geneid) du gène ainsi qu'un résumé pour ce gène (beaucoup plus loin dans le fichier).
J'ai bien suivi le tutoriel sur Perl et les fichiers, dont le parsage de fichier XML, mais j'avoue que je reste dubitative devant le résultat obtenu.
Voici mon script Perl actuel :
Code perl : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 #!/usr/bin/perl -w -*- Perl -*- # # $Id$ # # use strict; use warnings; use XML::Twig; my $xml_file = "gene_file.xml"; # Script de base de Djibril, source developpez.com (langage Perl) print "Version 2 - utilisation de XML::Twig\n\n"; my $twig = new XML::Twig( Twig_handlers => { 'Gene-track' => \&gene_track, 'Entrezgene_summary' => \&gene_summary,} ); # Creation du fichier resultat my $file_out = 'out.txt'; open OUT, "> $file_out" or ( warn "Can't open file $file_out\n!" and die); # creation d'un objet twig $twig->parsefile($xml_file); # Fermeture du fichier close OUT; # racine du XML # my $root = $twig->root; # Parcours des informations sur les gènes sub gene_track{ my ( $root, $gene_info ) = @_; # GeneID print OUT "GeneID: ".$gene_info->field('Gene-track_geneid')."\n"; # creation date my $creationdate = $gene_info->first_child('Gene-track_create-date'); my $day = $creationdate->field('Date' => {'Date_std' => {'Date-std' => 'Date-std_day'}}); my $month = $creationdate->field('Date' => {'Date_std' => {'Date-std' => 'Date-std_month'}}); my $year = $creationdate->field('Date' => {'Date_std' => {'Date-std' => 'Date-std_year'}}); print OUT "Create date: ".$day."/". $month."/". $year."\n"; # last update my $update = $gene_info->first_child('Gene-track_update-date'); print OUT "Modification date: ".$update->field('Date-std_day')."/". $update->field('Date-std_month')."/". $update->field('Date-std_year')."at ". $update->field('Date-std_hour')." h ". $update->field('Date-std_minute')."' ". $update->field('Date-std_second')."''\n"; $root->purge; return; } sub gene_summary{ my ( $root, $gene_info ) = @_; # gene summary print OUT "Summary: ".$gene_info->text."\n"; $root->purge; return; }
Et mon fichier de sortie actuel :
Comme vous pouvez le constater, je n'obtiens pas les informations souhaitées. Je pourrais m'amuser à passer par des expressions régulières mais je n'aurais pas à parser un seul fichier XML par la suite, aussi il faudrait réellement que j'arrive à comprendre ce qui ne va pas afin de récupérer les informations dont j'ai besoin et ce de la façon la plus automatisée que possible.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 GeneID: 119 Create date: 1998727/1998727/1998727 Modification date: //at h ' '' Summary: Adducins are heteromeric proteins composed of different subunits referred to as adducin alpha, beta and gamma. The three subunits are encoded by distinct genes and belong to a family of membrane skeletal proteins involved in the assembly of spectrin-actin network in erythrocytes and at sites of cell-cell contact in epithelial tissues. While adducins alpha and gamma are ubiquitously expressed, the expression of adducin beta is restricted to brain and hematopoietic tissues. Adducin, originally purified from human erythrocytes, was found to be a heterodimer of adducins alpha and beta. Polymorphisms resulting in amino acid substitutions in these two subunits have been associated with the regulation of blood pressure in an animal model of hypertension. Heterodimers consisting of alpha and gamma subunits have also been described. Structurally, each subunit is comprised of two distinct domains. The amino-terminal region is protease resistant and globular in shape, while the carboxy-terminal region is protease sensitive. The latter contains multiple phosphorylation sites for protein kinase C, the binding site for calmodulin, and is required for association with spectrin and actin. Alternatively spliced transcript variants have been described. [provided by RefSeq]
En vous remerciant d'avance, cordialement, Norore.
Partager