Hatena::Groupkdri

KazusaAPI開発日誌 このページをアンテナに追加 RSSフィード

2008-03-13

DAS サーバから Feature をとりだす(取り出すだけ)

|  DAS サーバから Feature をとりだす(取り出すだけ) - KazusaAPI開発日誌 を含むブックマーク はてなブックマーク -  DAS サーバから Feature をとりだす(取り出すだけ) - KazusaAPI開発日誌  DAS サーバから Feature をとりだす(取り出すだけ) - KazusaAPI開発日誌 のブックマークコメント

Processing から DAS サーバにアクセスしてゲノム座標情報を取得してみます。ここでは、localhost で動いている gbrowse 付属の DAS サーバにはいっている TAIR7 のデータをつかっています。

HTTP GET

DAS サーバへのアクセスは HTTP の GET で、XML 文章がかえります。Processing の XML ライブラリは引数に url を指定できるので、Network Client クラス等は不要です。

  url = "http://localhost/cgi-bin/das/arabidopsis/features?segment=Chr1:1,100";
  gff = new XMLElement(this, url); 

XML の処理

XML の要素にはタグ名の階層でアクセスできます。features コマンドからかえってくる XML 文章は次のようなものです。

<DASGFF>
  <GFF HREF="http://localhost/cgi-bin/das/arabidopsis/features?segment=Chr1%3A1%2C100" VERSION="1.01">
    <SEGMENT ID="Chr1" VERSION="1.0" STOP="100" START="1">
      <FEATURE ID="TEL1N" LABEL="TEL1N">
        <TYPE ID="BAC_cloned_genomic_insert:TAIR" CATEGORY="Assembly">BAC_cloned_genomic_insert:TAIR</TYPE>
        <METHOD ID="BAC_cloned_genomic_insert">BAC_cloned_genomic_insert</METHOD>
        <START>1</START>
        <END>444</END>
        <SCORE>-</SCORE>
        <ORIENTATION>+</ORIENTATION>
        <PHASE>0</PHASE>
        <LINK HREF="http://localhost/cgi-bin/gbrowse_details/arabidopsis?name=TEL1N;class=Sequence;ref=Chr1;start=1;end=444">BAC_cloned_genomic_insert:TAIR</LINK>
        <GROUP ID="TEL1N"/>
      </FEATURE>

FEATURE の階層のタグを複数とりだすには、XMLElement::getChildren() メソッドを使用します。

  XMLElement[] features = gff.getChildren("GFF/SEGMENT/FEATURE");

FEATURE タグの ID の値(ここでは "TEL1N")をとりだすには、XMLElement::getStringAttribute() メソッドを使用します。

    println("    ID: " + features[i].getStringAttribute("ID"));

START タグの中身(ここでは 1)をとりだすには、XMLElement::getContent() メソッドを使用します。

    println(" " + features[i].getChild("START").getContent());  

プログラム

import processing.xml.*;

/**
 * DAS HTTP Client. 
 */

String url;
XMLElement gff;

void setup() {
  size(500, 400);
  background(50);
  fill(200);
  url = "http://localhost/cgi-bin/das/arabidopsis/features?segment=Chr1:1,100";
  gff = new XMLElement(this, url); 

  XMLElement seg = gff.getChild("GFF/SEGMENT/FEATURE");
  println(seg);
  
  XMLElement[] features = gff.getChildren("GFF/SEGMENT/FEATURE");
  println("Length: " + features.length);

  for (int i = 0; i < features.length; i++) {
    println("i: " + i);
    println(features[i]);
    println("FEATURE:");
    println("    ID: " + features[i].getStringAttribute("ID"));
    println(" LABEL: " + features[i].getStringAttribute("LABEL"));
    
    println("TYPE:");
    println("       ID: " + features[i].getChild("TYPE").getAttribute("ID"));
    println(" CATEGORY: " + features[i].getChild("TYPE").getAttribute("CATEGORY"));
    println(" " + features[i].getChild("TYPE").getContent());
      
    println("METHOD:");
    println("       ID: " + features[i].getChild("METHOD").getAttribute("ID"));
    println(" " + features[i].getChild("METHOD").getContent());
  
    println("START:");
    println(" " + features[i].getChild("START").getContent());  

    println("END:");
    println("E: " + features[i].getChild("END").getContent());  

    println("SCORE:");
    println(" " + features[i].getChild("SCORE").getContent());  
    
    println("ORIENTATION:");
    println(" " + features[i].getChild("ORIENTATION").getContent());  
    
    println("PHASE:");
    println(" " + features[i].getChild("PHASE").getContent());  

    println("LINK:");
    println(" HREF: " + features[i].getChild("LINK").getAttribute("HREF"));
    println(" " + features[i].getChild("LINK").getContent()); 
    
    println("GROUP:");
    println(" ID: " + features[i].getChild("GROUP").getAttribute("ID"));
    println(" " + features[i].getChild("GROUP").getContent());  
  }

}

void draw() {
}

出力

