Beispiel #1
0
        /// <summary>
        /// Remove any false colleagues from the database
        /// </summary>
        private void RemoveFalseColleagues_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            this.Cursor  = Cursors.WaitCursor;

            Database DB     = new Database(DSN.Text);
            int      Before = DB.GetIntValue("SELECT Count(*) FROM StarColleagues");

            if (useAlternateCheckbox.Checked)
            {
                ColleagueFinder.RemoveFalseColleagues(DB, this, alternateTableName.Text);
            }
            else
            {
                ColleagueFinder.RemoveFalseColleagues(DB, this, "PeoplePublications");
            }
            int After   = DB.GetIntValue("SELECT Count(*) FROM StarColleagues");;
            int Removed = Before - After;

            AddLogEntry("Removed " + Removed.ToString() + " false colleague" +
                        ((Removed == 1) ? "" : "s"));

            UpdateStatus();

            this.Cursor  = Cursors.Default;
            this.Enabled = true;
        }
Beispiel #2
0
        /// <summary>
        /// Retrieve the publications for found colleagues
        /// </summary>
        private void RetrieveColleaguePublications_Click(object sender, EventArgs e)
        {
            if (!SetApiKeyFromFormField())
            {
                return;
            }

            this.Enabled = false;
            this.Cursor  = Cursors.WaitCursor;

            // Set the language restriction
            string[] Languages = null;
            if (LanguageList.Text != "")
            {
                Languages = LanguageList.Text.Split(',');
                foreach (string Language in Languages)
                {
                    AddLogEntry("Adding language restriction: " + Language);
                }
            }
            else
            {
                AddLogEntry("No language restriction added");
            }

            Database DB = new Database(DSN.Text);

            // Clear any publications left over after an interruption
            DB.ExecuteNonQuery(
                @"DELETE p.* FROM ColleaguePublications p, Colleagues c
                   WHERE c.Setnb = p.Setnb
                     AND c.Harvested = 0"
                );

            // Clear any errors
            int NumberOfErrors = DB.GetIntValue("SELECT Count(*) FROM Colleagues WHERE Error IS NOT NULL");

            AddLogEntry("Clearing " + NumberOfErrors.ToString() + " colleagues with errors");
            DB.ExecuteNonQuery(
                @"DELETE p.* FROM ColleaguePublications p, Colleagues c
                   WHERE c.Setnb = p.Setnb
                     AND c.Error IS NOT NULL"
                );
            DB.ExecuteNonQuery(
                @"UPDATE Colleagues 
                     SET Harvested = 0, Error = NULL, ErrorMessage = NULL
                   WHERE Error IS NOT NULL"
                );
            NumberOfErrors = DB.GetIntValue("SELECT Count(*) FROM Colleagues WHERE Error = 1");
            if (NumberOfErrors != 0)
            {
                AddLogEntry("WARNING: " + NumberOfErrors + " errors were not cleared!");
            }
            UpdateStatus();

            // Retrieve the publications for each unharvested colleague
            NCBI ncbi = new NCBI("Medline");

            AddApiKeyLogEntries();

            ColleagueFinder finder = new ColleagueFinder(DB, roster, ncbi,
                                                         GetPeoplePublicationTableName());
            People Colleagues = new People(DB, "Colleagues");
            int    Total      = Colleagues.PersonList.Count;
            int    Count      = 0;

            toolStripProgressBar1.Minimum = 0;
            toolStripProgressBar1.Maximum = Total;
            foreach (Person person in Colleagues.PersonList)
            {
                Count++;
                toolStripProgressBar1.Value = Count;
                statusStrip1.Refresh();
                if (person.Harvested == false)
                {
                    AddLogEntry("Harvesting publications for colleague " + person.Last + " (" + person.Setnb + "), " + Count.ToString() + " of " + Total.ToString());
                    UpdateStatus();

                    // Check for existing publications in ColleaguePublications
                    ArrayList Parameters = new ArrayList();
                    Parameters.Add(Database.Parameter(person.Setnb));
                    int ExistingPublications = DB.GetIntValue(
                        "SELECT Count(*) FROM ColleaguePublications WHERE Setnb = ?", Parameters);
                    if (ExistingPublications > 0)
                    {
                        DB.ExecuteNonQuery("UPDATE Colleagues SET Harvested = 1 WHERE Setnb = ?", Parameters);
                        AddLogEntry(ExistingPublications.ToString() + " publications already exist for colleague " + person.Last + " (" + person.Setnb + "), " + Count.ToString() + " of " + Total.ToString());
                    }
                    else
                    {
                        Person[] personArray = new Person[1];
                        personArray[0] = person;
                        try
                        {
                            List <int> allowedPubTypes = new List <int>();
                            foreach (string type in AllowedPubTypeCategories.Text.Split(','))
                            {
                                allowedPubTypes.Add(int.Parse(type));
                            }
                            finder.GetColleaguePublications(personArray, Languages, allowedPubTypes);
                            GC.Collect(); // no need to wait for finalizers, because they don't do anything
                        }
                        catch (Exception ex)
                        {
                            AddLogEntry(ex.Message);

                            // Set the error for the colleague
                            Parameters = new ArrayList();
                            Parameters.Add(Database.Parameter(ex.Message));
                            Parameters.Add(Database.Parameter(person.Setnb));
                            DB.ExecuteNonQuery(
                                @"UPDATE Colleagues 
                                     SET Error = 1, ErrorMessage = ?
                                   WHERE Setnb = ?", Parameters);
                        }
                    }
                    UpdateStatus();
                }
                else
                {
                    AddLogEntry("Already harvested publications for colleague " + person.Last + " (" + person.Setnb + "), " + Count.ToString() + " of " + Total.ToString());
                }
            }

            this.Cursor  = Cursors.Default;
            this.Enabled = true;
        }
Beispiel #3
0
        public void UpdateStatus()
        {
            try
            {
                Database UpdateDB = new Database(DSN.Text);
                bool     TablesCreated;
                int      NumPeople;
                int      NumHarvestedPeople;
                int      NumPublications;
                int      NumErrors;
                UpdateDB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors);
                this.TablesCreated.Text = TablesCreated.ToString();
                this.TablesCreated.Refresh();
                this.People.Text = NumPeople.ToString();
                this.People.Refresh();
                this.PeopleHarvested.Text = NumHarvestedPeople.ToString();
                this.PeopleHarvested.Refresh();
                this.PublicationsFound.Text = NumPublications.ToString();
                this.PublicationsFound.Refresh();

                // People With Errors textbox -- set it to red if there are errors
                this.PeopleWithErrors.Text = NumErrors.ToString();
                if (NumErrors > 0)
                {
                    PeopleWithErrors.BackColor = Color.Red;
                }
                else
                {
                    PeopleWithErrors.BackColor = People.BackColor;
                }

                this.PeopleNotHarvested.Text = ((int)(NumPeople - NumHarvestedPeople)).ToString();

                // People Not Harvested textbox -- set it to red if there are unharvested
                // people and the software is not currently processing
                if (NumPeople - NumHarvestedPeople > 0)
                {
                    PeopleNotHarvested.BackColor = Color.Red;
                }
                else
                {
                    PeopleNotHarvested.BackColor = People.BackColor;
                }


                // Get the colleague status, enable buttons appropriately
                int DiadsFound;
                int ColleaguesFound;
                int ColleaguesHarvested;
                int ColleaguePublications;
                int StarsWithColleagues;
                ColleagueFinder.GetDBStatus(UpdateDB, out ColleaguesFound, out DiadsFound, out ColleaguesHarvested, out ColleaguePublications, out StarsWithColleagues);
                this.DiadsFound.Text            = DiadsFound.ToString();
                this.ColleaguesFound.Text       = ColleaguesFound.ToString();
                this.ColleaguesHarvested.Text   = ColleaguesHarvested.ToString();
                this.ColleaguePublications.Text = ColleaguePublications.ToString();
                this.StarsWithColleagues.Text   = StarsWithColleagues.ToString();

                // Colleagues With Errors textbox -- set it to red if there are errors
                // (first check ColleaguesFound so we don't issue this SELECT against a database with no Colleagues table)
                if (ColleaguesFound > 0)
                {
                    try
                    {
                        NumErrors = UpdateDB.GetIntValue("SELECT Count(*) FROM Colleagues WHERE Error IS NOT NULL");
                        this.ColleaguesWithErrors.Text = NumErrors.ToString();
                    }
                    catch (Exception ex)
                    {
                        this.ColleaguesWithErrors.Text = ex.Message;
                        NumErrors = -1;
                    }
                    if (NumErrors != 0)
                    {
                        ColleaguesWithErrors.BackColor = Color.Red;
                    }
                    else
                    {
                        ColleaguesWithErrors.BackColor = People.BackColor;
                    }
                }

                // Enable/disable buttons
                if (ColleaguesFound == 0)
                {
                    RetrieveColleaguePublications.Enabled = false;
                    CopyPublicationsFromAnotherDB.Enabled = false;
                }
                else
                {
                    RetrieveColleaguePublications.Enabled = true;
                    CopyPublicationsFromAnotherDB.Enabled = true;
                }

                if (ColleaguePublications > 0)
                {
                    RemoveFalseColleagues.Enabled = true;
                }
                else
                {
                    RemoveFalseColleagues.Enabled = false;
                }


                // Roster status -- disable buttons if the roster is not loaded
                if (roster != null)
                {
                    this.RosterRows.Text            = roster.RosterData.Rows.Count.ToString();
                    FindPotentialColleagues.Enabled = true;
                }
                else
                {
                    this.RosterRows.Text                  = "not loaded";
                    FindPotentialColleagues.Enabled       = false;
                    RetrieveColleaguePublications.Enabled = false;
                    CopyPublicationsFromAnotherDB.Enabled = false;
                }

                Application.DoEvents();
            }
            catch
            {
                //
            }
        }
