bio-samtools 2.5.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 536e4a02119f2315755d2768e868ca21b29213ac
4
- data.tar.gz: 6b4c39ca800763b7f654d4d04994338ea9b809a1
3
+ metadata.gz: 72a3a3a4e3c01d54205edb87755569d0a3299e7b
4
+ data.tar.gz: 92ba63563ff1d9f0e3b5009ee6f1eea0ce0b3064
5
5
  SHA512:
6
- metadata.gz: 94d1754483e138a78321e5d73a94406aaa51186a01f9bf70239b2f4089cef3378ac06d075180631e815eec52336e0bbc834bb4724ed454845bd63d93ac591f70
7
- data.tar.gz: 1cce66d5dbab92a6fc1ccd167b5df3827d8f44efac002fd970c789335abf6dace5ea32aab75e82a6a977b47241da967531660131059ddc8224cdaaff0bb8f3f2
6
+ metadata.gz: cbe47a74c33a88e075528be9f295d2e389df16209ca7c5a1ffce47481db4e14dbe799672e7204f578041d35bcb3cacc48b890e86cb506b68b0a2e39d47181c62
7
+ data.tar.gz: 355d19cc987094262d5b925c4fce99d3334ca9de58bd6b550a2507a10903e3206f0500417413adbd0377dd69a5696a3fb4c27bb4970d8a3642a2978cab905413
@@ -12,9 +12,7 @@ before_script:
12
12
  - rake -f Rakefile
13
13
  - cd ../
14
14
  rvm:
15
- - 2.0.0
16
15
  - 2.1.10
17
- - 2.2.2
18
- - 2.2.3
19
16
  - 2.2.5
20
- - 2.3.1
17
+ - 2.3.5
18
+ - 2.4.2
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  gem "bio-svgenes", ">= 0.4.1"
5
5
  gem "bio", ">= 1.4.2"
6
+ #gem "rake"
6
7
  #gem 'open_uri_redirections'
7
8
 
8
9
  # Add dependencies to develop your gem here.
@@ -13,9 +14,7 @@ group :development do
13
14
  if RUBY_VERSION.start_with?("2.1") or RUBY_VERSION.start_with?("2.2") or RUBY_VERSION.start_with?("2.0")
14
15
  gem "jeweler", "= 2.0.1"
15
16
  else
16
- gem "juwelier" , :platforms => :ruby_23 #jeweler support is being dropped
17
+ gem "juwelier" #, :platforms => :ruby_23 #jeweler support is being dropped
17
18
  end
18
- gem "rack", "1.6.4", :platforms => :ruby_21
19
-
20
-
19
+ gem "rack", "1.6.4", :platforms => :ruby_21
21
20
  end
data/README.md CHANGED
@@ -465,7 +465,7 @@ Each test file tests different aspects of the code.
465
465
  1. Filter to the fetching algorithm (give a condition that has to be satisfied to add the alignment to the list)
466
466
 
467
467
  ### To whom do I complain?
468
- Try [Ricardo.Ramirez-Gonzalez@tgac.ac.uk](Ricardo.Ramirez-Gonzalez@tgac.ac.uk)
468
+ Try [Ricardo.Ramirez-Gonzalez@jic.ac.uk](Ricardo.Ramirez-Gonzalez@jic.ac.uk)
469
469
  and [dan.maclean@tsl.ac.uk](dan.maclean@tsl.ac.uk)
470
470
 
471
471
  ### Important Notes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.6.0
@@ -2,21 +2,21 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bio-samtools 2.5.1 ruby lib
5
+ # stub: bio-samtools 2.6.0 ruby lib
6
6
  # stub: ext/mkrf_conf.rb
7
7
 
8
8
  Gem::Specification.new do |s|
9
- s.name = "bio-samtools"
10
- s.version = "2.5.1"
9
+ s.name = "bio-samtools".freeze
10
+ s.version = "2.6.0"
11
11
 
12
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
- s.require_paths = ["lib"]
14
- s.authors = ["Ricardo Ramirez-Gonzalez", "Dan MacLean", "Raoul J.P. Bonnal"]
15
- s.date = "2016-11-04"
16
- s.description = "Binder of samtools for ruby, on the top of FFI. \n\n This project was born from the need to add support of BAM files to \n the gee_fu genome browser (http://github.com/danmaclean/gee_fu)."
17
- s.email = "Ricardo.Ramirez-Gonzalez@tgac.ac.uk"
18
- s.executables = ["bam_consensus.rb"]
19
- s.extensions = ["ext/mkrf_conf.rb"]
12
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
13
+ s.require_paths = ["lib".freeze]
14
+ s.authors = ["Ricardo Ramirez-Gonzalez".freeze, "Dan MacLean".freeze, "Raoul J.P. Bonnal".freeze]
15
+ s.date = "2017-11-30"
16
+ s.description = "Binder of samtools for ruby, on the top of FFI. \n\n This project was born from the need to add support of BAM files to \n the gee_fu genome browser (http://github.com/danmaclean/gee_fu).".freeze
17
+ s.email = "Ricardo.Ramirez-Gonzalez@tgac.ac.uk".freeze
18
+ s.executables = ["bam_consensus.rb".freeze]
19
+ s.extensions = ["ext/mkrf_conf.rb".freeze]
20
20
  s.extra_rdoc_files = [
21
21
  "LICENSE.txt",
22
22
  "README.md"
@@ -85,7 +85,6 @@ Gem::Specification.new do |s|
85
85
  "doc/table_of_contents.html",
86
86
  "ext/Makefile-bioruby.patch",
87
87
  "ext/Makefile-suse.patch",
88
- "ext/Rakefile",
89
88
  "ext/mkrf_conf.rb",
90
89
  "lib/bio-samtools.rb",
91
90
  "lib/bio/BIOExtensions.rb",
@@ -147,36 +146,36 @@ Gem::Specification.new do |s|
147
146
  "tutorial/tutorial.md",
148
147
  "tutorial/tutorial.pdf"
149
148
  ]
