刚才小玩了下,不错,。net确实很方便,很强大

Using Entrez Utilities Web Service with C# and MS Visual Studio 2005

Updated: May 20, 2008

Entrez Utilities Web Service has been tested with:

  • Microsoft Windows XP Professional (Service Pack2)
  • Microsoft .NET Framework Version 2.0.50727
  • Microsoft Visual Studio 2005 Version 8.0.50727.42

NCBI Entrez Utilities Web Service using MS Visual Studio 2005.

To create Windows application:

  1. Press Ctrl+Shift+N or Select File menu, then New, and then click Project to open the New Project dialog.
  2. Select Visual C# in Project types list.
  3. Select Windows Application in Templates list.
  4. Click OK to create a new project.
  5. Select View menu and then Toolbox to open a Toolbox window.
  6. From the Toolbox, drag a Textbox and a Button to the design surface of Form1.
  7. On the Project menu, click Add Web Reference.
  8. In the URL field of the Add Web Reference dialog, type the URL http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/eutils.wsdl
  9. Click the Go button to retrieve information about the XML Web service.
  10. In the Web reference name field, rename the Web reference to eUtils.
  11. Click Add Reference to add a Web reference for the target XML Web service.
  12. Double-click the button on Form1 to create an event-handling method for this button.
  13. In the button1_Click method enter the following code:

    // eInfo utility returns a list of available databases

    try

    {

    eUtils.eUtilsService serv = new eUtils.eUtilsService();

    // call NCBI EInfo utility

    eUtils.eInfoResult res = serv.run_eInfo(new eUtils.eInfoRequest());

    // results output

    textBox1.Text = "";

    for(int i=0; i<res.DbList.Items.Length; i++) textBox1.Text += res.DbList.Items[i]+"\r\n";

    }

    catch (Exception eee)

    {

    textBox1.Text = eee.ToString();

    }

  14. Build and run application.

eutils_MS.wsdl file.

Click on parameter to get its description.

Click on method name to see the example of use.

public Result run_eGquery(eGqueryRequest params)eGqueryRequest class properties:  - String term  - String tool  - String emailpublic eInfoResult run_eInfo(eInfoRequest params)eInfoRequest class properties:  - String db  - String tool  - String emailpublic eLinkResult run_eLink(eLinkRequest params)eLinkRequest class properties: - String db- String[] id- String reldate- String mindate- String maxdate- String datetype- String term- String dbfrom- String WebEnv- String query_key- String cmd- String tool- String emailpublic ePostResult run_ePost(ePostRequest params) ePostRequest class properties:  - String db  - String id  - String tool  - String emailpublic eSearchResult run_eSearch(eSearchRequest params)eSearchRequest class properties:  - String db  - String term  - String WebEnv  - String query_key  - String usehistory  - String tool  - String email  - String field  - String reldate  - String mindate  - String maxdate  - String datetype  - String retstart  - String retmax  - String rettype  - String sort public eSpellResult run_eSpell(eSpellRequest params) eSpellRequest class properties: - String db  - String term  - String tool  - String emailpublic eSummaryResult run_eSummary(eSummaryRequest params)eSummaryRequest class properties:  - String db  - String id  - String WebEnv  - String query_key  - String retstart  - String retmax  - String tool  - String emailpublic eFetchResult run_eFetch(eFetchRequest params)eFetchRequest class properties: - String db - String id - String WebEnv - String query_key - String tool - String email - String retstart - String retmax - String rettype燩roperties available for Sequence databases: - String rettype - String strand - String seq_start - String seq_stop - String complexity - String report

EGQuery

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI EGQuery utility

eUtils.eGqueryRequest req = new eUtils.eGqueryRequest();

req.term = "mouse";

eUtils.Result res = serv.run_eGquery(req);

// results output

textBox1.Text = "Search term: " + res.Term + "\r\n";

textBox1.Text += "Results: \r\n";

for(int i=0; i<res.eGQueryResult.ResultItem.Length; i++)

{

textBox1.Text += "  " + res.eGQueryResult.ResultItem[i].DbName +

": " + res.eGQueryResult.ResultItem[i].Count + "\r\n";

}

}

catch (Exception eee)

{

textBox1.Text = eee.ToString();

}

EInfo

// eInfo utility returns an PMC db info

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI EInfo utility

eUtils.eInfoRequest req = new eUtils.eInfoRequest();

req.db = "pmc";

eUtils.eInfoResult res = serv.run_eInfo(req);

// results output

textBox1.Text = "DbName: " + res.DbInfo.DbName + "\r\n" +

"Description: " + res.DbInfo.Description + "\r\n" +

"MenuName: " + res.DbInfo.MenuName + "\r\n";

}

catch (Exception eee)

{

textBox1.Text = eee.ToString();

}

ELink

// example retrieves links from Nuccore for to Protein GI 48819,7140345

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

string[] id = {"48819,7140345"};

// call NCBI ELink utility

eUtils.eLinkRequest req = new eUtils.eLinkRequest();

req.db = "protein";

req.id = id;

req.dbfrom = "nuccore";

eUtils.eLinkResult res = serv.run_eLink(req);

// results output

textBox1.Text = "";

for(int i=0; i<res.LinkSet.Length; i++)

{

textBox1.Text += "Links from " + res.LinkSet[i].DbFrom +

" to " + res.LinkSet[i].LinkSetDb[0].DbTo + "\r\n";

textBox1.Text += "  " + res.LinkSet[i].DbFrom + " id(s): ";

for(int k=0; k<res.LinkSet[i].IdList.Length; k++)

{

textBox1.Text +=  res.LinkSet[i].IdList[k].Value + " ";

}

textBox1.Text += "\r\n";

textBox1.Text += "  " + res.LinkSet[i].LinkSetDb[0].DbTo + " id(s): ";

for(int k=0; k<res.LinkSet[i].LinkSetDb[0].Link.Length; k++)

{

textBox1.Text += res.LinkSet[i].LinkSetDb[0].Link[k].Id.Value + " ";

}

textBox1.Text += "\r\n----------------------\r\n";

}

}

catch (Exception eee)

{

textBox1.Text = eee.ToString();

}

EPost

// Put ID list to history for later use

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI ESpell utility

eUtils.ePostRequest req = new eUtils.ePostRequest();

req.db = "pubmed";

req.id = "11237011";

eUtils.ePostResult res = serv.run_ePost(req);

// results output

textBox1.Text = "WebEnv: "+res.WebEnv  + "\r\n";

textBox1.Text += "QueryKey: "+res.QueryKey;

}

catch (Exception eee)

{

textBox1.Text = eee.ToString();

}

ESearch

// search in PubMed Central for stem cells in free fulltext articles

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI ESearch utility

// NOTE: search term should be URL encoded

eUtils.eSearchRequest req = new eUtils.eSearchRequest();

req.db = "pmc";

req.sort = "SortDate";

req.term = "stem+cells+AND+free+fulltext[filter]";

req.RetStart = "0";

req.RetMax = "15";

eUtils.eSearchResult res = serv.run_eSearch(req);

// results output

textBox1.Text = "Original query: stem cells AND free fulltext[filter]\r\n";

textBox1.Text += "Found ids: " + res.Count+"\r\n";

textBox1.Text += "First " + res.RetMax +" ids: ";

for(int i=0; i<res.IdList.Length; i++)

{

textBox1.Text += res.IdList[i] + " ";

}

}

catch (Exception eee)

{

textBox1.Text = eee.ToString();

}

ESpell

// retrieves spelling suggestions

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI ESpell utility

eUtils.eSpellRequest req = new eUtils.eSpellRequest();

req.db = "pubmed";

req.term = "mouss";

eUtils.eSpellResult res = serv.run_eSpell(req);

// results output

textBox1.Text = "Misspelled word: "+res.Query + "\r\n";

textBox1.Text += "Corrected word: "+res.CorrectedQuery;

}

