bio-samtools 2.3.3 → 2.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 775737792e8669adba78db39510bc7bfa13bb086
4
- data.tar.gz: 3741d4320545bb862be52f603e7ac6018eb1601d
3
+ metadata.gz: 90e15e76b4d1f9b079ab0f3fd6ecca9833a67e99
4
+ data.tar.gz: 251a8a0a110617d3894cfa6e287bc06bbd24ed89
5
5
  SHA512:
6
- metadata.gz: 11f21eab205187229b295bae05bc108a1ccec626b93f277e4e8c26f64dfd1a963c1ec741efef9476ab5717647a04e44079ffaeb14f99ae7561ceaca9e41060b5
7
- data.tar.gz: d593004ccb8e0dbf6f1f8f37372745e6caffba5e6b27f1f8b97973e180acd4ef25245629dffb438a2888888b49763d364f3f4c9330c793e011820c3f196c10a2
6
+ metadata.gz: 84b928dc4aeb6b96f7854beb4cf54bdc94d8a8e7b6a50e5a581d9a5d2d7d22f435f765ebae9ef4765701dd823c603ca84896714b5685269c9e4d33f7fceb1eff
7
+ data.tar.gz: 6eca1fbf0fcb285c2c4cf7a436eab0b087a697d1e858e8a4b491bd1ec13e2bc90fccec00c1c1d8c12c70b1bcb88ad4663271720c0b6de9fc5121c4b263cb4841
@@ -1,7 +1,11 @@
1
1
  language: ruby
2
- before_install:
3
- - sudo apt-get update
4
- - sudo apt-get install zlib1g-dev libncurses5-dev libtinfo-dev
2
+ sudo: false
3
+ addons:
4
+ apt:
5
+ packages:
6
+ - zlib1g-dev
7
+ - libncurses5-dev
8
+ - libtinfo-dev
5
9
  before_script:
6
10
  - cd ext
7
11
  - ruby mkrf_conf.rb
@@ -12,3 +16,4 @@ rvm:
12
16
  - 2.0.0
13
17
  - 2.1.0
14
18
  - 2.2.2
19
+ - 2.2.3
data/Gemfile CHANGED
@@ -4,11 +4,12 @@ source "http://rubygems.org"
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "bio-svgenes", ">= 0.4.1"
6
6
  gem "bio", ">= 1.4.2"
7
+ gem 'open_uri_redirections'
7
8
 
8
9
  # Add dependencies to develop your gem here.
9
10
  # Include everything needed to run rake, tests, features, etc.
10
11
  group :development do
11
- gem "shoulda", ">= 0"
12
+ gem "shoulda", "> 2.10"
12
13
  gem "shoulda-context"
13
14
  gem "shoulda-matchers"
14
15
  gem "bundler", "> 1.0.21"
data/README.md CHANGED
@@ -485,6 +485,18 @@ The latest I think is the easiest way, cause you are replicating the automatic p
485
485
 
486
486
  For testing just run `rake test`. Tests must be improved.
487
487
 
488
+ ####Travis integration###
489
+ If you are integrating this library into another tool and testing it with travis, add the follwing in ```.travis.yml```:
490
+
491
+ ```yml
492
+ addons:
493
+ apt:
494
+ packages:
495
+ - zlib1g-dev
496
+ - libncurses5-dev
497
+ - libtinfo-dev
498
+ ```
499
+
488
500
  ## Copyright
489
501
 
490
502
  Copyright (c) 2011 Raoul J.P. Bonnal. See LICENSE.txt for
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.4
1
+ 2.4.0
@@ -63,7 +63,6 @@ fasta_db.load_fai_entries
63
63
 
64
64
  output = $stdout
65
65
 
66
-
67
66
  output = File.open(options[:output_file], "w") if options[:output_file] != "-"
68
67
 
69
68
  fasta_db.index.entries.each do | r |
@@ -2,17 +2,17 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bio-samtools 2.3.3 ruby lib
5
+ # stub: bio-samtools 2.4.0 ruby lib
6
6
  # stub: ext/mkrf_conf.rb
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "bio-samtools"
10
- s.version = "2.3.3"
10
+ s.version = "2.4.0"
11
11
 
12
12
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
14
14
  s.authors = ["Ricardo Ramirez-Gonzalez", "Dan MacLean", "Raoul J.P. Bonnal"]
15
- s.date = "2015-06-19"
15
+ s.date = "2016-05-25"
16
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
17
  s.email = "Ricardo.Ramirez-Gonzalez@tgac.ac.uk"
18
18
  s.executables = ["bam_consensus.rb"]
@@ -101,6 +101,9 @@ Gem::Specification.new do |s|
101
101
  "test/helper.rb",
102
102
  "test/sample.vcf",
103
103
  "test/samples/.gitignore",
104
+ "test/samples/LCI/NC_001988.ffn",
105
+ "test/samples/LCI/test.bam",
106
+ "test/samples/LCI/test.bam.bai",
104
107
  "test/samples/small/dupes.bam",
105
108
  "test/samples/small/dupes.sam",
106
109
  "test/samples/small/ids2.txt",
@@ -133,7 +136,6 @@ Gem::Specification.new do |s|
133
136
  "test/samples/small/test_chr.fasta.sa",
134
137
  "test/samples/small/test_cov.svg",
135
138
  "test/samples/small/testu.bam",
136
- "test/samples/small/testu.bam.bai",
137
139
  "test/samples/small/testu.bed",
138
140
  "test/test_bio-samtools.rb",
139
141
  "test/test_pileup.rb",
@@ -145,7 +147,7 @@ Gem::Specification.new do |s|
145
147
  ]
146
148
  s.homepage = "http://github.com/helios/bioruby-samtools"
147
149
  s.licenses = ["MIT"]
148
- s.rubygems_version = "2.4.6"
150
+ s.rubygems_version = "2.2.2"
149
151
  s.summary = "Binder of samtools for ruby, on the top of FFI."
150
152
 
151
153
  if s.respond_to? :specification_version then
@@ -154,7 +156,8 @@ Gem::Specification.new do |s|
154
156
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
155
157
  s.add_runtime_dependency(%q<bio-svgenes>, [">= 0.4.1"])
156
158
  s.add_runtime_dependency(%q<bio>, [">= 1.4.2"])
157
- s.add_development_dependency(%q<shoulda>, [">= 0"])
159
+ s.add_runtime_dependency(%q<open_uri_redirections>, [">= 0"])
160
+ s.add_development_dependency(%q<shoulda>, ["> 2.10"])
158
161
  s.add_development_dependency(%q<shoulda-context>, [">= 0"])
159
162
  s.add_development_dependency(%q<shoulda-matchers>, [">= 0"])
160
163
  s.add_development_dependency(%q<bundler>, ["> 1.0.21"])
@@ -167,7 +170,8 @@ Gem::Specification.new do |s|
167
170
  else
168
171
  s.add_dependency(%q<bio-svgenes>, [">= 0.4.1"])
169
172
  s.add_dependency(%q<bio>, [">= 1.4.2"])
170
- s.add_dependency(%q<shoulda>, [">= 0"])
173
+ s.add_dependency(%q<open_uri_redirections>, [">= 0"])
174
+ s.add_dependency(%q<shoulda>, ["> 2.10"])
171
175
  s.add_dependency(%q<shoulda-context>, [">= 0"])
172
176
  s.add_dependency(%q<shoulda-matchers>, [">= 0"])
173
177
  s.add_dependency(%q<bundler>, ["> 1.0.21"])
@@ -181,7 +185,8 @@ Gem::Specification.new do |s|
181
185
  else
182
186
  s.add_dependency(%q<bio-svgenes>, [">= 0.4.1"])
183
187
  s.add_dependency(%q<bio>, [">= 1.4.2"])
184
- s.add_dependency(%q<shoulda>, [">= 0"])
188
+ s.add_dependency(%q<open_uri_redirections>, [">= 0"])
189
+ s.add_dependency(%q<shoulda>, ["> 2.10"])
185
190
  s.add_dependency(%q<shoulda-context>, [">= 0"])
186
191
  s.add_dependency(%q<shoulda-matchers>, [">= 0"])
