Created
March 2, 2010 21:54
-
-
Save michaelbarton/320001 to your computer and use it in GitHub Desktop.
Find gap regions containing Ns in fasta files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'bio' | |
| def find_gaps(file,buffer=200) | |
| re = Regexp.compile("[ATGC]{#{buffer}}N+[ATGC]{#{buffer}}") | |
| return Bio::FastaFormat.open(file).inject(Hash.new([])) do |hash,entry| | |
| hash[entry.definition.split.first] = entry.seq.scan(re) | |
| hash | |
| end | |
| end | |
| # This bit prints the sequences to STDOUT as a series of fasta entries | |
| find_gaps(ARGV[0]).each do |scaffold,sequences| | |
| sequences.each_with_index {|s,i| puts s.to_fasta("#{scaffold} gap#{i+1}")} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment