Aug 12

We are on a grant writing mode. As I’m not actively participating of the writing per se, I decided to help on the background. We needed something to gather all the references and save them in a format that some software like Endnote was capable of reading. As I mentioned before BioPython seems really convoluted when accessing PubMed, so I decided to go with BioRuby. We had the references entries and their PMID organized this way


Goldman, JM, Melo JV 2003 NEJM 349:1451 14534339
Lewis GD 1993 Cancer Immunol Immun other 37: 255 8102322
McShane LM 2009 Clin Canc Res 15: 1898 19276274
Fox JL 2007 Nature Biotech 25: 489 17483821
Bodin L 2005 Blood 106: 135 15790782

basically author name(s), journal information, two tabs and the PMID at the end of each row. From this I would need to search PubMed for the ID and download a formatted reference. The script I used was this

require 'rubygems'
require 'bio'

my_file = File.new(ARGV[0])
refs = my_file.readlines
ids = []

refs.each do |line|
  pmid = line.strip().split("\t")
  ids.push(pmid[2])
end

ids.each do |id|
   entry = Bio::PubMed.query(id)
   medline = Bio::MEDLINE.new(entry)
   reference = medline.reference
   puts reference.endnote
end

The file name with the refs table is passed to the script that reads its entirety, ids is initialized as an array and the PMIDs are extracted from each line, by using a split on the tabs (not forgetting to remove the carriage return/line feed with strip) and saved in the ids array.

After that, by iterating over the ids array, we use the Bio::PubMed to query PubMed in order get the reference in PubMed format and then by using the Bio::MEDLINE we get the reference, which then can be output onto an Endnote format.

Quite simple and useful.

Reblog this post [with Zemanta]
Aug 08

I recently installed BioRuby on my machine and yesterday I need some script to access and get some pubmed IDs from NCBI. I had some time to write the script, so I decided to compare the functionality of BioRuby with BioPython. As I have more Python knowledge, I decided to start with it. Turns out, it’s very complicated to get some PMIDs from search timers in BioPython. The programming is quite convoluted and not clear, maybe the tutorial doesn’t help.

I then decided to check BioRuby. I went to their wiki page and found exactly what I wanted, a short script that would return a list of PMIDs from search terms. And to my surprise, much simpler than anything I needed to do on BioPython. You can check the script below

require 'rubygems'
require 'bio'

keywords = ARGV.join(' ')

options = {
  'retmax' => 1
}

entries = Bio::PubMed.esearch(keywords, options)

Bio::PubMed.efetch(entries).each do |entry|
  medline = Bio::MEDLINE.new(entry)
  reference = medline.reference
  puts reference.bibtex
end

The only differences to the script on the wiki are the require ‘rubygems’ that needs to be added due to the fact I’m on a Mac (using the default 1.8 version) and some small changes in the options hash, instead of returning 1000 I modified to return just the top result. The scripts searches fine, seems to download the data, but the output is quite strange. Apparently, each record is being split into different output records


@article{PMID:,
author = {Ji, R. Y.},
journal = {},
year = {},
volume = {},
}
@article{PMID:,
journal = {},
year = {},
volume = {},
}
@article{PMID:,
journal = {},
year = {},
volume = {},
}
@article{PMID:,
journal = {},
year = {},
volume = {},
}
@article{PMID:,
journal = {},
year = {},
volume = {},
}
@article{PMID:,
journal = {Yao Xue Xue Bao},
year = {},
volume = {},
}

It’s very weird, don’t know if there’s a bug on my code or on BioRuby modules. Any help appreciated.

Aug 08

Long time since I posted here, no updates at all. During this time I’m trying a different approach to learn a language: I’m actually reading the books and trying to immerse myself in the language. Basically I’m following three books, two at home and one at the office. These are the books I’m reading

Home
The Ruby Programming Language
The Well-Grounded Rubyist

Office
Programming Ruby 1.9: The Pragmatic Programmers’ Guide (Facets of Ruby)

Of all three, the one I’m enjoying most is the Well Ground Rubyist, which is very clear and very well written.IT has a good introduction and nice examples. It’s not too deep (until the point I’m reading) and not too shallow. Really recommend it. Because of this I might have left The Ruby Programming Language on a forgotten corner.

I also like Programming Ruby 1.9, but it’s deeper than WGR. In one of the initial chapters it already has some unit tests. WGR is better written, but this is not a problem with PR1.9.

So far, I’m enjoying.

Mar 27
Ruby on Rails
Image via Wikipedia

My first real contact with Ruby was a couple of years ago when I decided to find out more about Ruby on Rails, the famous web framework. My idea was to learn a little bit more of programming and the Model-View-Controller. I think at the time I had a couple of chapters of the Agile Web Development with Rails and did a little bit of the bookstore tutorial. At first glance, for a biologist, RoR was incredibly good and powerful. Just the fact that RoR “understands” your database and gets the fields and values with minimal coding is enough to find some reason to learn it.

I don’t know what happened and I ended up not having much time to continue learning and then Ruby and RoR were put on the backburner. Until late last year, at least. I god the third edition of Agile Web Development with Rails, which I highly recommend, and restarted the whole process. I was able to recreate the bookstore (not until the end, I admit) and even convert a desktop Python application to RoR.

But as everything done without method, the learning and conversion process was much more difficult than I expected. Particularly the deployment of the RoR app to a different webserver. So I decided to start from the beginning, got a couple more Ruby books and will learn from the beginning and try to use it in my daily programming routine, either converting Python scripts or new ones in Ruby.

Reblog this post [with Zemanta]
Mar 25
Official Ruby logo
Image via Wikipedia

Why Ruby? The same way why it was Python a couple of years ago. Just curiosity, but this time I have almost no background in Ruby as I had in Python when I started Beginning Python for Bioinformatics. This time is a different approach, I will tell my experiences in learning Ruby (and some Ruby on Rails) along the way, while applying it to Bioinformatics tasks.

Stay tuned, it will be a bumpy ride …

Reblog this post [with Zemanta]