catch (Exception eee)

{

textBox1.Text = eee.ToString();

}

ESummary

// retreives document Summaries by list of primary IDs

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI ESummary utility

eUtils.eSummaryRequest req = new eUtils.eSummaryRequest();

req.db = "nlmcatalog";

req.id = "905";

eUtils.eSummaryResult res = serv.run_eSummary(req);

// results output

textBox1.Text = "";

for(int i=0; i<res.DocSum.Length; i++)

{

textBox1.Text += "ID: "+res.DocSum[i].Id+"\r\n";

for(int k=0; k<res.DocSum[i].Items.Length; k++)

{

textBox1.Text += "  "+res.DocSum[i].Items[k].Name +": "+res.DocSum[i].Items[k].ItemContent + "\r\n";

}

textBox1.Text += "-----------------------\r\n\r\n";

}

}

catch (Exception eee)

{

textBox1.Text = eee.ToString();

}

EFetch

To fetch data from one of the supported databases add the corresponding Web Reference to project. For example, for taxonomy database in Add Web Reference dialog type http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/efetch_taxon.wsdl in URL field and eFetchTaxon in Web Reference Name.

Taxonomy database example:

// fetch a record from Taxonomy database

try

{

eFetchTaxon.eFetchTaxonService serv = new eFetchTaxon.eFetchTaxonService();

// call NCBI EFetch utility

eFetchTaxon.eFetchRequest req = new eFetchTaxon.eFetchRequest();

req.id = "9685";

eFetchTaxon.eFetchResult res = serv.run_eFetch(req);

// results output

textBox1.Text = res.TaxaSet[0].ScientificName + ": " +

res.TaxaSet[0].Division + " (" +

res.TaxaSet[0].Rank + ")\r\n";

}

catch (Exception eee)

{

textBox1.Text = eee.ToString();

}

Search, Link & Fetch example

Add two Web References to project for http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/eutils.wsdl and http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/efetch_seq.wsdl files. Name them eUtils and eFetchSeq correspondingly.

String[] ids = { "" };

String fetchIds = "";

// STEP #1: search in PubMed for "cat"

//

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI ESearch utility

// NOTE: search term should be URL encoded

eUtils.eSearchRequest req = new eUtils.eSearchRequest();

req.db = "pubmed";

req.sort = "PublicationDate";

req.term = "cat+AND+pubmed_nuccore[sb]";

req.RetMax = "5";

eUtils.eSearchResult res = serv.run_eSearch(req);

// store UIDs for use in ELink

int N = res.IdList.Length;

for (int i = 0; i < N; i++)

{

if (i > 0) ids[0] += ",";

ids[0] += res.IdList[i];

}

textBox1.Text = "Search in PubMed for \"cat\" returned " + res.Count + " hits\r\n";

textBox1.Text += "Search links in nuccore for the first 5 UIDs: " + ids[0]+"\r\n\r\n";

}

catch (Exception eee)

{

textBox1.Text += eee.ToString();

}

// STEP #2: get links in nucleotide database (nuccore)

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI ELink utility

eUtils.eLinkRequest req = new eUtils.eLinkRequest();

req.db = "nuccore";

req.id = ids;

req.dbfrom = "pubmed";

eUtils.eLinkResult res = serv.run_eLink(req);

// read result and create a list of UIDs to fetch

for (int i = 0; i < res.LinkSet[0].LinkSetDb[0].Link.Length; i++)

{

if (i > 0) fetchIds += ",";

fetchIds += res.LinkSet[0].LinkSetDb[0].Link[i].Id.Value;

textBox1.Text += "ELink returned the following UIDs from nuccore: " + fetchIds + "\r\n\r\n";

}

catch (Exception eee)

{

textBox1.Text += eee.ToString();

}

// STEP #3: fetch records from nuccore

//

try

