Skip to content

Instantly share code, notes, and snippets.

View shujishigenobu's full-sized avatar

Shuji Shigenobu shujishigenobu

  • NIBB
  • Japan
View GitHub Profile
##
# to_dokuwiki_table.rb
# convert tab-delimited text to dokuwiki table
file = ARGV[0]
File.open(file).each do |l|
a = l.chomp.split(/\t/)
puts "|" + a.map{|x| "#{x} "}.join("|") + "|"
end
#!/usr/bin/env ruby
require 'rubygems'
require 'active_support/core_ext/hash/conversions'
require 'open-uri'
require 'json'
require 'yaml'
require 'pp'
infile = ARGV[0]
@shujishigenobu
shujishigenobu / cosine_correlation.R
Last active August 29, 2015 14:20
Uncentered Pearson correlation coefficient = cosine (Eisen correlation)
cosine.coef <- function(x,y){
a <- sum(na.omit(x * y)) / sqrt(sum(na.omit(x)^2) * sum(na.omit(y)^2))
return(a)
}
cosine.table <- function(x) {
numberOfPoints <- ncol(x)
columnNames <- colnames(x)
distanceTable <- matrix(data = NA, nrow = numberOfPoints, ncol = numberOfPoints,
dimnames = list( columnNames, columnNames ) )
require 'bio'
include Bio
#require 'pp'
#alias :p :pp
ref_proteome_file = ARGV[0]
# || "/home/DB/public/processed/OrthoDB/OrthoDB7/blastdb/DMELA.Drosophila_melanogaster.fas")
blast_res_file = ARGV[1]
# || "BLAST_DMELA/RsGM3.evm.out.combined.pep.vs.DMELA.Drosophila_melanogaster.fas.blastp.fmt7c.txt")
#!/usr/bin/ruby
$pp = true # pretty print
$head = true # display header
$targetdir = ( ARGV[0] || "fastqc")
files = Dir["#{$targetdir}/*_fastqc/fastqc_data.txt"]
@shujishigenobu
shujishigenobu / sn-optparse1.rb
Last active December 25, 2015 08:49
An example snippet to parse option using OptionParser.
### Parse command-line options
require 'optparse'
opt = OptionParser.new
opt.on('-i', '--in FASTA', 'predicted protein files in fasta format [required]') {|v| $pepf = v}
opt.on('-d', '--db BLASTDB', 'blastdb [required]') {|v| $blastdb = v}
opt.on('-m', '--min [MIN_LEN]', 'min aa length to predict [default:50]') {|v| $min_len = v.to_i}
opt.on('-h', '--help', 'show this message'){
puts opt; exit
}
!/bin/ruby
#=== config
MAX_MEMORY = 30000000000
#===
$sam = ARGV[0]
bam_unsorted = File.basename($sam, '.sam') + '.unsorted.bam'
@shujishigenobu
shujishigenobu / taxpath.rb
Created August 16, 2012 04:58
Obtain full path of lineage from root to target species
#===
# taxpath.rb
# Obtain full path of lineage from root to target species
### conf ###
taxtab = "/home/DB/public/processed/NCBI/taxonomy/taxdump/nodes.dmp"
nametab = "/home/DB/public/processed/NCBI/taxonomy/taxdump/names.dmp"
###
infile = ARGV[0]
@shujishigenobu
shujishigenobu / nr_taxinfo.rb
Created August 16, 2012 04:33
Reading tab-delimited tables, retrieve taxonomy information. It works only with NCBI nr database.
#===
# nr_taxinfo.rb
#
# Reading tab-delimited tables, retrieve taxonomy information.
# It works only with NCBI nr database.
# Three columns, tax_id, scientific_name and common_name, are added.
$infile = ARGV[0]
$blastdb = ARGV[1]
$keypos = (ARGV[2] || 1).to_i
@shujishigenobu
shujishigenobu / blast_tab_add_target_annot.rb
Created August 9, 2012 12:56
Reading BLAST result table (fmt6,7) and add description of target seq referring blastdb
$infile = ARGV[0]
$blastdb = ARGV[1]
$keypos = (ARGV[2] || 1).to_i
=begin
counter = Hash.new(0)
File.open($infile).each do |l|
next if /^\#/.match(l)
a = l.chomp.split(/\t/)
tophit = a[2]