187
192
  s.add_dependency(%q<bundler>, ["> 1.0.21"])
@@ -1,51 +1,50 @@
1
1
  require 'rbconfig'
2
2
  require 'open-uri'
3
+ #require 'open_uri_redirections'
3
4
  require 'fileutils'
4
5
  include FileUtils::Verbose
5
6
  require 'rake/clean'
6
7
 
7
- URL = "http://sourceforge.net/projects/samtools/files/samtools/1.2/samtools-1.2.tar.bz2/download"
8
- URL2 = "https://github.com/samtools/bcftools/releases/download/1.2/bcftools-1.2.tar.bz2"
9
-
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
10
  task :download do
11
11
  open(URL) do |uri|
12
- File.open("samtools-1.2.tar.bz2",'wb') do |fout|
12
+ File.open("samtools-1.3.1.tar.bz2",'wb') do |fout|
13
13
  fout.write(uri.read)
14
- end #fout
14
+ end #fout
15
15
  end #uri
16
16
 
17
- open(URL2) do |uri|
18
- File.open("bcftools-1.2.tar.bz2",'wb') do |fout|
17
+ open(URL_bcf) do |uri|
18
+ File.open("bcftools-1.3.1.tar.bz2",'wb') do |fout|
19
19
  fout.write(uri.read)
20
- end #fout
20
+ end #fout
21
21
  end #uri
22
+
22
23
  end
23
-
24
+
24
25
  task :compile do
25
- sh "tar xvfj samtools-1.2.tar.bz2"
26
- sh "tar xvfj bcftools-1.2.tar.bz2"
27
- cd("samtools-1.2") do
26
+ sh "tar xvfj samtools-1.3.1.tar.bz2"
27
+ cd("samtools-1.3.1") do
28
28
  sh "make"
29
- cp("samtools", "/Users/ramirezr/Documents/public_code/bioruby-samtools/ext/../lib/bio/db/sam/external")
29
+ cp('samtools', "/Users/ramirezr/Documents/public_code/helios/bioruby-samtools/ext/../lib/bio/db/sam/external")
30
30
  end #cd
31
- cd("bcftools-1.2") do
31
+
32
+ sh "tar xvfj bcftools-1.3.1.tar.bz2"
33
+ cd("bcftools-1.3.1") do
32
34
  sh "make"
33
- cp('bcftools', "/Users/ramirezr/Documents/public_code/bioruby-samtools/ext/../lib/bio/db/sam/external")
34
- end
35
+ cp('bcftools', "/Users/ramirezr/Documents/public_code/helios/bioruby-samtools/ext/../lib/bio/db/sam/external")
36
+ end #cd
35
37
  end
36
-
38
+
37
39
  task :clean do
38
- cd("samtools-1.2") do
40
+ cd("samtools-1.3.1") do
39
41
  sh "make clean"
40
42
  end
41
- cd("bcftools-1.2") do
42
- sh "make clean"
43
- end
44
- rm("samtools-1.2.tar.bz2")
45
- rm_rf("samtools-1.2")
46
- rm("bcftools-1.2.tar.bz2")
47
- rm_rf("bcftools-1.2")
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")
48
47
  end
49
48
 
50
49
  task :default => [:download, :compile, :clean]
51
-
50
+
@@ -1,4 +1,4 @@
1
- #(c) Copyright 2011 Raoul Bonnal. All Rights Reserved.
1
+ #(c) Copyright 2011 Raoul Bonnal. All Rights Reserved.
2
2
 
3
3
  # create Rakefile for shared library compilation
4
4
 
@@ -12,64 +12,64 @@ version = File.open(File.join(path_external,"VERSION"),'r')
12
12
  Version = version.read
13
13
  version.close
14
14
 
15
- url = "http://sourceforge.net/projects/samtools/files/samtools/#{Version}/samtools-#{Version}.tar.bz2/download"
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"
16
17
  SamToolsFile = "samtools-#{Version}.tar.bz2"
17
- url2 = "https://github.com/samtools/bcftools/releases/download/#{Version}/bcftools-#{Version}.tar.bz2"
18
- VcfToolsFile = "bcftools-#{Version}.tar.bz2"
18
+ url_bcftools="https://github.com/samtools/bcftools/releases/download/#{Version}/bcftools-#{Version}.tar.bz2"
19
+ BcfToolsFile = "bcftools-#{Version}.tar.bz2"
19
20
 
20
21
  File.open(File.join(path,"Rakefile"),"w") do |rakefile|
21
22
  rakefile.write <<-RAKE
22
23
  require 'rbconfig'
23
24
  require 'open-uri'
25
+ #require 'open_uri_redirections'
24
26
  require 'fileutils'
25
27
  include FileUtils::Verbose
26
28
  require 'rake/clean'
27
29
 
28
30
  URL = "#{url}"
29
- URL2 = "#{url2}"
30
-
31
+ URL_bcf = "#{url_bcftools}"
31
32
  task :download do
32
33
  open(URL) do |uri|
33
34
  File.open("#{SamToolsFile}",'wb') do |fout|
34
35
  fout.write(uri.read)
35
- end #fout
36
+ end #fout
36
37
  end #uri
37
38
 
38
- open(URL2) do |uri|
39
- File.open("#{VcfToolsFile}",'wb') do |fout|
39
+ open(URL_bcf) do |uri|
40
+ File.open("#{BcfToolsFile}",'wb') do |fout|
40
41
  fout.write(uri.read)
41
- end #fout
42
+ end #fout
42
43
  end #uri
44
+
43
45
  end
44
-
46
+
45
47
  task :compile do
46
48
  sh "tar xvfj #{SamToolsFile}"
47
- sh "tar xvfj #{VcfToolsFile}"
48
49
  cd("samtools-#{Version}") do
49
50
  sh "make"
50
- cp("samtools", "#{path_external}")
51
+ cp('samtools', "#{path_external}")
51
52
  end #cd
53
+
54
+ sh "tar xvfj #{BcfToolsFile}"
52
55
  cd("bcftools-#{Version}") do
53
56
  sh "make"
54
57
  cp('bcftools', "#{path_external}")
55
- end
58
+ end #cd
56
59
  end
57
-
60
+
58
61
  task :clean do
59
62
  cd("samtools-#{Version}") do
60
63
  sh "make clean"
61
64
  end
62
- cd("bcftools-#{Version}") do
63
- sh "make clean"
64
- end
65
65
  rm("#{SamToolsFile}")
66
66
  rm_rf("samtools-#{Version}")
67
- rm("#{VcfToolsFile}")
67
+ rm("#{BcfToolsFile}")
68
68
  rm_rf("bcftools-#{Version}")
69
69
  end
70
70
 
71
71
  task :default => [:download, :compile, :clean]
72
-
72
+
73
73
  RAKE
74
-
75
- end
74
+
75
+ end
@@ -1,7 +1,9 @@
1
- require 'open3'
2
1
  module Bio
3
2
  class DB
4
3
  class Sam
4
+
5
+ class SamException < StandardError; end
6
+
5
7
  attr_accessor :bam, :fasta, :samtools, :bcftools, :last_command
6
8
  attr_accessor :minumum_ratio_for_iup_consensus
7
9
  attr_reader :cached_regions
@@ -25,7 +27,7 @@ module Bio
25
27
 
26
28
  @last_command = nil
27
29
  raise ArgumentError, "Need Fasta and at least one BAM or SAM" if not @fasta or not @bam
28
- raise IOError, "File not found #{files}" if not files_ok?
30
+ raise IOError, "File not found #{@files}" if not files_ok?
29
31
  @bams = [@bams] if @bams.instance_of? String
30
32
 
31
33
  end
@@ -65,7 +67,7 @@ module Bio
65
67
  region = String.new
66
68
  if opts[:chr] and opts[:start] and opts[:stop]
67
69
  has_e = self.has_entry? opts[:chr]
68
- raise Exception.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]
69
71
  region = "#{opts[:chr]}:#{opts[:start]}-#{opts[:stop]}"
70
72
  [:chr, :start, :stop].each {|o| opts.delete(o)}
71
73
  end
@@ -80,7 +82,7 @@ module Bio
80
82
  end
81
83
  command = String.new