{

eFetchSeq.eFetchSequenceService serv = new eFetchSeq.eFetchSequenceService();

// call NCBI ESpell utility

eFetchSeq.eFetchRequest req = new eFetchSeq.eFetchRequest();

req.db = "nuccore";

req.id = fetchIds;

eFetchSeq.eFetchResult res = serv.run_eFetch(req);

// results output

for (int i = 0; i < res.GBSet.GBSeq.Length; i++)

{

textBox1.Text += "Organism: " + res.GBSet.GBSeq[i].GBSeq_organism + "\r\n";

textBox1.Text += "Locus: " + res.GBSet.GBSeq[i].GBSeq_locus + "\r\n";

textBox1.Text += "Definition: " + res.GBSet.GBSeq[i].GBSeq_definition + "\r\n";

textBox1.Text += "----------------------\r\n\r\n";

}

}

catch (Exception eee)

{

textBox1.Text += eee.ToString();

}

Using WebEnv & QueryKey example

Add two Web References to project for http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/eutils.wsdl and http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/efetch_pubmed.wsdl files. Name them eUtils and eFetchPubmed correspondingly.

String WebEnv = "";

String query_key = "";

// STEP #1: search in PubMed for "cat"

//

try

{

eUtils.eUtilsService serv = new eUtils.eUtilsService();

// call NCBI ESearch utility

// NOTE: search term should be URL encoded

eUtils.eSearchRequest req = new eUtils.eSearchRequest();

req.db = "pubmed";

req.term = "cat";

req.usehistory = "y";

eUtils.eSearchResult res = serv.run_eSearch(req);

// store WebEnv & QueryKey for use in eFetch

WebEnv = res.WebEnv;

query_key = res.QueryKey;

textBox1.Text = "Search in PubMed for \"cat\" returned " + res.Count + " hits\r\n";

textBox1.Text += "WebEnv: " + WebEnv + "\r\n";

textBox1.Text += "QueryKey: " + query_key + "\r\n\r\n";

}

catch (Exception eee)

{

textBox1.Text += eee.ToString();

}

// STEP #2: fetch 5 records from pubmed starting from record #10

//

try

{

eFetchPubmed.eFetchPubmedService serv = new eFetchPubmed.eFetchPubmedService();

// call NCBI EFetch utility

eFetchPubmed.eFetchRequest req = new eFetchPubmed.eFetchRequest();

req.WebEnv = WebEnv;

req.query_key = query_key;

req.retstart = "10";

req.retmax = "5";

eFetchPubmed.eFetchResult res = serv.run_eFetch(req);

// results output

for (int i = 0; i < res.PubmedArticleSet.Length; i++)

{

textBox1.Text += "Title: " + res.PubmedArticleSet[i].MedlineCitation.Article.ArticleTitle + "\r\n";

textBox1.Text += "Abstract: " + res.PubmedArticleSet[i].MedlineCitation.Article.Abstract.AbstractText + "\r\n";

textBox1.Text += "--------------------------\r\n\r\n";

}

}

catch (Exception eee)

{

textBox1.Text += eee.ToString();

}

