Example #1
0
        //EInfo, Get Databases
        //EGQuery, Search all databases and return database/count
        //ESearch, Search a database and return a list of UIDs
        //ESummary, Turn UID into Document Summary
        //EFetch, Turn UID into formatted data records
        //EFetch, see http://www.ncbi.nlm.nih.gov/books/NBK25499/table/chapter4.chapter4_table1/?report=objectonly
        //ELink, List links, and more
        //ELink, see http://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ELink
        //EPost, Append UIDs to a list of UIDs
        //ESpell, Suggests ?improved queries? and spelling fixes.
        static void Main(string[] args)
        {
            //Current Plan
            //Get Article IDs from PMC
            //Get Journal name, File Name, and Date
            //Sort by Journal Name
            //Extract tars
            //Keep only the Journals & Articles we care about.
            //
            //Processing ?? Co-Word Occurance ??
            //Stop Words = 1:5000 checking every 500,000 words.
            string myQuery = "((\"hiv\"[MeSH Terms] OR \"hiv\"[All Fields]) OR (\"acquired immunodeficiency syndrome\"[MeSH Terms] OR (\"acquired\"[All Fields] AND \"immunodeficiency\"[All Fields] AND \"syndrome\"[All Fields]) OR \"acquired immunodeficiency syndrome\"[All Fields] OR \"aids\"[All Fields])) AND hasabstract[text]";
            string linkageFileName = "Links.txt";
            string articleFileName = "Articles.csv";
            //myQuery      = "( \"hiv\"[MeSH Terms] OR \"hiv\"[All Fields]) OR (\"acquired immunodeficiency syndrome\"[MeSH Terms] OR (\"acquired\"[All Fields] AND \"immunodeficiency\"[All Fields] AND \"syndrome\"[All Fields]) OR \"acquired immunodeficiency syndrome\"[All Fields] OR \"aids\"[All Fields])";
            eUtils.eUtilsServiceSoapClient utilServ = new eUtils.eUtilsServiceSoapClient();
            string database = null;
            //database = "PMC";
            eUtils.eSearchResult searchResult = GetSearchResults(database, myQuery, utilServ);

            TextWriter LinksOutputFile = new StreamWriter(linkageFileName);
            TextWriter ArticleOutputFile = new StreamWriter(articleFileName);
            ArticleOutputFile.WriteLine("PMID,Date,Title,Abstract,MeSH,Citation,Grant");

            int Total = int.Parse(searchResult.Count);

            while (searchResult != null)
            {
                if (int.Parse(searchResult.RetStart) > 1000)
                    break;
                foreach (string paper in searchResult.IdList)
                {
                    #region Article Links
                    eUtils.eLinkResult linkResults = GetLinkResults(paper, utilServ);
                    //if (linkResults.LinkSet.Length != 0)
                    //{
                    LinksOutputFile.Write(paper);
                    foreach (var a in linkResults.LinkSet)
                        foreach (var b in a.LinkSetDb)
                            foreach (var c in b.Link)
                                if (c.Id.Value != paper && b.DbTo.ToLower() == "pubmed")
                                    LinksOutputFile.Write(" " + c.Id.Value);
                    LinksOutputFile.WriteLine();
                    //}
                    //else
                    //{
                    //    //No References!?!?
                    //    //Should probably remove from Dataset.
                    //    throw new ArgumentNullException("linkResults", "PubMED ID: " + paper + " has no references, which is improbable to impossible.  Throwing Error");
                    //}
                    #endregion
                    #region Article Title, Abstract, and Date
                    eFetch_pubmed.eUtilsServiceSoapClient fetchServ = new eFetch_pubmed.eUtilsServiceSoapClient();
                    eFetch_pubmed.eFetchRequest fetchRequest = new eFetch_pubmed.eFetchRequest();
                    fetchRequest.id = paper;
                    //fetchRequest.id = string.Join(",", Results);
                    eFetch_pubmed.eFetchResult fetchResult = fetchServ.run_eFetch(fetchRequest);
                    for (int i = 0; i < fetchResult.PubmedArticleSet.Length; i++)
                    {
                        eFetch_pubmed.PubmedArticleType art = null;
                        //eFetch_pubmed.PubmedBookArticleType book = null;

                        if (fetchResult.PubmedArticleSet[i] is eFetch_pubmed.PubmedArticleType)
                        {
                            art = (eFetch_pubmed.PubmedArticleType)fetchResult.PubmedArticleSet[i];
                            if (art.PubmedData.History == null)
                            {
                                art.PubmedData.History = new eFetch_pubmed.PubMedPubDateType[1];
                                art.PubmedData.History[0] = new eFetch_pubmed.PubMedPubDateType();
                                art.PubmedData.History[0].Year = "N/A";
                                art.PubmedData.History[0].Month = string.Empty;
                                art.PubmedData.History[0].Day = string.Empty;
                            }
                            if(art.MedlineCitation.Article.ArticleTitle != null)
                                ArticleOutputFile.Write(string.Join(",",
                                    art.MedlineCitation.PMID.Value,
                                    art.PubmedData.History[0].Year + " " + art.PubmedData.History[0].Month + " " + art.PubmedData.History[0].Day,
                                    //art.MedlineCitation.Article.ArticleDate != null ? art.MedlineCitation.Article.ArticleDate[0].Year + " " + art.MedlineCitation.Article.ArticleDate[0].Month + " " + art.MedlineCitation.Article.ArticleDate[0].Day : "N/A",
                                    '"' + art.MedlineCitation.Article.ArticleTitle.Value.Replace("\"", "''") + '"',
                                    '"' + art.MedlineCitation.Article.Abstract.AbstractText[0].Value.Replace("\"", "''") + '"',
                                    art.MedlineCitation.MeshHeadingList != null ? '"' + string.Join(" ", art.MedlineCitation.MeshHeadingList.Select(o => o.DescriptorName.Value)) + '"' : "N/A",
                                    art.MedlineCitation.CitationSubset != null ? string.Join(" ", art.MedlineCitation.CitationSubset) : "N/A",
                                    (art.MedlineCitation.Article.GrantList != null && art.MedlineCitation.Article.GrantList.Grant != null) ?
                                    string.Join(" ", art.MedlineCitation.Article.GrantList.Grant.Select(o => o.Agency)) : "N/A"));
                            else if(art.MedlineCitation.Article.Journal.Title != null)
                                ArticleOutputFile.Write(string.Join(",",
                                    art.MedlineCitation.PMID.Value,
                                    art.PubmedData.History[0].Year + " " + art.PubmedData.History[0].Month + " " + art.PubmedData.History[0].Day,
                                    '"' + art.MedlineCitation.Article.Journal.Title.Replace("\"", "''") + '"',
                                    '"' + art.MedlineCitation.Article.Abstract.AbstractText[0].Value.Replace("\"", "''") + '"',
                                    art.MedlineCitation.MeshHeadingList != null ? '"' + string.Join(" ", art.MedlineCitation.MeshHeadingList.Select(o => o.DescriptorName.Value)) + '"' : "N/A",
                                    art.MedlineCitation.CitationSubset != null ? string.Join(" ", art.MedlineCitation.CitationSubset) : "N/A",
                                    (art.MedlineCitation.Article.GrantList != null && art.MedlineCitation.Article.GrantList.Grant != null) ?
                                    string.Join(" ", art.MedlineCitation.Article.GrantList.Grant.Select(o => o.Agency)) : "N/A"));

                            ArticleOutputFile.WriteLine();
                            //foreach (var v in art.MedlineCitation.Article.Abstract.AbstractText)
                            //Console.WriteLine(v.Value);
                            //foreach(string a in art.MedlineCitation.CitationSubset)
                            //Console.WriteLine(a);
                        }
                        else if (fetchResult.PubmedArticleSet[i] is eFetch_pubmed.PubmedBookArticleType) { }
                        else if (fetchResult.PubmedArticleSet[i] is eFetch_pubmed.PubmedBookDataType) { }
                        else if (fetchResult.PubmedArticleSet[i] is eFetch_pubmed.PubmedDataType) { }
                        else if (fetchResult.PubmedArticleSet[i] is eFetch_pubmed.PubMedPubDateType) { }
                        else if (fetchResult.PubmedArticleSet[i] is eFetch_pubmed.PubMedPubDateTypePubStatus) { }
                    }
                    #endregion
                }
                searchResult = GetSearchResults(database, myQuery, utilServ, searchResult);
            }
            LinksOutputFile.Flush();
            LinksOutputFile.Close();
            LinksOutputFile.Dispose();
            ArticleOutputFile.Flush();
            ArticleOutputFile.Close();
            ArticleOutputFile.Dispose();
        }