150
- s.homepage = "http://github.com/helios/bioruby-samtools"
151
- s.licenses = ["MIT"]
152
- s.rubygems_version = "2.5.1"
153
- s.summary = "Binder of samtools for ruby, on the top of FFI."
149
+ s.homepage = "http://github.com/helios/bioruby-samtools".freeze
150
+ s.licenses = ["MIT".freeze]
151
+ s.rubygems_version = "2.6.10".freeze
152
+ s.summary = "Binder of samtools for ruby, on the top of FFI.".freeze
154
153
 
155
154
  if s.respond_to? :specification_version then
156
155
  s.specification_version = 4
157
156
 
158
157
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
159
- s.add_runtime_dependency(%q<bio-svgenes>, [">= 0.4.1"])
160
- s.add_runtime_dependency(%q<bio>, [">= 1.4.2"])
161
- s.add_development_dependency(%q<shoulda>, ["= 2.10"])
162
- s.add_development_dependency(%q<test-unit>, [">= 0"])
163
- s.add_development_dependency(%q<juwelier>, [">= 0"])
164
- s.add_development_dependency(%q<rack>, ["= 1.6.4"])
158
+ s.add_runtime_dependency(%q<bio-svgenes>.freeze, [">= 0.4.1"])
159
+ s.add_runtime_dependency(%q<bio>.freeze, [">= 1.4.2"])
160
+ s.add_development_dependency(%q<shoulda>.freeze, ["= 2.10"])
161
+ s.add_development_dependency(%q<test-unit>.freeze, [">= 0"])
162
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
163
+ s.add_development_dependency(%q<rack>.freeze, ["= 1.6.4"])
165
164
  else
166
- s.add_dependency(%q<bio-svgenes>, [">= 0.4.1"])
167
- s.add_dependency(%q<bio>, [">= 1.4.2"])
168
- s.add_dependency(%q<shoulda>, ["= 2.10"])
169
- s.add_dependency(%q<test-unit>, [">= 0"])
170
- s.add_dependency(%q<juwelier>, [">= 0"])
171
- s.add_dependency(%q<rack>, ["= 1.6.4"])
165
+ s.add_dependency(%q<bio-svgenes>.freeze, [">= 0.4.1"])
166
+ s.add_dependency(%q<bio>.freeze, [">= 1.4.2"])
167
+ s.add_dependency(%q<shoulda>.freeze, ["= 2.10"])
168
+ s.add_dependency(%q<test-unit>.freeze, [">= 0"])
169
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
170
+ s.add_dependency(%q<rack>.freeze, ["= 1.6.4"])
172
171
  end
173
172
  else
174
- s.add_dependency(%q<bio-svgenes>, [">= 0.4.1"])
175
- s.add_dependency(%q<bio>, [">= 1.4.2"])
176
- s.add_dependency(%q<shoulda>, ["= 2.10"])
177
- s.add_dependency(%q<test-unit>, [">= 0"])
178
- s.add_dependency(%q<juwelier>, [">= 0"])
179
- s.add_dependency(%q<rack>, ["= 1.6.4"])
173
+ s.add_dependency(%q<bio-svgenes>.freeze, [">= 0.4.1"])
174
+ s.add_dependency(%q<bio>.freeze, [">= 1.4.2"])
175
+ s.add_dependency(%q<shoulda>.freeze, ["= 2.10"])
176
+ s.add_dependency(%q<test-unit>.freeze, [">= 0"])
177
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
178
+ s.add_dependency(%q<rack>.freeze, ["= 1.6.4"])
180
179
  end
181
180
  end
182
181
 
@@ -8,68 +8,110 @@ path = File.expand_path(File.dirname(__FILE__))
8
8
 
9
9
  path_external = File.join(path, "../lib/bio/db/sam/external")
10
10
 