82
84
  command = form_opt_string(@samtools, 'view', opts, [:b, :h, :H, :S, :u, '1', :x, :X, :c, :B])
83
- commad = command + " '#{region}'" if region.size > 0
85
+ command = command + " '#{region}'" if region.size > 0
84
86
  @last_command = command
85
87
  type = (opts[:u] or opts[:b]) ? :binary : :text
86
88
  klass = (type == :binary) ? String : Bio::DB::Alignment
@@ -258,7 +260,7 @@ module Bio
258
260
  query = opts[:r].to_s
259
261
  query = opts[:r].to_region.to_s if opts[:r].respond_to?(:to_region)
260
262
  if not query.nil? and query.size > 0
261
- raise Exception.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
262
264
  end
263
265
  opts[:r] = query
264
266
 
@@ -268,7 +270,7 @@ module Bio
268
270
  end
269
271
 
270
272
  command = form_opt_string(@samtools, "mpileup", opts, [:R, :B, :E, "6", :A, :g, :u, :I] )
271
- puts stderr.read if $VERBOSE
273
+ puts "Running: #{command}" if $VERBOSE
272
274
  if opts[:u]
273
275
  command = command + " | #{@bcftools} view -cg -"
274
276
  end
@@ -285,13 +287,13 @@ module Bio
285
287
  #* stop - [INT] the stop position for the subsequence
286
288
  #* as_bio - boolean stating if the returned object should be a Bio::Sequence::NA object
287
289
  def fetch_reference(chr,start,stop, opts={:as_bio => false})
288
- raise Exception.new(), "The sequence #{chr} is not in the bam file" unless has_entry? chr
290
+ raise SamException.new(), "The sequence #{chr} is not in the bam file" unless has_entry? chr
289
291
  seq = ""
290
292
  unless @fasta #We return a string of Ns if we don't know the reference.
291
293
  seq = "n" * (stop-start)
292
294
  else
293
- command = "#{@samtools} faidx #{@fasta} '#{chr}:#{start}-#{stop}'"
294
- puts stderr.read if $VERBOSE
295
+ command = "#{@samtools} faidx \"#{@fasta}\" '#{chr}:#{start}-#{stop}'"
296
+ puts "Running: #{command}" if $VERBOSE
295
297
  @last_command = command
296
298
  seq = ""
297
299
  yield_from_pipe(command, String, :text ) {|line| seq = seq + line unless line =~ /^>/}
@@ -313,19 +315,17 @@ module Bio
313
315
  opts={:as_bio => false}
314
316
  self.fetch_reference(:chr,:start,:stop,opts)
315
317
  else
316
- command = "#{@samtools} faidx #{@fasta}"
318
+ command = "#{@samtools} faidx \"#{@fasta}\""
317
319
  @last_command = command
318
320
  system(command)
319
321
  end
320
322
  end
321
323
 
322
324
  #Index sorted alignment for fast random access. Index file <aln.bam>.bai will be created of no out_index is provided.
323
- #* out_index - [STRING] name of index Depreciated. It will fail now as
324
- #* samtools doesn't support it anymore.
325
+ #* out_index - [STRING] name of index
325
326
  def index(opts={})
326
- raise Exception.new "Index can't recieve parameters" if opts.size > 0
327
- command = "#{@samtools} index #{@bam}"
328
- puts stderr.read if $VERBOSE
327
+ command = "#{@samtools} index \"#{@bam}\" #{opts[:out_index]}"
328
+ puts "Running: #{command}" if $VERBOSE
329
329
  @last_command = command
330
330
  system(command)
331
331
  end
@@ -333,15 +333,14 @@ module Bio
333
333
  #Fill in mate coordinates, ISIZE and mate related flags from a name-sorted alignment
334
334
  #* out_bam name of outfile
335
335
  #* r - remove unmapped reads and secondary alignments
336
- #* p - Disable FR proper pair check.
337
- #* o - Add template cigar ct tag.
338
- #* O FORMAT Write the final output as sam, bam, or cram.
339
336
  def fix_mates(opts={})
