Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

started script to split fasta sequences into chunks

  • Loading branch information...
commit 2368c22970e265b05c4d2630e21d18153e353235 1 parent 158c26f
Ben J. Woodcroft authored
Showing with 41 additions and 0 deletions.
  1. +41 −0 sequence_chunks.rb
View
41 sequence_chunks.rb
@@ -0,0 +1,41 @@
+#!/usr/bin/env ruby
+
+require 'optparse'
+require 'bio-logger'
+require 'bio'
+
+if __FILE__ == $0 #needs to be removed if this script is distributed as part of a rubygem
+ SCRIPT_NAME = File.basename(__FILE__); LOG_NAME = SCRIPT_NAME.gsub('.rb','')
+
+ # Parse command line options into the options hash
+ options = {
+ :logger => 'stderr',
+ :chunk_size => 500,
+ :step_size => 250,
+ }
+ o = OptionParser.new do |opts|
+ opts.banner = "
+ Usage: #{SCRIPT_NAME} <fasta_file>
+
+ Takes an input fasta file, and separates each sequence it into overlapping pieces. Prints the chunks on stdout.\n\n"
+
+ # logger options
+ opts.on("-q", "--quiet", "Run quietly, set logging to ERROR level [default INFO]") {Bio::Log::CLI.trace('error')}
+ opts.on("--logger filename",String,"Log to file [default #{options[:logger]}]") { |name| options[:logger] = name}
+ opts.on("--trace options",String,"Set log level [default INFO]. e.g. '--trace debug' to set logging level to DEBUG"){|s| Bio::Log::CLI.trace(s)}
+ end
+ o.parse!
+ if ARGV.length != 0
+ $stderr.puts o
+ exit 1
+ end
+ # Setup logging. bio-logger defaults to STDERR not STDOUT, I disagree
+ Bio::Log::CLI.logger(options[:logger]); log = Bio::Log::LoggerPlus.new(LOG_NAME); Bio::Log::CLI.configure(LOG_NAME)
+
+
+ Bio::FlatFile.foreach(ARGF) do |seq|
+ name = seq.definition.split(/\s/)[0]
+
+ seq.window_search(500,250)
+ end
+end #end if running as a script
Please sign in to comment.
Something went wrong with that request. Please try again.