11
- version = File.open(File.join(path_external,"VERSION"),'r')
12
- Version = version.read
13
- version.close
14
-
15
- #url = "http://sourceforge.net/projects/samtools/files/samtools/#{Version}/samtools-#{Version}.tar.bz2/download"
16
- url="https://github.com/samtools/samtools/releases/download/#{Version}/samtools-#{Version}.tar.bz2"
17
- SamToolsFile = "samtools-#{Version}.tar.bz2"
18
- url_bcftools="https://github.com/samtools/bcftools/releases/download/#{Version}/bcftools-#{Version}.tar.bz2"
19
- BcfToolsFile = "bcftools-#{Version}.tar.bz2"
20
-
21
- File.open(File.join(path,"Rakefile"),"w") do |rakefile|
22
- rakefile.write <<-RAKE
23
11
  require 'rbconfig'
24
- require 'open-uri'
25
- #require 'open_uri_redirections'
26
- require 'fileutils'
27
- include FileUtils::Verbose
28
- require 'rake/clean'
29
-
30
- URL = "#{url}"
31
- URL_bcf = "#{url_bcftools}"
32
- task :download do
33
- open(URL) do |uri|
34
- File.open("#{SamToolsFile}",'wb') do |fout|
35
- fout.write(uri.read)
36
- end #fout
37
- end #uri
38
-
39
- open(URL_bcf) do |uri|
40
- File.open("#{BcfToolsFile}",'wb') do |fout|
41
- fout.write(uri.read)
42
- end #fout
43
- end #uri
44
-
45
- end
46
-
47
- task :compile do
48
- sh "tar xvfj #{SamToolsFile}"
49
- cd("samtools-#{Version}") do
50
- sh "make"
51
- cp('samtools', "#{path_external}")
52
- end #cd
53
-
54
- sh "tar xvfj #{BcfToolsFile}"
55
- cd("bcftools-#{Version}") do
56
- sh "make"
57
- cp('bcftools', "#{path_external}")
58
- end #cd
59
- end
60
-
61
- task :clean do
62
- cd("samtools-#{Version}") do
63
- sh "make clean"
12
+
13
+ if is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
14
+ SamToolsFile = "samtools.zip"
15
+
16
+ File.open(File.join(path,"Rakefile"),"w") do |rakefile|
17
+ rakefile.write <<-RAKE
18
+ require 'rbconfig'
19
+ require 'open-uri'
20
+ require 'fileutils'
21
+ include FileUtils::Verbose
22
+ require 'rake/clean'
23
+
24
+ url = "http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=bow&DownloadId=379402&FileTime=129956483945970000&Build=21040"
25
+
26
+ task :download do
27
+ open(url) do |uri|
28
+ File.open("#{SamToolsFile}",'wb') do |fout|
29
+ fout.write(uri.read)
30
+ end #fout
31
+ end #uri
32
+ end
33
+
34
+ task :save do
35
+ sh "unzip #{SamToolsFile} -d samtools-windows"
36
+ cd("samtools-windows") do
37
+ cp('samtools.exe', "#{path_external}")
38
+ end #cd
39
+ end
40
+
41
+ task :clean do
42
+ rm_rf("samtools-windows")
43
+ rm_rf("#{SamToolsFile}")
44
+ end
45
+
46
+ task :default => [:download, :save, :clean]
47
+
48
+ RAKE
49
+
50
+ end
51
+ else
52
+ version = File.open(File.join(path_external,"VERSION"),'r')
53
+ Version = version.read
54
+ version.close
55
+
56
+ #url = "http://sourceforge.net/projects/samtools/files/samtools/#{Version}/samtools-#{Version}.tar.bz2/download"
57
+ url="https://github.com/samtools/samtools/releases/download/#{Version}/samtools-#{Version}.tar.bz2"
58
+ SamToolsFile = "samtools-#{Version}.tar.bz2"
59
+ url_bcftools="https://github.com/samtools/bcftools/releases/download/#{Version}/bcftools-#{Version}.tar.bz2"
60
+ BcfToolsFile = "bcftools-#{Version}.tar.bz2"
61
+
62
+ File.open(File.join(path,"Rakefile"),"w") do |rakefile|
63
+ rakefile.write <<-RAKE
64
+ require 'rbconfig'
65
+ require 'open-uri'
66
+ #require 'open_uri_redirections'
67
+ require 'fileutils'
68
+ include FileUtils::Verbose
69
+ require 'rake/clean'
70
+
71
+ URL = "#{url}"
72
+ URL_bcf = "#{url_bcftools}"
73
+ task :download do
74
+ open(URL) do |uri|
75
+ File.open("#{SamToolsFile}",'wb') do |fout|
76
+ fout.write(uri.read)
77
+ end #fout
78
+ end #uri
79
+
80
+ open(URL_bcf) do |uri|
81
+ File.open("#{BcfToolsFile}",'wb') do |fout|
82
+ fout.write(uri.read)
83
+ end #fout
84
+ end #uri
85
+
86
+ end
87
+
88
+ task :compile do
89
+ sh "tar xvfj #{SamToolsFile}"
90
+ cd("samtools-#{Version}") do
91
+ sh "make"
92
+ cp('samtools', "#{path_external}")
93
+ end #cd
94
+
95
+ sh "tar xvfj #{BcfToolsFile}"
96
+ cd("bcftools-#{Version}") do
97
+ sh "make"
98
+ cp('bcftools', "#{path_external}")
99
+ end #cd
100
+ end
101
+
102
+ task :clean do
103
+ cd("samtools-#{Version}") do
104
+ sh "make clean"
105
+ end
106
+ rm("#{SamToolsFile}")
107
+ rm_rf("samtools-#{Version}")
108
+ rm("#{BcfToolsFile}")
109
+ rm_rf("bcftools-#{Version}")
64
110
  end
