Method: Bio::Alignment::Output#output_molphy
- Defined in:
- lib/bio/alignment.rb
#output_molphy(options = {}) ⇒ Object
Generates Molphy alignment format text as a string
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 |
# File 'lib/bio/alignment.rb', line 1151 def output_molphy( = {}) len = self.alignment_length header = "#{self.number_of_sequences} #{len}\n" sn = self.sequence_names.collect { |x| x.to_s.gsub(/[\r\n\x00]/, ' ') } if [:replace_space] sn.collect! { |x| x.gsub(/\s/, '_') } end if !.has_key?(:escape) or [:escape] sn.collect! { |x| x.gsub(/[\:\;\,\(\)]/, '_') } end if !.has_key?(:split) or [:split] sn.collect! { |x| x.split(/\s/)[0].to_s } end if !.has_key?(:avoid_same_name) or [:avoid_same_name] sn = __clustal_avoid_same_name(sn, 30) end seqwidth = ([:width] or 60) seqregexp = Regexp.new("(.{1,#{seqwidth}})") gchar = ([:gap_char] or '-') aseqs = Array.new(len).clear self.each_seq do |s| aseqs << s.to_s.gsub(self.gap_regexp, gchar) end case [:case].to_s when /lower/i aseqs.each { |s| s.downcase! } when /upper/i aseqs.each { |s| s.upcase! } end aseqs.collect! do |s| s << (gchar * (len - s.length)) s.gsub!(seqregexp, "\\1\n") sn.shift + "\n" + s end aseqs.unshift(header) aseqs.join('') end |