Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'active_rdf'
class Bio
class SPARQL
def initialize(params ={})
@adapter=ConnectionPool.add(:type => :sparql, :url => 'http://geneid.bio2rdf.org/sparql', :engine => :virtuoso)
end
irb(main):137:0>mySubject.property_accessors
=> ["type", "label", "title", "comment", "identifier", "url", "created", "modified", "replaced", "isReplacedBy", "seeAlso", "symbol", "subType", "location", "chromosome", "fromInterval", "toInterval", "xGI", "xGenBank", "xProteinID", "xTaxon", "xRef", "xEC", "synonym"]
irb(main):141:0> mySubject.xGI
=> [<RDFS::Resource:0xb7434650 @predicates={}, @uri="http://bio2rdf.org/gi:72015298">, <RDFS::Resource:0xb74345d8 @predicates={}, @uri="http://bio2rdf.org/gi:72015290">, <RDFS::Resource:0xb7434538 @predicates={}, @uri="http://bio2rdf.org/gi:72015291">]
irb(main):136:0> mySubject=myGenSemWeb.first.first
=> <RDFS::Resource:0xb74abcb4 @predicates={}, @uri="http://bio2rdf.org/geneid:578147">
irb(main):134:0> myGenSemWeb.fisrt
=> [<RDFS::Resource:0xb74abcb4 @predicates={}, @uri="http://bio2rdf.org/geneid:578147">, <RDFS::Resource:0xb74abc50 @predicates={}, @uri="http://www.w3.org/2000/01/rdf-schema#label">, "similar to TP53 regulating kinase (p53-related protein kinase) (Nori-2)[geneid:578147]"]
# Recode a vector based on a block
class Pippo
def recode!(vector_name)
0.upto(@cases-1) {|i|
@vectors[vector_name].data[i]=yield case_as_hash(i)
}
@vectors[vector_name].set_valid_data
end
end
@rjpbonnal
rjpbonnal / gist:804318
Created January 31, 2011 16:35
Recover stats from genes list using targetscan filtered by miRNA 125b
def gene_list(genes_str)
genes_str.split("\n").select{|gene| !(gene.empty? || gene.match(/LOC/))}
end
def targetted_genes(genes_ary)
Bio::Kb::Targetscan::Prediction.where(['gene_symbol IN (?) and species = 9606', genes_ary]).select("distinct gene_symbol").count
end
def targetted_125b(genes_ary)
Bio::Kb::Targetscan::Prediction.search(genes_ary,'hsa-miR-125b').count
@rjpbonnal
rjpbonnal / gist:885723
Created March 24, 2011 19:48
Esempio per il riassunto dei dati da sequenziamento
require 'yaml'
stats=YAML::load_stream(File.open("CD4_Th1_forward.stats"))
ary_stats=stats.documents
sum=0
ary_stats.each do |record|
sum += record[:stats] [: reads_total]
end
#in sum troverai il risultato
#----------
@rjpbonnal
rjpbonnal / gist:887127
Created March 25, 2011 16:23
BioRuby & Google Summer of Code 2011
Dear All,
our project, is looking for students to participate at GSoC 2011, thanks to OBF and NESCENT
Please feel free to forward this message to your university-ml, lab or local ruby group.
Use our ml to discuss ideas and feel free to contact the mentors or any other member for the development team.
March 18-27: Would-be student participants discuss application ideas with mentoring organizations.
March 28: Student application period opens.
April 8 19:00 UTC Student application deadline.
@rjpbonnal
rjpbonnal / gist:905246
Created April 6, 2011 06:49
bioruby-ngs tophat task with sorting and indexing
desc "tophat DIST INDEX OUTPUTDIR FASTQS", "run tophat as from command line, default 6 processors and then create a sorted bam indexed."
method_option :paired, :type => :boolean, :default => false, :desc => 'Are reads paired? If you chose this option pass just the basename of the file without forward/reverse and .fastq'
Bio::Ngs::Tophat.new.thor_task(self, :tophat) do |wrapper, task, dist, index, outputdir, fastqs|
wrapper.params = task.options #merge passed options to the wrapper.
wrapper.params = {"mate-inner-dist"=>dist, "output-dir"=>outputdir, "num-threads"=>6, "solexa1.3-quals"=>true}
fastq_files = task.options[:paired] ? ["#{fastqs}_forward.fastq","#{fastqs}_reverse.fastq"] : ["#{fastqs}"]
wrapper.run :arguments=>[index, fastq_files ].flatten, :separator=>"="
accepted_hits_bam_fn = File.join(outputdir, "accepted_hit.bam")
@rjpbonnal
rjpbonnal / gist:942392
Created April 26, 2011 14:47
binding with ffi bam_merge_core
# @abstract Merge multiple sorted BAM.
# @param is_by_qname whether to sort by query name
# @param out output BAM file name
# @param headers name of SAM file from which to copy '@' header lines,
# or NULL to copy them from the first file to be merged
# @param n number of files to be merged
# @param fn names of files to be merged
#
# @discussion Padding information may NOT correctly maintained. This
# function is NOT thread safe.