65
- rm("#{SamToolsFile}")
66
- rm_rf("samtools-#{Version}")
67
- rm("#{BcfToolsFile}")
68
- rm_rf("bcftools-#{Version}")
69
- end
70
111
 
71
- task :default => [:download, :compile, :clean]
112
+ task :default => [:download, :compile, :clean]
72
113
 
73
- RAKE
114
+ RAKE
74
115
 
75
- end
116
+ end
117
+ end
@@ -1,9 +1,9 @@
1
1
  module Bio
2
2
  class DB
3
3
  class Sam
4
-
4
+
5
5
  class SamException < StandardError; end
6
-
6
+
7
7
  attr_accessor :bam, :fasta, :samtools, :bcftools, :last_command
8
8
  attr_accessor :minumum_ratio_for_iup_consensus
9
9
  attr_reader :cached_regions
@@ -37,7 +37,7 @@ module Bio
37
37
  files_ok?
38
38
  end
39
39
 
40
- #runs the samtools view command
40
+ #runs the samtools view command
41
41
  #* b - output BAM
42
42
  #* h - print header for the SAM output
43
43
  #* H - print header only (no alignments)
@@ -67,7 +67,7 @@ module Bio
67
67
  region = String.new
68
68
  if opts[:chr] and opts[:start] and opts[:stop]
69
69
  has_e = self.has_entry? opts[:chr]
70
- raise SamException.new(), "[view] The sequence #{opts[:chr]} is not in the bam file" unless self.has_entry? opts[:chr]
70
+ raise SamException.new(), "[view] The sequence #{opts[:chr]} is not in the bam file" unless self.has_entry? opts[:chr]
71
71
  region = "#{opts[:chr]}:#{opts[:start]}-#{opts[:stop]}"
72
72
  [:chr, :start, :stop].each {|o| opts.delete(o)}
73
73
  end
@@ -81,8 +81,8 @@ module Bio
81
81
  opts.delete(:one)
82
82
  end
83
83
  command = String.new
84
- command = form_opt_string(@samtools, 'view', opts, [:b, :h, :H, :S, :u, '1', :x, :X, :c, :B])
85
- command = command + " '#{region}'" if region.size > 0
84
+ command = form_opt_string(@samtools, 'view', opts, [:b, :h, :H, :S, :u, '1', :x, :X, :c, :B])
85
+ command = command + " \"#{region}\"" if region.size > 0
86
86
  @last_command = command
87
87
  type = (opts[:u] or opts[:b]) ? :binary : :text
88
88
  klass = (type == :binary) ? String : Bio::DB::Alignment
@@ -95,12 +95,12 @@ module Bio
95
95
  #* stop - the stop position for the subsequence
96
96
  #* &block - the the block of code to execute
97
97
  def fetch(chr, start,stop, &block)
98
-
98
+
99
99
  view(
100
100
  :chr => chr,
101
101
  :start => start,
102
- :stop => stop,
103
- &block
102
+ :stop => stop,
103
+ &block
104
104
  )
105
105
  end
106
106
 
@@ -108,7 +108,7 @@ module Bio
108
108
 
109
109
  #returns an array of coverage for each location for which there are mapped reads
110
110
  #* chr - the reference name
111
- #* start - the start position
111
+ #* start - the start position
112
112
  #* length - the length of the region queried
113
113
  def chromosome_coverage(chr,start,length)
114
114
  result = []
@@ -122,7 +122,7 @@ module Bio
122
122
 
123
123
  #returns an svg file or object, plotting coverage for each location for which there are mapped reads
124
124
  #* chr - the reference name
125
- #* start - the start position
125
+ #* start - the start position
126
126
  #* length - the length of the region queried
127
127
  #OPTIONS
128
128
  #* bin - the amount of bins to split the histogram into. The arithmetic mean score for each bin will be plotted. [default 30 bins]
@@ -141,25 +141,25 @@ module Bio
141
141
  self.mpileup(:r => region) do |p|
142
142
  result << p.coverage
143
143
  end
