Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HMMfile splitter
#!/usr/bin/env ruby
if ARGV.length != 2 then
STDERR.puts "Usage: #{$0} <pfamfile> <directory>"
exit 1
end
file = File.open(ARGV[0]).read
seen_accs = {}
file.split('//').each do |entry|
acc = nil
name = nil
leng = nil
desc = nil
entry.each_line do |l|
unless (m = /ACC\s+(.+)\./.match(l)).nil?
acc = m[1]
end
unless (m = /LENG\s+(.+)/.match(l)).nil?
leng = m[1]
end
unless (m = /DESC\s+(.+)/.match(l)).nil?
desc = m[1]
end
unless (m = /NAME\s+(.+)/.match(l)).nil?
name = m[1]
end
end
if !(seen_accs[acc].nil?) then
puts "acc seen twice: #{acc} (#{name})"
exit 1
else
seen_accs[acc] = true
#xxx
puts "#{acc}\t#{name}\t#{desc}\t#{leng}"
#xxx
end
File.open("#{ARGV[1]}/#{acc}_fs.hmm", "w+") do |f|
f.write("#{entry.lstrip}")
f.puts('//')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.