Example #2
0
 private void btnGo2_Click(object sender, EventArgs e)
 {
     // example retrieves links from Nuccore for to Protein GI 48819,7140345
     try
     {
         eUtils.eUtilsServiceSoapClient serv = new eUtils.eUtilsServiceSoapClient();
         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();
     }
 }
Example #3
0
 private void btnGo_Click(object sender, EventArgs e)
 {
     // O utilitário eInfo retorna uma lista dos bancos de dados disponíveis
     try
     {
         eUtils.eUtilsServiceSoapClient serv = new eUtils.eUtilsServiceSoapClient();
         // chama o NCBI EInfo utility
         eUtils.eInfoResult res = serv.run_eInfo(new eUtils.eInfoRequest());
         // results output
         this.txtResult.Text = "";
         for (int i = 0; i < res.DbList.Items.Length; i++)
         {
             txtResult.Text += res.DbList.Items[i] + "\r\n";
         }
     }
     catch (Exception ex)
     {
         txtResult.Text = ex.ToString();
     }
 }
Example #4
0
        public string bustaTextual(String termo)
        {
            StringBuilder builder = new StringBuilder();
            StringBuilder builderFinal = new StringBuilder();
            string retorno = "";
            try
            {
                eUtils.eUtilsServiceSoapClient serv = new eUtils.eUtilsServiceSoapClient();
                // call NCBI ESearch utility
                // NOTE: search term should be URL encoded
                String inicio = "0";
                Boolean teste = true;
                int qnt = 0;
                int qntfound = 0;

                do{
                     eUtils.eSearchRequest req = new eUtils.eSearchRequest();
                     req.db = "nuccore";
                     req.term = termo.Replace(" " ,"+");
                     req.RetStart = inicio;
                     req.RetMax = "100000";
                     eUtils.eSearchResult res = serv.run_eSearch(req);
                     qntfound = Convert.ToInt32(res.Count);
                     qnt = qnt + res.IdList.Length;
                     if (qnt == qntfound)
                     {
                         builder.Clear();
                         int cont = 0;
                         for (int x = 0; x < res.IdList.Length; x++)
                         {
                             if (cont == 500)
                             {

                                 builderFinal.Append(getStringPost(createURL(builder.ToString(), "nuccore")));
                                 richTextBox1.Text += builderFinal.ToString();

                                 builderFinal.Clear();
                                 builder.Clear();
                                 cont = 0;
                             }
                             else
                             {
                                 builder.Append(res.IdList[x] + ",");
                                 cont++;
                             }

                         }

                         teste = false;
                     }
                     else
                     {
                         builder.Clear();
                         int cont = 0;
                         for (int x = 0; x < res.IdList.Length; x++)
                         {

                             if (cont == 500)
                             {

                                     builderFinal.Append(getStringPost(createURL(builder.ToString(), "nuccore")));
                                     richTextBox1.Text += builderFinal.ToString();

                                 builderFinal.Clear();
                                 builder.Clear();
                                 cont = 0;
                             }
                             else
                             {
                                 builder.Append(res.IdList[x] + ",");
                                 cont++;
                             }

                         }

                         }

                         inicio = Convert.ToString(Convert.ToInt32(inicio) + 100000);

                }while(teste);

                MessageBox.Show(Convert.ToString(qntfound) + " Id`s Encontrados e armazanados em Buffer... \n Clique em OK para MOstrar as sequências");

                 retorno = builderFinal.ToString();
                 return retorno;
            }
            catch (Exception eee)
            {
                textBox1.Text = eee.ToString();
                return retorno;
            }
        }