Skip to content

Instantly share code, notes, and snippets.

View cknoxrun's full-sized avatar

Craig Knox cknoxrun

View GitHub Profile
@cknoxrun
cknoxrun / gist:441276
Created June 16, 2010 21:12
A small module to download and convert PubMed citations to TextTile format.
require 'rubygems'
require 'bio'
module PubMed
# Download and annotate the given pubmed_id and return a citation in textile format.
# Example Citation:
# Smythe MA, Stephens JL, Koerber JM, Mattson JC: A comparison of lepirudin and argatroban outcomes.
# Clin Appl Thromb Hemost. 2005 Oct;11(4):371-4. "Pubmed":http://www.ncbi.nlm.nih.gov/pubmed/16244762
def PubMed.annotate(pubmed_id)
require 'zip/zip'
# Interface to the mutfinder library
class ReadAnalysis
@@nml_dir = File.join(Rails.root, 'lib', 'mutfinder')
@@result_dir = File.join(@@nml_dir, '/var/results/')
# Main entry point for analysis. Just pass an analysis ID
# (An object is not passed because this doesnt work with delayed_job)
def check_cas_number
# Check the CAS number for validity (the last number in a CAS number is a checksum)
if cas_number.present?
matches = cas_number.scan(/^(\d{1,7})-(\d{1,2})-(\d)$/)
if matches.first.blank? || matches.first.size != 3
self.errors.add(:cas_number, "format invalid")
else
match = matches.first
require 'zip/zipfilesystem'
require 'builder'
namespace :hmdb do
namespace :export do
DOWNLOAD_PATH = 'public/downloads'
desc "Run all export tasks"
task :all => [ :xml, :structures, :sequences ]
# desc 'Export all compounds to json format'
require 'zip/zipfilesystem'
require 'builder'
namespace :hmdb do
namespace :export do
DOWNLOAD_PATH = 'public/downloads'
desc "Run all export tasks"
task :all => [ :xml, :structures, :sequences ]
# desc 'Export all compounds to json format'
def concentration_value(c)
unit = ""
conc = c.conc_value
mean = 0
error = 0
if (conc.nil?)
return ""
elsif(conc == "Detected")
mean = -1
########################################################################
#
# This class finds properties of a compound, given the SMILES string.
# For required programs, check the comments before each method.
#
# Written by Roman Eisner, 2010
#
# Updated by Yannick Djoumbou
#######################################################################
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
# Render 404: Not Found
def render_404(exception = nil)
logger.info( clean_backtrace(exception, "Rendering 404 due to exception") )
if /(jpe?g|png|gif)/i === request.path
# Images should simply return the error as text
require 'nokogiri'
require 'open-uri'
module Uniprot
# Download and annotate the given uniprot_id and return an entry as an array
def Uniprot.annotate_name(uniprot_id)
doc = Nokogiri::XML( open("http://www.uniprot.org/uniprot/#{uniprot_id}.xml") )
doc.remove_namespaces!
name_node = doc.at_xpath("//recommendedName/fullName")
def index
options = params
options[:page] ||= 1
options[:limit] ||= 50
@pathway_visualizations =
PathwayVisualization.search(load: true, page: options[:page],
per_page: options[:limit]) do |search|
if options[:term].present?
search.query do |query|