Created
May 27, 2015 13:31
-
-
Save satta/51f1427d54cc42ec969a to your computer and use it in GitHub Desktop.
HMMfile splitter
This file contains 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 | |
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