Skip to content

Instantly share code, notes, and snippets.

@yagays
Created May 29, 2012 08:23
Show Gist options
  • Select an option

  • Save yagays/2823292 to your computer and use it in GitHub Desktop.

Select an option

Save yagays/2823292 to your computer and use it in GitHub Desktop.
NGSのサンプルデータっぽい感じで,fastaから適当に短い配列取ってきてfastqにするスクリプト
#/usr/bin/env ruby
# usage:
# ruby rand_fastq.rb hoge.fasta > random.fastq
require 'bio'
genome = ""
read_length = 100
read_count = 10000000
Bio::FlatFile.open(Bio::FastaFormat,ARGV[0]).each do |e|
genome << e.naseq.gsub(/n/,"")
end
random_start = Array.new( read_count ){ rand genome.length - read_length}
random_start.each_with_index do |r,i|
seq = Bio::Sequence.new(genome[r, read_length].upcase)
puts seq.output(:fastq, :title=> "random_"+i.to_s, :width => read_length)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment