Problem To Getting Articles From Pubmed Webservice
1
0
Entering edit mode
12.6 years ago

Hello everyone. I am a student and I am developing an application in c# with visual studio 2010 that returns a few articles related to a given term like "anemia". The problem is : in the code that I found in the NCBI website it works fine, returns the expected (5 items). I tryed to increase this number to 20 but only returns 12 because it launches an NULL exception before that.

The items returned should be correct right? Why exist null exceptions in the middle of list?

Could anyone help how to fix this?

Best regards, Costa

the code:

        String data = null;
        String WebEnv = "";
        String query_key = "";

        // STEP #1: search in PubMed for "cat"
        //
        try
        {
            eUtils.eUtilsServiceSoapClient serv = new eUtils.eUtilsServiceSoapClient();
            // 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;

            data = "Search in PubMed for \"cat\" returned " + res.Count + " hits\r\n";
            data += "WebEnv: " + WebEnv + "\r\n";
            data += "QueryKey: " + query_key + "\r\n\r\n";

        }
        catch (Exception eee)
        {
            data += eee.ToString();
        }

        // STEP #2: fetch 5 records from pubmed starting from record #10
        //
        try
        {
            eFetchPubmed.eUtilsServiceSoapClient serv = new eFetchPubmed.eUtilsServiceSoapClient();
            // call NCBI EFetch utility
            eFetchPubmed.eFetchRequest req = new eFetchPubmed.eFetchRequest();
            req.WebEnv = WebEnv;
            req.query_key = query_key;
            req.retstart = "0";
            req.retmax = "20";
            eFetchPubmed.eFetchResult res = serv.run_eFetch(req);
            // results output
            // PubmedArticleSet array can include articles of PubmedArticleType and
            // PubmedBookArticleType types. There should be separate display method
            // for each article's type.
            for (int i = 0; i < res.PubmedArticleSet.Length; i++)
            {
                eFetchPubmed.PubmedArticleType art = null;
                eFetchPubmed.PubmedBookArticleType book = null;
                if (res.PubmedArticleSet[i] is eFetchPubmed.PubmedArticleType)
                    art = (eFetchPubmed.PubmedArticleType)res.PubmedArticleSet[i];
                else
                    book = (eFetchPubmed.PubmedBookArticleType)res.PubmedArticleSet[i];
                // show book or article
                if (art != null)
                {
                    data += "Type: Pubmed Article\r\n";
                    data += "Title: " + art.MedlineCitation.Article.ArticleTitle + "\r\n";
                    data += "Abstract: " + art.MedlineCitation.Article.Abstract.AbstractText + "\r\n";
                    data += "--------------------------\r\n\r\n";

                    count++;
                }
                else if (book != null)
                {
                    data += "Type: Pubmed Book Article\r\n";
                    data += "Title: " + book.BookDocument.ArticleTitle + "\r\n";
                    data += "--------------------------\r\n\r\n";
                }
            }
        }
        catch (Exception eee)
        {
            data += eee.ToString();
        }

        System.Diagnostics.Debug.Write(data);
pubmed webservice c • 4.6k views
ADD COMMENT
0
Entering edit mode

Please post the full stacktrace. And are you using the code exactly as shown here (are you searching for cat?) My first guess would have been that there were only 12 results, but cat gives more. Can't say more without a stacktrace though.

ADD REPLY
0
Entering edit mode

Hy!I have a problem with code that i found from NCBI website.I want to display an article and abstract in a textbox. The code is this: String WebEnv = "";

String query_key = "";



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

//

try

{

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

    // 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.eUtilsServiceSoapClient serv = new eFetchPubmed.eUtilsServiceSoapClient();

    // 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

    // PubmedArticleSet array can include articles of PubmedArticleType and

    // PubmedBookArticleType types. There should be separate display method

    // for each article's type.

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

    {

        eFetchPubmed.PubmedArticleType art = null;

        eFetchPubmed.PubmedBookArticleType book = null;

        if (res.PubmedArticleSet[i] is eFetchPubmed.PubmedArticleType)

            art = (eFetchPubmed.PubmedArticleType)res.PubmedArticleSet[i];

        else

            book = (eFetchPubmed.PubmedBookArticleType)res.PubmedArticleSet[i];

        // show book or article

        if (art != null)

        {

            textBox1.Text += "Type: Pubmed Article\r\n";

            textBox1.Text += "Title: " + art.MedlineCitation.Article.ArticleTitle + "\r\n";

            textBox1.Text += "Abstract: " + art.MedlineCitation.Article.Abstract.AbstractText + "\r\n";

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

        }

        else if (book != null)

        {

            textBox1.Text += "Type: Pubmed Book Article\r\n";

            textBox1.Text += "Title: " + book.BookDocument.ArticleTitle + "\r\n";

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

        }

    }

}

catch (Exception eee)

{

    textBox1.Text += eee.ToString();

}

And the error is this: Type: Pubmed Article Title: WindowsFormsApplication1.eFetchPubmed.ArticleTitleType Abstract: WindowsFormsApplication1.eFetchPubmed.AbstractTextType[]

Can you help me? Thank you!

ADD REPLY
1
Entering edit mode
12.6 years ago
user56 ▴ 300

Solution outside C would be to use plain XML page

Try this:

http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=cat

and then loop and for each article get details like this:

http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=22077236&retmode=xml

I did it in R with no issues.

ADD COMMENT
0
Entering edit mode

This guy knows what hes talking about ... solidi solution!

ADD REPLY

Login before adding your answer.

Traffic: 1611 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6