Beispiel #4
0
        /// <summary>
        /// Generate the colleagues using the Colleagues class
        /// </summary>
        private void FindPotentialColleagues_Click(object sender, EventArgs e)
        {
            if (!SetApiKeyFromFormField())
            {
                return;
            }

            // If the tables aren't populated, don't look for colleagues.
            Database UpdateDB = new Database(DSN.Text);
            bool     TablesCreated;
            int      NumPeople;
            int      NumHarvestedPeople;
            int      NumPublications;
            int      NumErrors;

            UpdateDB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors);
            if ((!TablesCreated) || (NumPeople == 0) || (NumHarvestedPeople == 0))
            {
                MessageBox.Show("Please select a database that the Publication Harvester has been run on.", "Specify a Valid Database", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }


            // Reset the database by default -- if the user says "Yes" when asked,
            // then continue from the previous search.
            bool ResetDatabase = true;

            if (DiadsFound.Text != "0")
            {
                if (MessageBox.Show("Colleagues have already been found. Are you sure you want to re-find them (or continue the previous search)?",
                                    "Re-find Colleagues?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.No)
                {
                    return;
                }

                if (MessageBox.Show("Should the colleague search continue where it was previously left off? (Click 'No' to reset the database and start finding new colleagues.)",
                                    "Continue from previous search?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes)
                {
                    ResetDatabase = false;
                }
            }
            this.Enabled = false;
            this.Cursor  = Cursors.WaitCursor;
            Database DB = new Database(DSN.Text);

            // Use the ResetDatabase variable to determine whether or not to resume
            // a past find. If resuming, get the Setnb's of stars from the StarColleagues
            // table so they can be skipped.
            if (ResetDatabase)
            {
                ColleagueFinder.CreateTables(DB);
            }
            DataTable StarSetnbsResult = DB.ExecuteQuery("SELECT StarSetnb FROM StarColleagues");
            ArrayList StarSetnbs       = new ArrayList();

            foreach (DataRow Row in StarSetnbsResult.Rows)
            {
                if (!(StarSetnbs.Contains(Row[0].ToString())))
                {
                    StarSetnbs.Add(Row[0].ToString());
                }
            }

            NCBI ncbi = new NCBI("Medline");

            AddApiKeyLogEntries();

            ColleagueFinder finder = new ColleagueFinder(DB, roster, ncbi,
                                                         GetPeoplePublicationTableName());
            People Stars    = new People(DB);
            int    NumStars = Stars.PersonList.Count;

            toolStripProgressBar1.Minimum = 0;
            toolStripProgressBar1.Maximum = NumStars;
            int Count = 0;

            foreach (Person Star in Stars.PersonList)
            {
                Count++;
                toolStripProgressBar1.Value = Count;
                statusStrip1.Refresh();
                Application.DoEvents();
                if (StarSetnbs.Contains(Star.Setnb))
                {
                    AddLogEntry("Already found colleagues for " + Star.Last + " (" + Star.Setnb + "), " + Count.ToString() + " of " + NumStars.ToString());
                }
                else
                {
                    AddLogEntry("Finding " + Star.Last + " (" + Star.Setnb + "), " + Count.ToString() + " of " + NumStars.ToString());
                    UpdateStatus();
                    Person[] Colleagues = finder.FindPotentialColleagues(Star);
                }
            }
            UpdateStatus();
            this.Cursor  = Cursors.Default;
            this.Enabled = true;
        }
Beispiel #5
0
        /// <summary>
        /// Retrieve all of the publications a set of colleagues
        /// </summary>
        /// <param name="Star">Star whose colleagues are being retrieved</param>
        /// <param name="Colleagues">List of colleagues whose publications should be retrieved</param>
        public void GetColleaguePublications(Person[] Colleagues, string[] Languages, List <int> AllowedPubTypeCategories)
        {
            // Keep a list of written Setnbs, just to make sure we don't write the
            // same colleage twice
            ArrayList WrittenSetnbs = new ArrayList();

            // Process each colleague
            foreach (Person Colleague in Colleagues)
            {
                // Only process a colleague that hasn't yet been touched
                if (!WrittenSetnbs.Contains(Colleague.Setnb))
                {
                    WrittenSetnbs.Add(Colleague.Setnb);

                    // Get the colleague's publications
                    // Search NCBI -- if an error is thrown, write that error to the database
                    string results;
                    try
                    {
                        results = ncbi.Search(Colleague.MedlineSearch);
                    }
                    catch (Exception ex)
                    {
                        string Message = "Error reading publications for "
                                         + Colleague.Last + " (" + Colleague.Setnb + ex.Message;
                        ColleagueFinder.WriteErrorToDB(Message, DB, Colleague);
                        throw new Exception(Message);
                    }

                    // Turn the results into a set of publications for the colleague
                    if ((results != null) && (results.Trim() != ""))
                    {
                        Publications ColleaguePublications = new Publications(results, pubTypes);

                        // Write the publications to the database -- but only if they
                        // actually belong to the colleague.
                        if (ColleaguePublications.PublicationList != null)
                        {
                            foreach (Publication pub in ColleaguePublications.PublicationList)
                            {
                                // If the publication has no authors, it's clearly not actually
                                // a publication that belongs to this colleague.
                                // Also, since the publication harvester only harvests
                                // English publications, we exclude any non-English ones as well.
                                if ((pub.Authors != null) && (pub.Language == "eng") &&
                                    (AllowedPubTypeCategories.Contains(pubTypes.GetCategoryNumber(pub.PubType))))
                                {
                                    // Add a row to the ColleaguePublications table -- this will
                                    // return False if the publication doesn't actually belong
                                    // to the colleague
                                    bool PubBelongsToColleague = WriteColleaguePublicationsToDB(DB, Colleague, pub, pubTypes, Languages);
                                    if (PubBelongsToColleague)
                                    {
                                        // Make sure the publication doesn't already exist, then write
                                        // it to the database.
                                        if (DB.GetIntValue("SELECT Count(*) FROM Publications WHERE PMID = " + pub.PMID.ToString()) == 0)
                                        {
                                            Publications.WriteToDB(pub, DB, pubTypes, Languages);
                                        }
                                    }
                                }
                            }
                        }

                        // Update the Harvested column in the Colleagues table
                        ArrayList Parameters = new ArrayList();
                        Parameters.Add(Database.Parameter(Colleague.Setnb));
                        DB.ExecuteNonQuery("UPDATE Colleagues SET Harvested = 1 WHERE Setnb = ?", Parameters);
                    }
                }
            }
        }