<FEATURE ID="TEL1N" LABEL="TEL1N"><TYPE ID="BAC_cloned_genomic_insert:TAIR" CATEGORY="Assembly">BAC_cloned_genomic_insert:TAIR</TYPE><METHOD ID="BAC_cloned_genomic_insert">BAC_cloned_genomic_insert</METHOD><START>1</START><END>444</END><SCORE>-</SCORE><ORIENTATION>+</ORIENTATION><PHASE>0</PHASE><LINK HREF="http://localhost/cgi-bin/gbrowse_details/arabidopsis?name=TEL1N;class=Sequence;ref=Chr1;start=1;end=444">BAC_cloned_genomic_insert:TAIR</LINK><GROUP ID="TEL1N"/></FEATURE>
Length: 4
i: 0
<FEATURE ID="TEL1N" LABEL="TEL1N"><TYPE ID="BAC_cloned_genomic_insert:TAIR" CATEGORY="Assembly">BAC_cloned_genomic_insert:TAIR</TYPE><METHOD ID="BAC_cloned_genomic_insert">BAC_cloned_genomic_insert</METHOD><START>1</START><END>444</END><SCORE>-</SCORE><ORIENTATION>+</ORIENTATION><PHASE>0</PHASE><LINK HREF="http://localhost/cgi-bin/gbrowse_details/arabidopsis?name=TEL1N;class=Sequence;ref=Chr1;start=1;end=444">BAC_cloned_genomic_insert:TAIR</LINK><GROUP ID="TEL1N"/></FEATURE>
FEATURE:
    ID: TEL1N
 LABEL: TEL1N
TYPE:
       ID: BAC_cloned_genomic_insert:TAIR
 CATEGORY: Assembly
 BAC_cloned_genomic_insert:TAIR
METHOD:
       ID: BAC_cloned_genomic_insert
 BAC_cloned_genomic_insert
START:
 1
END:
E: 444
SCORE:
 -
ORIENTATION:
 +
PHASE:
 0
LINK:
 HREF: http://localhost/cgi-bin/gbrowse_details/arabidopsis?name=TEL1N;class=Sequence;ref=Chr1;start=1;end=444
 BAC_cloned_genomic_insert:TAIR
GROUP:
 ID: TEL1N
 
i: 1
<FEATURE ID="SALK_001127" LABEL="SALK_001127"><TYPE ID="transposable_element_insertion_site:TAIR7" CATEGORY="Variation">transposable_element_insertion_site:TAIR7</TYPE><METHOD ID="transposable_element_insertion_site">transposable_element_insertion_site</METHOD><START>1</START><END>1</END><SCORE>-</SCORE><ORIENTATION>+</ORIENTATION><PHASE>0</PHASE><LINK HREF="http://www.arabidopsis.org/servlets/TairObject?name=SALK_001127type=polyallele">transposable_element_insertion_site:TAIR7</LINK><GROUP ID="SALK_001127"/></FEATURE>
FEATURE:
    ID: SALK_001127
 LABEL: SALK_001127
TYPE:
       ID: transposable_element_insertion_site:TAIR7
 CATEGORY: Variation
 transposable_element_insertion_site:TAIR7
METHOD:
       ID: transposable_element_insertion_site
 transposable_element_insertion_site
START:
 1
END:
E: 1
SCORE:
 -
ORIENTATION:
 +
PHASE:
 0
LINK:
 HREF: http://www.arabidopsis.org/servlets/TairObject?name=SALK_001127type=polyallele
 transposable_element_insertion_site:TAIR7
GROUP:
 ID: SALK_001127
 
i: 2
<FEATURE ID="WISCDSLOX354D10" LABEL="WISCDSLOX354D10"><TYPE ID="transposable_element_insertion_site:TAIR7" CATEGORY="Variation">transposable_element_insertion_site:TAIR7</TYPE><METHOD ID="transposable_element_insertion_site">transposable_element_insertion_site</METHOD><START>2</START><END>2</END><SCORE>-</SCORE><ORIENTATION>+</ORIENTATION><PHASE>0</PHASE><LINK HREF="http://www.arabidopsis.org/servlets/TairObject?name=WISCDSLOX354D10type=polyallele">transposable_element_insertion_site:TAIR7</LINK><GROUP ID="WISCDSLOX354D10"/></FEATURE>
FEATURE:
    ID: WISCDSLOX354D10
 LABEL: WISCDSLOX354D10
TYPE:
       ID: transposable_element_insertion_site:TAIR7
 CATEGORY: Variation
 transposable_element_insertion_site:TAIR7
METHOD:
       ID: transposable_element_insertion_site
 transposable_element_insertion_site
START:
 2
END:
E: 2
SCORE:
 -
ORIENTATION:
 +
PHASE:
 0
LINK:
 HREF: http://www.arabidopsis.org/servlets/TairObject?name=WISCDSLOX354D10type=polyallele
 transposable_element_insertion_site:TAIR7
GROUP:
 ID: WISCDSLOX354D10
 
i: 3
<FEATURE ID="Chr1" LABEL="Chr1"><TYPE ID="chromosome:TAIR7" CATEGORY="chromosome">chromosome:TAIR7</TYPE><METHOD ID="chromosome">chromosome</METHOD><START>1</START><END>30432563</END><SCORE>-</SCORE><ORIENTATION>+</ORIENTATION><PHASE>0</PHASE><LINK HREF="http://localhost/cgi-bin/gbrowse_details/arabidopsis?name=Chr1;class=Sequence;ref=Chr1;start=1;end=30432563">chromosome:TAIR7</LINK><GROUP ID="Chr1"/></FEATURE>
FEATURE:
    ID: Chr1
 LABEL: Chr1
TYPE:
       ID: chromosome:TAIR7
 CATEGORY: chromosome
 chromosome:TAIR7
METHOD:
       ID: chromosome
 chromosome
START:
 1
END:
E: 30432563
SCORE:
 -
ORIENTATION:
 +
PHASE:
 0
LINK:
 HREF: http://localhost/cgi-bin/gbrowse_details/arabidopsis?name=Chr1;class=Sequence;ref=Chr1;start=1;end=30432563
 chromosome:TAIR7
GROUP:
 ID: Chr1
トラックバック - http://kdri.g.hatena.ne.jp/nakao_mitsuteru/20080313