340
- out_bam = opts[:out_bam]
341
- opts.delete(:out_bam)
342
- command = form_opt_string(@samtools, "fixmate", opts, [:r,:p,:c])
343
- command << " #{out_bam}"
344
- puts stderr.read if $VERBOSE
337
+ #opts.merge!({:out_index=>nil})
338
+ remove_reads = ""
339
+ if opts[:r]
340
+ remove_reads = "-r"
341
+ end
342
+ command = "#{@samtools} fixmate #{remove_reads} \"#{@bam}\" #{opts[:out_bam]}"
343
+ puts "Running: #{command}" if $VERBOSE
345
344
  @last_command = command
346
345
  system(command)
347
346
  end
@@ -351,7 +350,7 @@ module Bio
351
350
  #generate simple stats with regard to the number and pairing of reads mapped to a reference
352
351
  def flag_stats(opts={})
353
352
  command = form_opt_string(@samtools, "flagstat", opts, [])
354
- puts stderr.read if $VERBOSE
353
+ puts "Running: #{command}" if $VERBOSE
355
354
  @last_command = command
356
355
  strings = []
357
356
  yield_from_pipe(command,String) {|line| strings << line.chomp}
@@ -366,7 +365,7 @@ module Bio
366
365
  stats = {}
367
366
  command = form_opt_string(@samtools, "idxstats", {}, [])
368
367
  @last_command = command
369
- puts stderr.read if $VERBOSE
368
+ puts "Running: #{command}" if $VERBOSE
370
369
  yield_from_pipe(command, String, :text, true, "#") do |line|
371
370
  info = line.chomp.split(/\t/)
372
371
  stats[ info[0] ] = {:length => info[1].to_i, :mapped_reads => info[2].to_i, :unmapped_reads => info[3].to_i }
@@ -447,7 +446,7 @@ module Bio
447
446
  command = "#{@samtools} merge #{options} #{out} #{bam_list}"
448
447
 
449
448
  @last_command = command
450
- puts command puts stderr.read if $VERBOSE
449
+ puts "Running: #{command}" if $VERBOSE
451
450
  system(command)
452
451
 
453
452
  end
@@ -482,10 +481,9 @@ module Bio
482
481
  #* S - treat PE reads as SE in rmdup (force -s)
483
482
  #* out - [FILE] output bam
484
483
  def remove_duplicates(opts={})
485
- raise Exception.new(), "Remove duplicates is unsuported in samtools 1.2. This function will come back onece rmdup is available again."
486
484
  out = opts[:out]
487
485
  opts.delete(:out)
488
- command = "#{form_opt_string(@samtools, "rmdup", opts, [:s, :S])} #{out} #{@bam}"
486
+ command = "#{form_opt_string(@samtools, "rmdup", opts, [:s, :S])} #{out} \"#{@bam}\""
489
487
  @last_command = command
490
488
  system(command)
491
489
  end
@@ -495,26 +493,28 @@ module Bio
495
493
  #Sort alignments by leftmost coordinates
496
494
  #* n - sort by read name
497
495
  #* f - use <out.prefix> as full file name instead of prefix
498
- #* o - final output to stdout returns bio::db::alignment
496
+ #* o - final output to stdout returns bio::db::alignment depreciated (samtools-1.x saves to a file)
499
497
  #* l - [INT] compression level, from 0 to 9 [-1]
500
498
  #* at - [INT] number of sorting and compression threads [1]
501
499
  #* m - [INT] max memory per thread; suffix K/M/G recognized [768M]
502
- #* prefix - [STRING] prefix for output bamfile
500
+ #* prefix - [STRING] prefix for output bamfile (for legacy, becomes "o" to use in samtools-1.x)
503
501
  def sort(opts={})
504
502
  if !opts.has_key?(:prefix)
505
- opts.merge!({:prefix => "sorted"})
503
+ opts.merge!({:o => "sorted"})
504
+ else
505
+ opts[:o] = opts[:prefix] += ".bam"
506
506
  end
507
- prefix = opts[:prefix]
507
+
508
508
  opts.delete(:prefix)
509
- command = form_opt_string(@samtools, "sort", opts, [:n, :f, :o])
510
- command = command + " " + prefix
509
+ command = form_opt_string(@samtools, "sort", opts, [:n, :f])
510
+ command = command + " "
511
511
  @last_command = command