强大的NCBI接口的更多相关文章

  1. Postman - 功能强大的 API 接口请求调试和管理工具

    Postman 是一款功能强大的的 Chrome 应用,可以便捷的调试接口.前端开发人员在开发或者调试 Web 程序的时候是需要一些方法来跟踪网页请求的,用户可以使用一些网络的监视工具比如著名的 Fi ...

  2. 国内强大的API接口文档写作网站showdoc

    传送门:https://www.showdoc.cc/ 思思今天使用了一下,真是非常方便,瞬间爱上呀,哈哈. 赶紧去试试吧...

  3. Scala:类,对象和特征(接口)

    http://blog.csdn.net/pipisorry/article/details/52902609 Scala类和对象 类是对象的抽象,而对象是类的具体实例.类是抽象的,不占用内存,而对象 ...

  4. [二] java8 函数式接口详解 函数接口详解 lambda表达式 匿名函数 方法引用使用含义 函数式接口实例 如何定义函数式接口

    函数式接口详细定义 package java.lang; import java.lang.annotation.*; /** * An informative annotation type use ...

  5. [六] 函数式接口的复合方法示例 predicate 谓词逻辑运算 Function接口 组合运算 比较器 逆序 比较链

    复合的方法 有些函数式接口提供了允许复合的方法 也就是可以将Lambda表达式复合成为一个更加复杂的方法 之前的章节中有说到: 接口中的compose, andThen, and, or, negat ...

  6. linux 上部署 YApi 可视化接口管理平台

    linux 上部署 YApi 可视化接口管理平台: YApi 是一个高效.易用.功能强大的可视化接口管理平台,官方地址 : http://yapi.demo.qunar.com/ 环境要求 nodej ...

  7. 最实用的IT类网站及工具大集合

    1.聚合数据 大家在开发过程中,可能会用到各种各样的数据,想找一些接口来提供一些数据.比如天气预报查询,火车时刻表查询,彩票查询,身份证查询等等.有了这个接口,直接调用即可.各种各样的API接口满足你 ...

  8. C# 开源框架

    一.AOP框架        Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase 独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种 ...

  9. 闲聊——浅谈前端js模块化演变

    function时代 前端这几年发展太快了,我学习的速度都跟不上演变的速度了(门派太多了,后台都是大牛公司支撑类似于facebook的react.google的angular,angular的1.0还 ...

随机推荐

  1. 《Drools7.0.0.Final规则引擎教程》Springboot+规则重新加载

    在<Drools7.0.0.Final规则引擎教程>之Springboot集成中介绍了怎样将Drools与Springboot进行集成,本篇博客介绍一下集成之后,如何实现从数据库读取规则并 ...

  2. 目标检测 - Tensorflow Object Detection API

    一. 找到最好的工具 "工欲善其事,必先利其器",如果你想找一个深度学习框架来解决深度学习问题,TensorFlow 就是你的不二之选,究其原因,也不必过多解释,看过其优雅的代码架 ...

  3. Android 框架学习3:从 EventBus 中学到的精华

    关联文章: EventBus 3.0 的特点与如何使用 源码分析 EventBus 3.0 如何实现事件总线 学习的目的是为了超越,经过前面对 EventBus 3.0 的学习,我们已经对它相当熟悉了 ...

  4. 《PyQt5 快速开发与实战》 第九章代码Bug修正 DataGrid.py 最后一页下翻页 仍可点击的错误

    # -*- coding: utf-8 -*- import sys import re from PyQt5.QtWidgets import (QWidget , QHBoxLayout , QV ...

  5. linux中使用yum进行软件的安装

    yum 仓库 配置信息/etc/yum.reposd/ [linuxcast]name="this is soft ware"baseurl="http://ww.bai ...

  6. JAVA多线程----用--进阶--》网络编程1

    http://www.cnblogs.com/springcsc/archive/2009/12/03/1616413.html 一个服务器端一般都需要同时为多个客户端提供通讯,如果需要同时支持多个客 ...

  7. Android:数据持久化(1/2)文件、SharedPreferences

    Summary 持久化的3种方法: 普通文件:I/O流操作文件: SharedPreferences:XML文件,通过key-value pair的形式存储数据: SQLite:Android自带数据 ...

  8. WPF 程序无法触摸操作?我们一起来找原因和解决方法!

    WPF 自诞生以来就带着微软先生的傲慢.微软说 WPF 支持触摸,于是 WPF 就真的支持触摸了.对,我说的是"支持触摸",那种摸上去能点能动的:偶尔还能带点儿多指的炫酷效果.但是 ...

  9. Docker环境下eShopOnContainers部署

    从头开始学eShopOnContainers--Visual Studio 2017环境配置 https://www.cnblogs.com/dusthunter/p/9973815.html 一.安 ...

  10. L2-017. 人以群分

    社交网络中我们给每个人定义了一个“活跃度”,现希望根据这个指标把人群分为两大类,即外向型(outgoing,即活跃度高的)和内向型(introverted,即活跃度低的).要求两类人群的规模尽可能接近 ...