質問編集履歴
3
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
(6/21コメントをもとに質問を全面的に修正しました)
|
3
|
+
(6/21コメントをもとに質問を全面的に修正しました)下方のXMLファイル中にある特定の要素、ここではAttributes 内のmaterial のキーワードだけ(soil)を抽出・出力できない。また実際のファイルは、同様の形式で複数のidの情報が数万行で含まれており、idは必ずあるものの、Attributes 内にmaterialの項目がある場合とない場合があります。項目がある場合はそのまま、また、ない場合はスキップするか、あるいはmissingとしてidとともにタブ区切りで出力したいと考えております(以下が最終的に実現したいこと)。
|
4
4
|
|
5
5
|
[outputファイル]
|
6
6
|
SAMD00000001^ soil
|
@@ -9,7 +9,7 @@
|
|
9
9
|
…と続いていきます。
|
10
10
|
### 発生している問題・エラーメッセージ
|
11
11
|
|
12
|
-
以下の通り、Attributesの全てのワードが出てくる状況です。また、その情報をidと
|
12
|
+
以下の通り、Attributesの全てのワードが出てくる状況です。また、その情報をidと一緒に出力できない。
|
13
13
|
|
14
14
|
### 該当のコマンド
|
15
15
|
|
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
(
|
3
|
+
(6/21コメントをもとに質問を全面的に修正しました)XMLファイルが閉じタグがないものをuploadしており、また構造が不正確であったため、全面的に修正しました。XMLファイル中にある特定の要素、Attributes 内のmaterial のキーワードだけ(ここではsoil)を抽出・出力できない。また実際のファイルは、同様の形式で複数のidの情報が数万行で含まれており、idは必ずあるものの、Attributes 内にmaterialの項目がある場合とない場合があります。項目がある場合はそのまま、また、ない場合はスキップするか、あるいはmissingとしてidとともにタブ区切りで出力したいと考えております(以下が最終的に実現したいこと)。
|
4
4
|
|
5
5
|
[outputファイル]
|
6
6
|
SAMD00000001^ soil
|
1
文章、書式の全面的に改善しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,158 +1,83 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
|
4
|
-
https://teratail.com/questions/271498
|
3
|
+
(追記)XMLファイルが閉じタグがないものをuploadしており、また構造が不正確であったため、全面的に修正しました。XMLファイル中にある特定の要素、Attributes 内のmaterial のキーワードだけ(ここではsoil)を抽出・出力できない。また実際のファイルは、同様の形式で複数のidの情報が数万行で含まれており、idは必ずあるものの、Attributes 内にmaterialの項目がある場合とない場合があります。項目がある場合はそのまま、また、ない場合はスキップするか、あるいはmissingとしてidとともにタブ区切りで出力したいと考えております(以下が最終的に実現したいこと)。
|
5
4
|
|
5
|
+
[outputファイル]
|
6
|
+
SAMD00000001^ soil
|
7
|
+
SAMD00000002^ missing
|
8
|
+
SAMD00000003^ water
|
9
|
+
…と続いていきます。
|
6
|
-
|
10
|
+
### 発生している問題・エラーメッセージ
|
7
11
|
|
8
|
-
<BioSample access="public" publication_date="2015-11-08T00:00:00.000" last_update="2019-06-20T17:16:02.371" submission_date="2015-05-28T09:58:39.000" id="3741962" accession="SAMN03741962">
|
9
|
-
あるいは
|
10
|
-
|
12
|
+
以下の通り、Attributesの全てのワードが出てくる状況です。また、その情報をidとともに出力できない。
|
11
|
-
の中にある
|
12
|
-
「SAMN03741962」
|
13
13
|
|
14
|
-
|
14
|
+
### 該当のコマンド
|
15
15
|
|
16
|
-
<Attribute attribute_name="isolation_source" harmonized_name="isolation_source" display_name="isolation source">surface water</Attribute>
|
17
|
-
の中にある
|
18
|
-
「surface water」
|
19
|
-
|
20
|
-
のこれら2種のキーワード(SAMN03741962とsurface water)を抽出したいと考えております。属性や子要素の理解が不十分であるからと思いますが、もしよろしければ、コメントいただけましたら幸いです。
|
21
|
-
|
22
|
-
### 発生している問題・エラーメッセージ
|
23
|
-
|
24
16
|
```
|
17
|
+
xmllint --xpath "/BioSample/Ids/Id/text()" testbiosample.xml
|
18
|
+
# 結果、id SAMD00000001 が抽出される
|
25
|
-
|
19
|
+
xmllint --xpath "/BioSample/Attributes/Attribute/text()" testbiosample.xml
|
20
|
+
# 結果、以下の通りAttributesの全てのワードが出てくる
|
21
|
+
DOA9
|
22
|
+
grassland
|
23
|
+
N/A
|
24
|
+
grassland
|
25
|
+
Thailand
|
26
|
+
N/A
|
27
|
+
soil
|
26
|
-
|
28
|
+
Genetic diversity of Bradyrhizobium strains isolated from root nodules of Aeschynomene americana
|
29
|
+
22752179
|
30
|
+
2
|
31
|
+
22752179
|
32
|
+
symbiont
|
27
|
-
|
33
|
+
Aeschynomene americana
|
34
|
+
PRJDB1640
|
35
|
+
BDOA9
|
28
|
-
|
36
|
+
```
|
29
|
-
testbiosample.xml:160: parser error : Premature end of data in tag BioSample line 109
|
30
37
|
|
31
|
-
^
|
32
|
-
testbiosample.xml
|
38
|
+
### testbiosample.xml
|
33
|
-
|
34
|
-
^
|
35
|
-
testbiosample.xml:160: parser error : Premature end of data in tag BioSampleSet line 2
|
36
|
-
|
37
|
-
^
|
38
39
|
```
|
40
|
+
<BioSample access="public" publication_date="2014-04-07T00:00:00+09:00" last_update="2014-09-25T09:58:01+09:00">
|
41
|
+
<Ids>
|
42
|
+
<Id is_primary="1" namespace="BioSample">SAMD00000001</Id>
|
43
|
+
</Ids>
|
44
|
+
<Description>
|
45
|
+
<SampleName>Bradyrhizobium sp. DOA9</SampleName>
|
46
|
+
<Title>MIGS Cultured Bacterial/Archaeal sample from Bradyrhizobium sp. DOA9</Title>
|
47
|
+
<Organism taxonomy_id="1126627">
|
48
|
+
<OrganismName>Bradyrhizobium sp. DOA9</OrganismName>
|
49
|
+
</Organism>
|
50
|
+
</Description>
|
51
|
+
<Owner>
|
52
|
+
<Name url="-----">Tokyo University of Agriculture and Technology</Name>
|
53
|
+
</Owner>
|
54
|
+
<Models>
|
55
|
+
<Model>MIGS.ba</Model>
|
56
|
+
</Models>
|
57
|
+
<Attributes>
|
58
|
+
<Attribute attribute_name="strain">DOA9</Attribute>
|
59
|
+
<Attribute attribute_name="biome">grassland</Attribute>
|
60
|
+
<Attribute attribute_name="collection_date">N/A</Attribute>
|
61
|
+
<Attribute attribute_name="feature">grassland</Attribute>
|
62
|
+
<Attribute attribute_name="geo_loc_name">Thailand</Attribute>
|
63
|
+
<Attribute attribute_name="lat_lon">N/A</Attribute>
|
64
|
+
<Attribute attribute_name="material">soil</Attribute>
|
65
|
+
<Attribute attribute_name="project_name">Genetic diversity of Bradyrhizobium strains isolated from root nodules of Aeschynomene americana</Attribute>
|
66
|
+
<Attribute attribute_name="isol_growth_condt">22752179</Attribute>
|
67
|
+
<Attribute attribute_name="num_replicons">2</Attribute>
|
68
|
+
<Attribute attribute_name="ref_biomaterial">22752179</Attribute>
|
69
|
+
<Attribute attribute_name="biotic_relationship">symbiont</Attribute>
|
70
|
+
<Attribute attribute_name="specific_host">Aeschynomene americana</Attribute>
|
71
|
+
<Attribute attribute_name="bioproject_id">PRJDB1640</Attribute>
|
72
|
+
<Attribute attribute_name="locus_tag_prefix">BDOA9</Attribute>
|
73
|
+
</Attributes>
|
74
|
+
<Links>
|
75
|
+
<Link label="pubmed" type="db_xref">22752179</Link>
|
76
|
+
</Links>
|
77
|
+
</BioSample>
|
39
78
|
|
40
|
-
#
|
79
|
+
# 本来はこの下に次のidの情報が続きます。
|
41
|
-
|
42
80
|
```
|
43
|
-
xmllint --xpath expr "/BioSampleSet/BioSample/Ids/Id/@db" testbiosample.xml
|
44
|
-
xmllint --xpath expr "/BioSampleSet/Attribute/@isolation source" testbiosample.xml
|
45
|
-
```
|
46
81
|
|
47
|
-
### 該当のXMLファイル
|
48
82
|
|
49
|
-
```XML
|
50
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
51
|
-
<BioSampleSet>
|
52
|
-
<BioSample access="public" publication_date="2015-11-08T00:00:00.000" last_update="2019-06-20T17:16:02.371" submission_date="2015-05-28T09:58:39.000" id="3741962" accession="SAMN03741962">
|
53
|
-
<Ids>
|
54
|
-
<Id db="BioSample" is_primary="1">SAMN03741962</Id>
|
55
|
-
<Id db_label="Sample name">BACL4 MAG-120507-bin80</Id>
|
56
|
-
</Ids>
|
57
|
-
<Description>
|
58
|
-
<Title>Microbe sample from OM182 bacterium BACL3 MAG-120507-bin80</Title>
|
59
|
-
<Organism taxonomy_id="1655577" taxonomy_name="OM182 bacterium BACL3 MAG-120507-bin80">
|
60
|
-
<OrganismName>OM182 bacterium BACL3 MAG-120507-bin80</OrganismName>
|
61
|
-
</Organism>
|
62
|
-
<Comment>
|
63
|
-
<Paragraph>Genome assembled from metagenome sample SAMN03351369</Paragraph>
|
64
|
-
</Comment>
|
65
|
-
</Description>
|
66
|
-
<Owner>
|
67
|
-
<Name>Kungliga Tekniska Hogskolan, Science for Life Laboratory</Name>
|
68
|
-
<Contacts>
|
69
|
-
<Contact email="luisa.hugerth@scilifelab.se">
|
70
|
-
<Name>
|
71
|
-
<First>Luisa</First>
|
72
|
-
<Last>Hugerth</Last>
|
73
|
-
<Middle>W</Middle>
|
74
|
-
</Name>
|
75
|
-
</Contact>
|
76
|
-
</Contacts>
|
77
|
-
</Owner>
|
78
|
-
<Models>
|
79
|
-
<Model>Microbe, viral or environmental</Model>
|
80
|
-
</Models>
|
81
|
-
<Package display_name="Microbe; version 1.0">Microbe.1.0</Package>
|
82
|
-
<Attributes>
|
83
|
-
<Attribute attribute_name="strain" harmonized_name="strain" display_name="strain">not applicable</Attribute>
|
84
|
-
<Attribute attribute_name="Salinity (PSU)">6.6</Attribute>
|
85
|
-
<Attribute attribute_name="depth" harmonized_name="depth" display_name="depth">2</Attribute>
|
86
|
-
<Attribute attribute_name="env_biome" harmonized_name="env_broad_scale" display_name="broad-scale environmental context">Brackish water</Attribute>
|
87
|
-
<Attribute attribute_name="collection_date" harmonized_name="collection_date" display_name="collection date">07-May-2012</Attribute>
|
88
|
-
<Attribute attribute_name="temp" harmonized_name="temp" display_name="temperature">5.6</Attribute>
|
89
|
-
<Attribute attribute_name="environmental-sample">TRUE</Attribute>
|
90
|
-
<Attribute attribute_name="sample_type" harmonized_name="sample_type" display_name="sample type">Metagenomic Assembly</Attribute>
|
91
|
-
<Attribute attribute_name="isolation_source" harmonized_name="isolation_source" display_name="isolation source">surface water</Attribute>
|
92
|
-
<Attribute attribute_name="geo_loc_name" harmonized_name="geo_loc_name" display_name="geographic location">Baltic Sea</Attribute>
|
93
|
-
<Attribute attribute_name="lat_lon" harmonized_name="lat_lon" display_name="latitude and longitude">56.930850 N 17.060667 E</Attribute>
|
94
|
-
<Attribute attribute_name="metagenomic">TRUE</Attribute>
|
95
|
-
<Attribute attribute_name="metagenome-source">marine metagenome</Attribute>
|
96
|
-
<Attribute attribute_name="isolation-source" harmonized_name="isolation_source" display_name="isolation source">brackish water collected from the surface of the Baltic Sea</Attribute>
|
97
|
-
<Attribute attribute_name="isolate" harmonized_name="isolate" display_name="isolate">BACL4 MAG-120507-bin80</Attribute>
|
98
|
-
</Attributes>
|
99
|
-
<Links>
|
100
|
-
<Link target="bioproject" type="entrez" label="PRJNA273799">273799</Link>
|
101
|
-
</Links>
|
102
|
-
<Status status="live" when="2015-11-08T06:44:46.013"/>
|
103
|
-
</BioSample>
|
104
|
-
<BioSample access="public" publication_date="2015-11-08T06:44:46.060" last_update="2015-11-08T06:44:46.060" submission_date="2015-05-28T09:58:39.470" id="3741963" accession="SAMN03741963">
|
105
|
-
<Ids>
|
106
|
-
--
|
107
|
-
<Ids>
|
108
|
-
<Id db="BioSample" is_primary="1">SAMN03741963</Id>
|
109
|
-
<Id db_label="Sample name">BACL4 MAG-120813-bin39</Id>
|
110
|
-
</Ids>
|
111
|
-
<Description>
|
112
|
-
<Title>Microbe sample from Actinobacteria bacterium BACL4 MAG-120813-bin39</Title>
|
113
|
-
<Organism taxonomy_id="1655578" taxonomy_name="Actinobacteria bacterium BACL4 MAG-120813-bin39">
|
114
|
-
<OrganismName>Actinobacteria bacterium BACL4 MAG-120813-bin39</OrganismName>
|
115
|
-
</Organism>
|
116
|
-
<Comment>
|
117
|
-
<Paragraph>Genome assembled from metagenome sample SAMN03351393</Paragraph>
|
118
|
-
</Comment>
|
119
|
-
</Description>
|
120
|
-
<Owner>
|
121
|
-
<Name>Kungliga Tekniska Hogskolan, Science for Life Laboratory</Name>
|
122
|
-
<Contacts>
|
123
|
-
<Contact email="luisa.hugerth@scilifelab.se">
|
124
|
-
<Name>
|
125
|
-
<First>Luisa</First>
|
126
|
-
<Last>Hugerth</Last>
|
127
|
-
<Middle>W</Middle>
|
128
|
-
</Name>
|
129
|
-
</Contact>
|
130
|
-
</Contacts>
|
131
|
-
</Owner>
|
132
|
-
<Models>
|
133
|
-
<Model>Microbe, viral or environmental</Model>
|
134
|
-
</Models>
|
135
|
-
<Package display_name="Microbe; version 1.0">Microbe.1.0</Package>
|
136
|
-
<Attributes>
|
137
|
-
<Attribute attribute_name="strain" harmonized_name="strain" display_name="strain">not applicable</Attribute>
|
138
|
-
<Attribute attribute_name="Salinity (PSU)">6.2</Attribute>
|
139
|
-
<Attribute attribute_name="depth" harmonized_name="depth" display_name="depth">2</Attribute>
|
140
|
-
<Attribute attribute_name="env_biome" harmonized_name="env_broad_scale" display_name="broad-scale environmental context">Brackish water</Attribute>
|
141
|
-
<Attribute attribute_name="collection_date" harmonized_name="collection_date" display_name="collection date">13-Aug-2012</Attribute>
|
142
|
-
<Attribute attribute_name="temp" harmonized_name="temp" display_name="temperature">18.2</Attribute>
|
143
|
-
<Attribute attribute_name="environmental-sample">TRUE</Attribute>
|
144
|
-
<Attribute attribute_name="sample_type" harmonized_name="sample_type" display_name="sample type">Metagenomic Assembly</Attribute>
|
145
|
-
<Attribute attribute_name="isolation_source" harmonized_name="isolation_source" display_name="isolation source">surface water</Attribute>
|
146
|
-
<Attribute attribute_name="geo_loc_name" harmonized_name="geo_loc_name" display_name="geographic location">Baltic Sea</Attribute>
|
147
|
-
<Attribute attribute_name="lat_lon" harmonized_name="lat_lon" display_name="latitude and longitude">56.930850 N 17.060667 E</Attribute>
|
148
|
-
<Attribute attribute_name="metagenomic">TRUE</Attribute>
|
149
|
-
<Attribute attribute_name="metagenome-source">marine metagenome</Attribute>
|
150
|
-
<Attribute attribute_name="isolation-source" harmonized_name="isolation_source" display_name="isolation source">brackish water collected from the surface of the Baltic Sea</Attribute>
|
151
|
-
<Attribute attribute_name="isolate" harmonized_name="isolate" display_name="isolate">BACL4 MAG-120813-bin39</Attribute>
|
152
|
-
</Attributes>
|
153
|
-
<Links>
|
154
|
-
<Link target="bioproject" type="entrez" label="PRJNA273799">273799</Link>
|
155
|
-
</Links>
|
156
|
-
<Status status="live" when="2015-11-08T06:44:46.060"/>
|
157
|
-
</BioSample>
|
158
83
|
```
|