512
- puts stderr.read if $VERBOSE
513
- if opts[:o]
514
- yield_from_pipe(command, Bio::DB::Alignment)
515
- else
516
- system(command)
517
- end
512
+ puts "Running: #{command}" if $VERBOSE
513
+ #if opts[:o]
514
+ # yield_from_pipe(command, Bio::DB::Alignment)
515
+ #else
516
+ system(command)
517
+ #end
518
518
  end
519
519
 
520
520
  #used to generate a text alignment viewer
@@ -535,7 +535,7 @@ module Bio
535
535
  opts.delete(:s)
536
536
  end
537
537
  command = "#{form_opt_string(@samtools, "tview", opts)}"
538
- puts stderr.read if $VERBOSE
538
+ puts "Running: #{command}" if $VERBOSE
539
539
  @last_command = command
540
540
  system(command)
541
541
  end
@@ -546,11 +546,11 @@ module Bio
546
546
  def reheader(header_sam, opts={})
547
547
  if opts.has_key?(:out)
548
548
  out=opts[:out]
549
- command = "#{@samtools} reheader #{header_sam} #{@bam} > #{out}"
549
+ command = "#{@samtools} reheader #{header_sam} \"#{@bam}\" > #{out}"
550
550
  else
551
- command = "#{@samtools} reheader #{header_sam} #{@bam}"
551
+ command = "#{@samtools} reheader #{header_sam} \"#{@bam}\""
552
552
  end
553
- puts stderr.read if $VERBOSE
553
+ puts "Running: #{command}" if $VERBOSE
554
554
  @last_command = command
555
555
  system(command)
556
556
  end
@@ -566,7 +566,7 @@ module Bio
566
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
- puts stderr.read if $VERBOSE
569
+ puts "Running: #{command}" if $VERBOSE
570
570
  @last_command = command
571
571
  type = :text
572
572
  klass = Bio::DB::Alignment
@@ -587,7 +587,7 @@ module Bio
587
587
  end
588
588
 
589
589
  command = "#{form_opt_string(@samtools, "targetcut", opts, [] )}"
590
- puts stderr.read if $VERBOSE
590
+ puts "Running: #{command}" if $VERBOSE
591
591
  @last_command = command
592
592
  system(command)
593
593
  end
@@ -601,7 +601,7 @@ module Bio
601
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
- puts stderr.read if $VERBOSE
604
+ puts "Running: #{command}" if $VERBOSE
605
605
  @last_command = command
606
606
  system(command)
607
607
  end
@@ -646,7 +646,7 @@ module Bio
646
646
  #
647
647
  #TODO: It may be good to load partially the pileup
648
648
  def mpileup_cached (opts={})
649
- raise Exception.new(), "A region must be provided" unless opts[:r] or opts[:region]
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]
@@ -675,11 +675,11 @@ module Bio
675
675
  #bam = opts[:bam]
676
676
  if opts.has_key?(:out)
677
677
  out=opts[:out]
678
- command = "#{@samtools} bedcov #{bed} #{@bam} > #{out}"
678
+ command = "#{@samtools} bedcov \"#{bed}\" \"#{@bam}\" > \"#{out}\""
679
679
  else
680
- command = "#{@samtools} bedcov #{bed} #{@bam}"
680
+ command = "#{@samtools} bedcov \"#{bed}\" \"#{@bam}\""
681
681
  end
682
- #puts stderr.read if $VERBOSE
682
+ puts "Running: #{command}" if $VERBOSE
683
683
  #puts command
684
684
  @last_command = command
685
685
  system(command)
@@ -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 stderr.read if $VERBOSE
742
+ puts "Running: #{command}" if $VERBOSE
743
743
  stdin.close
744
744
  pipe.close
745
745
  stderr.close
@@ -753,7 +753,7 @@ module Bio
753
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
- "#{prog} #{command} #{opts_string} #{@bam}"
756
+ "#{prog} #{command} #{opts_string} \"#{@bam}\""
757
757
  end
758
758
 
759
759
  # turns an opts hash into a string