Skip to content

Instantly share code, notes, and snippets.

@shujishigenobu
Created April 12, 2013 10:55
Show Gist options
  • Select an option

  • Save shujishigenobu/5371237 to your computer and use it in GitHub Desktop.

Select an option

Save shujishigenobu/5371237 to your computer and use it in GitHub Desktop.
!/bin/ruby
#=== config
MAX_MEMORY = 30000000000
#===
$sam = ARGV[0]
bam_unsorted = File.basename($sam, '.sam') + '.unsorted.bam'
STDERR.puts "# converting sam to bam"
cmd = "samtools view -bS #{$sam} -o #{bam_unsorted}"
IO.popen(cmd){}
STDERR.puts "# sorting bam"
bam_sorted_prefix = File.basename(bam_unsorted, '.unsorted.bam')
cmd = "samtools sort -m #{MAX_MEMORY} #{bam_unsorted} #{bam_sorted_prefix}"
IO.popen(cmd){}
STDERR.puts "# indexing bam"
bam_sorted = bam_sorted_prefix + ".bam"
cmd = "samtools index #{bam_sorted}"
IO.popen(cmd)
File.delete(bam_unsorted)
STDERR.puts "# completed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment