sam 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/sam.rb +53 -0
  2. metadata +54 -0
data/lib/sam.rb ADDED
@@ -0,0 +1,53 @@
1
+ class Sam
2
+ public
3
+ attr_accessor :name, :flag, :chrom, :pos, :mapq, :cigar, :mchrom, :mpos, :insert, :seq, :qual, :tags
4
+
5
+ def initialize(line=nil)
6
+ @tags = {}
7
+ parse_line(line) if line != nil
8
+ end
9
+
10
+ def int_or_neg1(x)
11
+ Integer(x) rescue -1
12
+ end
13
+
14
+ def int_or_raw(x)
15
+ Integer(x) rescue x
16
+ end
17
+
18
+ def parse_line(line)
19
+ return false if line[0] == "@"
20
+
21
+ f = line.chomp.split("\t", -1)
22
+ raise "SAM lines must have at least 11 fields (had #{f.size})" if f.size < 11
23
+
24
+ # colnames = %w(1:name 2:flag 3:chr 4:pos 5:mapq 6:cigar 7:mchr 8:mpos 9:insrt 10:seq 11:qual)
25
+
26
+ @name = f[0]
27
+ @flag = f[1]
28
+ @chrom = f[2]
29
+ @pos = int_or_neg1(f[3])
30
+ @mapq = int_or_neg1(f[4])
31
+ @cigar = f[5]
32
+ @mchrom = f[6]
33
+ @mpos = int_or_neg1(f[7])
34
+ @insert = int_or_raw(f[8])
35
+ @seq = f[9]
36
+ @qual = f[10]
37
+
38
+ @tags = {}
39
+ i = 11
40
+ while i < f.size
41
+ tag = f[i]
42
+ i += 1
43
+ colon_index = tag.rindex(':')
44
+ raise line if f.rindex == nil
45
+ key = tag[0, colon_index]
46
+ value = int_or_raw(tag[colon_index + 1, tag.size - colon_index] || "")
47
+ @tags[key] = value
48
+ end
49
+
50
+ return true;
51
+ end
52
+
53
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sam
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jesse Rodriguez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-06 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: Lightweight SAM (Sequence Alignment/Map) file parsing
17
+ email: jesserod@cs.stanford.edu
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/sam.rb
26
+ homepage: http://rubygems.org/gems/sam
27
+ licenses: []
28
+
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.5
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Lightweight SAM file parsing
53
+ test_files: []
54
+