144
- p = Bio::Graphics::Page.new(:width => 1000,
145
- :height => 200,
144
+ p = Bio::Graphics::Page.new(:width => 1000,
145
+ :height => 200,
146
146
  :number_of_intervals => 10,
147
147
  :font_size => 14
148
148
  )
149
- default_options = {:glyph => :histogram,
149
+ default_options = {:glyph => :histogram,
150
150
  :stroke => 'black',
151
151
  :fill_color => 'gold',
152
152
  :track_height => 150,
153
- :name => 'read coverage',
154
- :label => true,
155
- :stroke_width => '1',
153
+ :name => 'read coverage',
154
+ :label => true,
155
+ :stroke_width => '1',
156
156
  :x_round => 1,
157
157
  :y_round => 1 }
158
158
  opts = default_options.merge(opts)
159
-
159
+
160
160
  data_track = p.add_track(opts)
161
- index = 0;
162
- result.each_slice(bin) {|slice|
161
+ index = 0;
162
+ result.each_slice(bin) {|slice|
163
163
  #result.each_with_index {|val, index|
164
164
  data_feature = Bio::Graphics::MiniFeature.new(:start => start + index,
165
165
  :end => (start + index + bin),
@@ -179,7 +179,7 @@ module Bio
179
179
 
180
180
  #returns the average coverage over the region queried
181
181
  #* chr - the reference name
182
- #* start - the start position
182
+ #* start - the start position
183
183
  #* length - the length of the region queried
184
184
  def average_coverage(chr,start,length)
185
185
  arr = self.chromosome_coverage(chr,start,length)
@@ -187,19 +187,19 @@ module Bio
187
187
  end
188
188
 
189
189
  #returns a Bio::DB::Pileup or Bio::DB::VCF object
190
- #* region - Only generate pileup in region [chrom:start-stop]
190
+ #* region - Only generate pileup in region [chrom:start-stop]
191
191
  #* illumina_quals - Assume the quality is in the Illumina 1.3+ encoding
192
192
  #* count_anomalous - Do not skip anomalous read pairs in variant calling
193
193
  #* no_baq - Disable probabilistic realignment for the computation of base alignment quality (BAQ). BAQ is the Phred-scaled probability of a read base being misaligned. Applying this option greatly helps to reduce false SNPs caused by misalignments.
194
- #* adjust_mapq - [INT] Coefficient for downgrading mapping quality for reads containing excessive mismatches. Given a read with a phred-scaled probability q of being generated from the mapped position, the new mapping quality is about sqrt((INT-q)/INT)*INT. A zero value disables this functionality; if enabled, the recommended value for BWA is 50. [0]
195
- #* max_per_bam_depth - [INT] At a position, read maximally INT reads per input BAM. [250]
194
+ #* adjust_mapq - [INT] Coefficient for downgrading mapping quality for reads containing excessive mismatches. Given a read with a phred-scaled probability q of being generated from the mapped position, the new mapping quality is about sqrt((INT-q)/INT)*INT. A zero value disables this functionality; if enabled, the recommended value for BWA is 50. [0]
195
+ #* max_per_bam_depth - [INT] At a position, read maximally INT reads per input BAM. [250]
196
196
  #* extended_baq - Extended BAQ computation. This option helps sensitivity especially for MNPs, but may hurt specificity a little bit.
197
197
  #* exclude_reads_file - [FILE] exclude read groups listed in FILE [null]
198
198
  #* list_of_positions - [FILE] BED or position list file containing a list of regions or sites where pileup or BCF should be generated [null]
199
199
  #* mapping_quality_cap - [INT] cap mapping quality at INT [60]
200
200
  #* ignore_rg - ignore read group tags
201
201
  #* min_mapping_quality - [INT] skip alignments with mapQ smaller than INT [0]
202
- #* min_base_quality - [INT] skip bases with baseQ/BAQ smaller than INT [13]
202
+ #* min_base_quality - [INT] skip bases with baseQ/BAQ smaller than INT [13]
203
203
  #* ##following options are for the -g -u option
204
204
  #* genotype_calling - generate BCF output (genotype likelihoods)
205
205
  #* uncompressed_bcf - generate uncompress BCF output
@@ -233,19 +233,19 @@ module Bio
233
233
  :no_indels => :I,
234
234
  :skip_indel_over_average_depth => :L,
235
235
  :gap_open_sequencing_error_probability => :o,
236
- :platforms => :P
236
+ :platforms => :P
237
237
  }
238
238
 
239
- ##convert any long_opts to short opts
239
+ ##convert any long_opts to short opts
240
240
  temp_opts = opts.dup
241
241
  opts.each_pair do |k,v|
242
242
  if long_opts[k]
243
- temp_opts[long_opts[k]] = v
243
+ temp_opts[long_opts[k]] = v
244
244
  temp_opts.delete(k)
245
245
  end
246
246
  end
247
247
  opts = Hash.new
248
- #To remove any unwanted options.
248
+ #To remove any unwanted options.
249
249
  long_opts.each_pair do |k,v|
250
250
  opts[v] = temp_opts[v] if temp_opts.has_key?(v)
251
251
  end
@@ -260,10 +260,10 @@ module Bio
260
260
  query = opts[:r].to_s
261
261
  query = opts[:r].to_region.to_s if opts[:r].respond_to?(:to_region)
262
262
  if not query.nil? and query.size > 0
263
- raise SamException.new(), "The sequence #{query} is not in the bam file" unless has_region? query
263
+ raise SamException.new(), "The sequence #{query} is not in the bam file" unless has_region? query
264
264
  end
265
265
  opts[:r] = query
266
-
266
+
267
267
  if opts[:six]
268
268
  opts["6"] = nil
269
269
  opts.delete(:six)
@@ -274,7 +274,7 @@ module Bio
274
274
  if opts[:u]
275
275
  command = command + " | #{@bcftools} view -cg -"
276
276
  end
277
-
277
+
278
278
  klass = opts[:u] ? Bio::DB::Vcf : Bio::DB::Pileup
279
279
  @last_command = command
280
280
  yield_from_pipe(command, klass, :text, &block)
@@ -289,8 +289,8 @@ module Bio
289
289
  def fetch_reference(chr,start,stop, opts={:as_bio => false})
290
290
  raise SamException.new(), "The sequence #{chr} is not in the bam file" unless has_entry? chr
291
291
  seq = ""
292
- unless @fasta #We return a string of Ns if we don't know the reference.
293
- seq = "n" * (stop-start)
292
+ unless @fasta #We return a string of Ns if we don't know the reference.
293
+ seq = "n" * (stop-start)
294
294
  else
295
295
  command = "#{@samtools} faidx \"#{@fasta}\" '#{chr}:#{start}-#{stop}'"
296
296
  puts "Running: #{command}" if $VERBOSE
@@ -362,7 +362,7 @@ module Bio
362
362
  #Retrieve and print stats in the index file. The output is TAB delimited with each line consisting of reference sequence name, sequence length, number of mapped reads and number unmapped reads.
363
363
  def index_stats
364
364
  return @stats if @stats
365
- stats = {}
365
+ stats = {}
366
366
  command = form_opt_string(@samtools, "idxstats", {}, [])
367
367
  @last_command = command
368
368
  puts "Running: #{command}" if $VERBOSE
@@ -375,12 +375,12 @@ module Bio
375
375
  end
376
376
 
377
377
  alias_method :idxstats, :index_stats
378
-
378
+
379
379
  #Retrive a hash with all the regions, with the region id as index or runs the function on each region
380
380
  def each_region
381
- index_stats
382
- if @regions
383
- return @regions unless block_given?
381
+ index_stats
382
+ if @regions
383
+ return @regions unless block_given?
384
384
  else
385
385
  @regions = Hash.new
386
386
  end
@@ -395,18 +395,18 @@ module Bio
395
395
  end
396
396
  @regions
397
397
  end
398
-
398
+
399
399
  #Tells if the bam file contains the entry. It has to be indexed.
400
400
  def has_entry?(entry)
401
401
  index_stats.has_key?(entry)
402
402
  # puts "#{entry} #{@stats.inspect}"
403
403
  # index_stats
404
404
  end
405
-
405
+
406
406
  def has_region?(region)
407
407
  index_stats
408
408
  reg=Bio::DB::Fasta::Region::parse_region(region)
409
- return 0 unless has_entry? (reg.entry)
409
+ return 0 unless has_entry? (reg.entry)
410
410
  len = @stats[reg.entry][:length]
411
411
  reg.start > 0 and reg.end <= len
412
412
  end
@@ -504,10 +504,10 @@ module Bio
504
504
  else
505
505
  opts[:o] = opts[:prefix] += ".bam"
506
506
  end
507
-
507
+
508
508
  opts.delete(:prefix)
509
509
  command = form_opt_string(@samtools, "sort", opts, [:n, :f])
510
- command = command + " "
510
+ command = command + " "
511
511
  @last_command = command
512
512
  puts "Running: #{command}" if $VERBOSE
513
513
  #if opts[:o]
@@ -518,7 +518,7 @@ module Bio
518
518
  end
519
519
 
520
520
  #used to generate a text alignment viewer
521
- #* d - display, output as (H)tml or (C)urses or (T)ext
521
+ #* d - display, output as (H)tml or (C)urses or (T)ext
522
522
  #* p - [chr:pos] go directly to this position
523
523
  #* s - [STR] display only reads from this sample or group
524
524
  def tview(opts={})
@@ -563,18 +563,18 @@ module Bio
563
563
  #* S - The input is SAM with header lines
564
564
  #* C - [INT] Coefficient to cap mapping quality of poorly mapped reads. See the pileup command for details. [0]
565
565
  #* r - Compute the BQ tag (without -A) or cap base quality by BAQ (with -A).
566
- #* E - Extended BAQ calculation. This option trades specificity for sensitivity, though the effect is minor.
566
+ #* E - Extended BAQ calculation. This option trades specificity for sensitivity, though the effect is minor.
567
567
  def calmd(opts={}, &block)
568
568
  command = form_opt_string(@samtools, "calmd", opts, [:E, :e, :u, :b, :S, :r] )+ " " + @fasta
569
569
  puts "Running: #{command}" if $VERBOSE
570
570
  @last_command = command
571
- type = :text
571
+ type = :text
572
572
  klass = Bio::DB::Alignment
573
573
  yield_from_pipe(command, klass, type, true, "@",&block)
574
574
  end
575
575
 
576
- #Identifies target regions by examining the continuity of read depth, computes haploid consensus sequences of targets and outputs a SAM with each sequence corresponding to a target. When option -f is in use, BAQ will be applied.
577
- #* Q - [INT] Minimum base quality for a base to be considered [13]
576
+ #Identifies target regions by examining the continuity of read depth, computes haploid consensus sequences of targets and outputs a SAM with each sequence corresponding to a target. When option -f is in use, BAQ will be applied.
577
+ #* Q - [INT] Minimum base quality for a base to be considered [13]
578
578
  #* i - in penalty
579
579
  #* 0 - em0
580
580
  #* 1 - em1
@@ -598,7 +598,7 @@ module Bio
598
598
  #* F - Do not attempt to fix chimeric reads.
599
599
  #* k - [INT] Maximum length for local phasing. [13]
600
600
  #* q - [INT] Minimum Phred-scaled LOD to call a heterozygote. [40]
601
- #* Q - [INT] Minimum base quality to be used in het calling. [13]
601
+ #* Q - [INT] Minimum base quality to be used in het calling. [13]
602
602
  def phase(opts={})
603
603
  command = "#{form_opt_string(@samtools, "phase", opts, [:A, :F] )}"
604
604
  puts "Running: #{command}" if $VERBOSE
@@ -619,18 +619,18 @@ module Bio
619
619
  system(command)
620
620
  end
621
621
 
622
- #Returns the pipelup of a region, encapsulated as a Bio::DB::Fasta::Region object.
622
+ #Returns the pipelup of a region, encapsulated as a Bio::DB::Fasta::Region object.
623
623
  #The opts are the same as for mpileup
624
- def fetch_region(opts={})
624
+ def fetch_region(opts={})
625
625
  region = opts[:r] ? opts[:r] : opts[:region]
626
626
  opts[:r] = region
627
627
  opts[:region] = region
628
628
  reg = Bio::DB::Fasta::Region.parse_region(region.to_s)
629
629
  reg.reference = self.fetch_reference(region.entry, region.start, region.end).downcase
630
630
  tmp = Array.new
631
- mpileup(opts) do | pile |
631
+ mpileup(opts) do | pile |
632
632
  # puts pile
633
- tmp << pile
633
+ tmp << pile
634
634
  yield pile if block_given?
635
635
  end
636
636
  reg.pileup = tmp
@@ -641,19 +641,19 @@ module Bio
641
641
  #Same as mpilup, but it caches the pileup, so if you want several operations on the same set of regions
642
642
  #the pile for different operations, it won't execute the mpilup command several times
643
643
  #Whenever you finish using a region, call mpileup_clear_cache to free the cache
644
- #The argument Region is required, as it will be the key for the underlying hash.
645
- #We asume that the options (other than the region) are constant. If they are not, the cache mechanism may not be consistent.
644
+ #The argument Region is required, as it will be the key for the underlying hash.
645
+ #We asume that the options (other than the region) are constant. If they are not, the cache mechanism may not be consistent.
646
646
  #
647
647
  #TODO: It may be good to load partially the pileup
648
- def mpileup_cached (opts={})
648
+ def mpileup_cached (opts={})
649
649
  raise SamException.new(), "A region must be provided" unless opts[:r] or opts[:region]
650
650
  @cached_regions = Hash.new unless @cached_regions
651
651
  region = opts[:r] ? opts[:r] : opts[:region]
652
652
  @cached_regions[region.to_s] = fetch_region(opts) unless @cached_regions[region.to_s]
653
653
  if block_given?
654
654
  @cached_regions[region.to_s].pileup.each do | pile |
655
- yield pile
656
- end
655
+ yield pile
656
+ end
657
657
  end
658
658
  region.pileup
659
659
  end
@@ -695,7 +695,7 @@ module Bio
695
695
  opts[:region] = Bio::DB::Fasta::Region.parse_region( opts[:region] .to_s) unless opts[:region].class == Bio::DB::Fasta::Region
696
696
  fastq_filename = opts[:fastq]
697
697
 
698
- out = $stdout
698
+ out = $stdout
699
699
  print_fastq = Proc.new do |alignment|
700
700
  out.puts "@#{alignment.qname}"
701
701
  out.puts "#{alignment.seq}"
@@ -709,25 +709,25 @@ module Bio
709
709
  fetch_with_function(chromosome, qstart, qstart+len, print_fastq)
710
710
  out.close if fastq_filename
711
711
  end
712
-
712
+
713
713
  # checks existence of files in instance
714
714
  def files_ok?
715
715
  [@fasta, @sam, @bam].flatten.compact.each {|f| return false unless File.exists? f }
716
716
  true
717
717
  end
718
-
719
- #Returns true if the .bai exists. It doesn't validate if it is valid.
718
+
719
+ #Returns true if the .bai exists. It doesn't validate if it is valid.
720
720
  def indexed?
721
721
  File.exists? @bam and File.exists? "#{@bam}.bai"
722
722
  end
723
-
723
+
724
724
  private
725
725
  #Returns Process::Status with the execution status. If run in a $VERBOSE environment, stderr of the process
726
726
  #is forwarded to the default stdout
727
727
  def yield_from_pipe(command, klass, type=:text, skip_comments=true, comment_char="#", &block)
728
728
  puts "[yield_from_pipe] #{command}" if $VERBOSE
729
729
  stdin, pipe, stderr, wait_thr = Open3.popen3(command)
730
- pid = wait_thr[:pid] # pid of the started process.
730
+ pid = wait_thr[:pid] # pid of the started process.
731
731
  if type == :text
732
732
  while (line = pipe.gets)
733
733
  next if skip_comments and line[0] == comment_char
@@ -739,7 +739,7 @@ module Bio
739
739
  end
740
740
  end
741
741
  exit_status = wait_thr.value # Process::Status object returned.
742
- puts "Running: #{command}" if $VERBOSE
742
+ puts "Running: #{command}" if $VERBOSE
743
743
  stdin.close
744
744
  pipe.close
745
745
  stderr.close
@@ -750,7 +750,7 @@ module Bio
750
750
  # returns a command string from a program
751
751
  # @param program [Symbol] either `:samtools` or `:bcftools`
752
752
  # @param opts [Hash] the options hash
753
- # @param singles `flag` options [Array] the options in `opts` that are single options
753
+ # @param singles `flag` options [Array] the options in `opts` that are single options
754
754
  def form_opt_string(prog, command, opts, singles=[])
755
755
  opts_string = commandify(opts, singles)
756
756
  "#{prog} #{command} #{opts_string} \"#{@bam}\""
@@ -763,7 +763,7 @@ module Bio
763
763
  value = "\"#{value}\""
764
764
  value = "" if singles.include?(tag)
765
765
 
766
- list << "-#{tag.to_s} #{value}"
766
+ list << "-#{tag.to_s} #{value}"
767
767
  end
768
768
  list.join(" ")
769
769
  end
@@ -1 +1 @@
1
- 1.3.1
1
+ 1.6
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-samtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Ramirez-Gonzalez
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-04 00:00:00.000000000 Z
13
+ date: 2017-11-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bio-svgenes
@@ -171,7 +171,6 @@ files:
171
171
  - doc/table_of_contents.html
172
172
  - ext/Makefile-bioruby.patch
173
173
  - ext/Makefile-suse.patch
174
- - ext/Rakefile
175
174
  - ext/mkrf_conf.rb
176
175
  - lib/bio-samtools.rb
177
176
  - lib/bio/BIOExtensions.rb
@@ -252,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
251
  version: '0'
253
252
  requirements: []
254
253
  rubyforge_project:
255
- rubygems_version: 2.5.1
254
+ rubygems_version: 2.6.10
256
255
  signing_key:
257
256
  specification_version: 4
258
257
  summary: Binder of samtools for ruby, on the top of FFI.
@@ -1,50 +0,0 @@
1
- require 'rbconfig'
2
- require 'open-uri'
3
- #require 'open_uri_redirections'
4
- require 'fileutils'
5
- include FileUtils::Verbose
6
- require 'rake/clean'
7
-
8
- URL = "https://github.com/samtools/samtools/releases/download/1.3.1/samtools-1.3.1.tar.bz2"
9
- URL_bcf = "https://github.com/samtools/bcftools/releases/download/1.3.1/bcftools-1.3.1.tar.bz2"
10
- task :download do
11
- open(URL) do |uri|
12
- File.open("samtools-1.3.1.tar.bz2",'wb') do |fout|
13
- fout.write(uri.read)
14
- end #fout
15
- end #uri
16
-
17
- open(URL_bcf) do |uri|
18
- File.open("bcftools-1.3.1.tar.bz2",'wb') do |fout|
19
- fout.write(uri.read)
20
- end #fout
21
- end #uri
22
-
23
- end
24
-
25
- task :compile do
26
- sh "tar xvfj samtools-1.3.1.tar.bz2"
27
- cd("samtools-1.3.1") do
28
- sh "make"
29
- cp('samtools', "/Users/ramirezr/Documents/public_code/helios/bioruby-samtools/ext/../lib/bio/db/sam/external")
30
- end #cd
31
-
32
- sh "tar xvfj bcftools-1.3.1.tar.bz2"
33
- cd("bcftools-1.3.1") do
34
- sh "make"
35
- cp('bcftools', "/Users/ramirezr/Documents/public_code/helios/bioruby-samtools/ext/../lib/bio/db/sam/external")
36
- end #cd
37
- end
38
-
39
- task :clean do
40
- cd("samtools-1.3.1") do
41
- sh "make clean"
42
- end
43
- rm("samtools-1.3.1.tar.bz2")
44
- rm_rf("samtools-1.3.1")
45
- rm("bcftools-1.3.1.tar.bz2")
46
- rm_rf("bcftools-1.3.1")
47
- end
48
-
49
- task :default => [:download, :compile, :clean]
50
-