Skip to content

Instantly share code, notes, and snippets.

@misshie
misshie / percentile.rb
Created April 16, 2024 05:56
Calculate percentaile values in an array of float values
#!/usr/bin/env ruby
class Percentile
ROUND_DIGIT = 1
def pctile(data0)
return [] if data0.empty?
data = data0.map{|x|Integer(x.round(ROUND_DIGIT) * (10 ** ROUND_DIGIT))}
sorted_data = data.sort
index_sum = Hash.new(0)
count = Hash.new(0)
##INFO=<ID=BaseQRankSum,Number=1,Type=Float,Description=".">
##INFO=<ID=InbreedingCoeff,Number=1,Type=Float,Description=".">
##INFO=<ID=ReadPosRankSum,Number=1,Type=Float,Description=".">
##INFO=<ID=NEGATIVE_TRAIN_SITE,Number=0,Type=Flag,Description=".">
##INFO=<ID=POSITIVE_TRAIN_SITE,Number=0,Type=Flag,Description=".">
##INFO=<ID=TOMMO_POSSIBLE_PLATFORM_BIAS_SITE,Number=0,Type=Flag,Description=".">
##INFO=<ID=CLNREVSTAT,Number=A,Type=String,Description=".">
##INFO=<ID=CLNSIGCONF,Number=A,Type=String,Description=".">
##INFO=<ID=CLNDISDBINCL,Number=A,Type=String,Description=".">
##INFO=<ID=CLNSIGINCL,Number=A,Type=String,Description=".">
@misshie
misshie / chisq_test.rb
Created October 19, 2023 02:34
2x2 table chi squared test ... use at your own risk ;)
require 'statistics2'
def chisq_test(a, b, c, d)
total = a + b + c + d
row1_total = a + b
row2_total = c + d
col1_total = a + c
col2_total = b + d
e_a = (row1_total * col1_total).to_f / total
e_b = (row1_total * col2_total).to_f / total
@misshie
misshie / tab2xl.rb
Created April 9, 2020 05:23
A Ruby script conveting a tab delimited text file into an Excel XLSX file using the RubyXL library https://github.com/weshatheleopard/rubyXL
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
require 'rubyXL'
require 'rubyXL/convenience_methods/cell'
require 'rubyXL/convenience_methods/color'
require 'rubyXL/convenience_methods/font'
require 'rubyXL/convenience_methods/workbook'
require 'rubyXL/convenience_methods/worksheet'
@misshie
misshie / parse-duplicated-options.rb
Last active March 28, 2017 03:25
Parse duplicated command-line options into a hash of arrays using Ruby
#!/usr/bin/env ruby
# $ ./klass.rb --hoge=fuga --hoge=puyo --foo=bar
# {:h=>false, :hoge=>["fuga", "puyo"] :foo=>["bar"]}
require 'optparse'
class Klass
attr_reader :opts
def initialize(opts)
@misshie
misshie / blink-enclosure.rb
Created October 5, 2016 02:22
Blink all locate LEDs of an SAS-enclosure binded to a block device
@misshie
misshie / PhysPosGrouping.vb
Last active November 9, 2015 02:59
An Excel VBA macro: Alterternate background of each row according to a key column (column C such as "chr1:123-123;A>T")
Sub PhysPosGrouping()
Dim oRange As Range
Dim lRorB As Long
Dim lColR As Long
Dim gcount As Long
Set oRange = ActiveSheet.UsedRange
lRowB = oRange.Row + oRange.Rows.Count - 1
lColR = oRange.Column + oRange.Columns.Count - 1
@misshie
misshie / byobua
Last active November 8, 2015 23:43
An application sample of "peco" to select attaching byobu session
#!/bin/bash
sel=$(byobu ls | peco | cut -d ":" -f 1)
if [ ! -z "${sel}" ] ; then
byobu a -t ${sel}
fi
@misshie
misshie / qstat2.rb
Last active October 28, 2016 01:56
Modified GridEngine's qstat command showing longer job names
#!/usr/bin/env ruby
# License: the MIT lincense.
# Copyright: MISHIMA, Hiroyuki hmishima at nagasaki-u.ac.jp, 2015
require 'rexml/document'
class Qstat2
JOBNAME_WIDTH = 65
def initialize
@misshie
misshie / iupac.rb
Last active August 29, 2015 13:56
The table of IUPAC ambiguous nucleic acid notation
iupac = {
"A" => ["A"], # Adenine
"C" => ["C"], # Cytosine
"G" => ["G"], # Guanine
"T" => ["T"], # Thymine
"R" => ["A", "G"], # puRine
"Y" => ["C", "T"], # pYrimidine
"S" => ["G", "C"], # Strong
"W" => ["A", "T"], # Weak
"K" => ["G", "T"], # Keto