Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:02:31+00:00 2026-06-02T01:02:31+00:00

Basically I have these files (medline from NCBI). Each is associated with a journal

  • 0

Basically I have these files (medline from NCBI). Each is associated with a journal title. Each has 0, 1 or more genbank identification numbers (GBIDs). I can associate the number of GBIDs per file with each journal name. My problem is that I may have more than one file associated with the same journal, and I don’t know how to add the number of GBIDs per file into a total number of GBIDs per journal.

My current code:
jt stands for journal title, pulled out properly from the file. GBIDs are added to the count as encountered.

Full code:

 #!/usr/local/bin/ruby

 require 'rubygems'
 require 'bio'


Bio::NCBI.default_email = 'kepresto@uvm.edu'

ncbi_search = Bio::NCBI::REST::ESearch.new
ncbi_fetch = Bio::NCBI::REST::EFetch.new


print "\nQuery?\s" 

query_phrase = gets.chomp

"\nYou said \"#{query_phrase}\". Searching, please wait..."

pmid_list = ncbi_search.search("pubmed", "#{query_phrase}", 0)

puts "\nYour search returned #{pmid_list.count} results."

if pmid_list.count > 200
puts "\nToo big."
exit
end

gbid_hash = Hash.new
jt_hash = Hash.new(0)


pmid_list.each do |pmid|

ncbi_fetch.pubmed(pmid, "medline").each do |pmid_line|

    if pmid_line =~ /JT.+- (.+)\n/
        jt = $1
        jt_count = 0
        jt_hash[jt] = jt_count

        ncbi_fetch.pubmed(pmid, "medline").each do |pmid_line_2|

            if pmid_line_2 =~ /SI.+- GENBANK\/(.+)\n/
                gbid = $1
                jt_count += 1
                gbid_hash["#{gbid}\n"] = nil
            end 
        end 

        if jt_count > 0
            puts "#{jt} = #{jt_count}"

        end
        jt_hash[jt] += jt_count
    end
end
end


jt_hash.each do |key,value|
# if value > 0
    puts "Journal: #{key} has #{value} entries associtated with it. "
# end
end

# gbid_file = File.open("temp_*.txt","r").each do |gbid_count|
#   puts gbid_count
# end

My result:

 Your search returned 192 results.
 Virology journal = 8
 Archives of virology = 9
 Virus research = 1
 Archives of virology = 6
 Virology = 1

Basically, how do I get it to say Archives of virology = 15, but for any journal title? I tried a hash, but the second archives of virology just overwrote the first… is there a way to make two keys add their values in a hash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:02:32+00:00Added an answer on June 2, 2026 at 1:02 am

    I don’t entirely follow what you are asking for here.

    However, you are overwriting your value for a given hash key because because you are doing this:

    jt_count = 0
    jt_hash[jt] = jt_count
    

    You already initialized your hash earlier like this:

    jt_hash = Hash.new(0)
    

    That is, every key will have a default value of 0. Thus, there’s no need to do initialize jt_hash[jt] to 0.

    If you remove this line:

     jt_hash[jt] = jt_count
    

    Then the values for jt_hash[jt] should accumulate for each pass through the loop

    ncbi_fetch.pubmed(pmid, "medline").each do |pmid_line|
      ....
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have requirements from our client where we basically have to 'parse' PDF files
Basically i have these two pages... each with a string that i get with
So! Basically I have a database with a load of blog posts, these are
We have two separate web-apps, say 'retailUI' and 'bulkUI'. These two are basically two
Okay basically here's where I'm at. I have a list of PropertyDescriptor objects. These
We have an application that basically archives files and we give the user the
We have these files: Action.php <?php $array = array( 0 => array( 'id' =>
I must have done something very stupid which has caused the following situation. Basically
To jog everyone's memory, Java has these files with an extension of .properties, which
I would like to rename these files to not have the ending of (.processed2011*)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.