Created
February 23, 2011 10:49
-
-
Save yagays/840281 to your computer and use it in GitHub Desktop.
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 | |
def open_indel_file(filename) | |
h = [] | |
open(filename) { |f| | |
f.each_line do |line| | |
a = line.chomp.split("\t") | |
h << a | |
end | |
} | |
h.reverse!{ |a,b| a[0].to_i <=> b[0].to_i} | |
h | |
end | |
def open_fasta_file(filename) | |
sequence = "" | |
seq_name = "" | |
open(filename){ |f| | |
f.each_line do |line| | |
if line =~ />(.+)$/ | |
seq_name = $1 | |
else | |
sequence += line.chomp | |
end | |
end | |
} | |
return sequence, seq_name | |
end | |
if __FILE__ == $PROGRAM_NAME | |
indels = open_indel_file(ARGV[0]) | |
sequence, seq_name = open_fasta_file(ARGV[1]) | |
output_file_name = "output.fasta" # 出力ファイル名 | |
output_seq_length = 60 # 出力するFASTAの1行あたりの塩基長 | |
indels.each do |i| | |
s = i[0].to_i | |
n = i[1] | |
flag = i[2] | |
if flag == "insertion" | |
sequence.insert(s, n) | |
elsif flag == "deletion" | |
sequence[s, n.length] = "" | |
else | |
puts "unknown format : #{flag}" | |
end | |
end | |
open(output_file_name, "w"){ |f| | |
f.puts ">" + seq_name | |
sequence.each_char.each_slice(output_seq_length){|l| f.puts l.join} | |
f.puts "\n" | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://qa.lifesciencedb.jp/questions/328