Skip to content

Instantly share code, notes, and snippets.

@drio
Created August 18, 2011 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drio/1154539 to your computer and use it in GitHub Desktop.
Save drio/1154539 to your computer and use it in GitHub Desktop.
parse fastq files and filter out base on name
#!/usr/bin/env ruby
# http://biostar.stackexchange.com/questions/10376/how-to-efficiently-parse-a-huge-fastq-file
# Usage: cat my.fastq | parse_fastq.rb list.txt
h = {} # hash with reads I am looking for
File.open(ARGV[0].to_s).each_line {|l| h["@" + l] = 1}
ln, f = [0, 0] # line number, flag
$stdin.each_line do |l|
f = h[l] ? 1 : 0 if ln % 4 == 0
puts l if f == 1
ln = ln + 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment