Module: Bix
- Defined in:
- lib/bix.rb,
lib/bix/gtf.rb,
lib/bix/blast.rb,
lib/bix/fasta.rb,
lib/bix/fastq.rb,
lib/bix/plink.rb
Overview
Define it here, will get used elsewhere
Defined Under Namespace
Modules: Blast Classes: Fasta, Fastq, Gtf
Class Method Summary collapse
- .get_all_fastqs(io) ⇒ Object
- .read_fastas(io) ⇒ Object
-
.read_frq(io_or_fn) ⇒ Object
Reads a frq file, producing a list of hashes with the keys :chr, :snp, :a1, :a2, :maf, :nchrobs.
-
.read_tfam(io_or_fn) ⇒ Object
Reads a tfam file, extracting a list of the individual names.
-
.read_tped(io_or_fn, ind_list = nil, as_array = false) ⇒ Object
Reads a tped file.
Class Method Details
.get_all_fastqs(io) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/bix/fastq.rb', line 44 def self.get_all_fastqs(io) fqs = [] while(fq = Fastq.from_io(io)) fqs << fq end return fqs end |
.read_fastas(io) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bix/fasta.rb', line 6 def self.read_fastas(io) fastas = [] fa = nil for line in io line.chomp! if line[0] == '>' fastas << fa if fa != nil fa = Bix::Fasta.new fa.header = line fa.seq = "" else fa.seq << line end end fastas << fa if fa != nil return fastas end |
.read_frq(io_or_fn) ⇒ Object
Reads a frq file, producing a list of hashes with the keys :chr, :snp, :a1, :a2, :maf, :nchrobs
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/bix/plink.rb', line 69 def self.read_frq(io_or_fn) io = io_or_fn.instance_of?(String) ? File.new(io_or_fn) : io io.gets # header res = [] for line in io f = line.chomp.split h = {} h[:chr] = f[0] h[:snp] = f[1] h[:a1] = f[2] h[:a2] = f[3] h[:maf] = f[4].to_f h[:nchrobs] = f[5].to_i res << h end return res end |
.read_tfam(io_or_fn) ⇒ Object
Reads a tfam file, extracting a list of the individual names
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bix/plink.rb', line 5 def self.read_tfam(io_or_fn) io = io_or_fn.instance_of?(String) ? File.new(io_or_fn) : io inds = [] for line in io line.chomp! next if line[0] == '#' f = line.split(/\t| /) inds << f[1] end return inds end |
.read_tped(io_or_fn, ind_list = nil, as_array = false) ⇒ Object
Reads a tped file. Produces a hash of ind_name => [haplotype 1, haplotype 2]. ind_list specifies ind_names, if nil, ind names are just 0,1,2… as_array indicates whether haps will be output as strings or arrays
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bix/plink.rb', line 23 def self.read_tped(io_or_fn, ind_list=nil, as_array=false) io = io_or_fn.instance_of?(String) ? File.new(io_or_fn) : io ind_map = nil for line in io line.chomp! next if line[0] == '#' f = line.split(/ |\t/) if !ind_map ind_map = {} # Initialize ind_map first if ind_list for i in 0...ind_list.size ind_map[ind_list[i]] = i end else ((f.size-4)/2).times do |ind_idx| ind_map[ind_idx] = ind_idx end end # Initialize haps object haps = {} # name => [hap1_vec, hap2_vec] for name, ind_idx in ind_map if as_array haps[name] = [[], []] else haps[name] = ["", ""] end end end for name, ind_idx in ind_map haps[name][0] << f[4 + 2 * ind_idx + 0] haps[name][1] << f[4 + 2 * ind_idx + 1] end end return haps end |