Skip to content

Instantly share code, notes, and snippets.

@michaelbarton
Created April 3, 2012 15:25
Show Gist options
  • Save michaelbarton/2292903 to your computer and use it in GitHub Desktop.
Save michaelbarton/2292903 to your computer and use it in GitHub Desktop.
Update GFF records for tRNAs from identifiers in a different fasta file
#!/usr/bin/env ruby
require 'bio'
trnas = Bio::FlatFile.auto('genes.fna').
map(&:definition).
grep(/tRNA_..._.../).
map{|i| /^(?<id>\d+).+tRNA_(?<amino_acid>...)_(?<codon>...)/.match(i)}.
inject(Hash.new){|h,i| h[i[:id]] = {:amino_acid => i[:amino_acid], :codon => i[:codon]}; h}
a,b = Bio::GFF::GFF3.new(File.read('assembly/annotations.gff')).
records.partition{|i| trnas[i.id] }
a.map! do |i|
i.attributes = {
'feature_type' => 'tRNA',
'Note' => 'Codon: ' + trnas[i.id][:codon],
'product' => 'tRNA-' + trnas[i.id][:amino_acid],
'ID' => i.id}
i
end
puts a + b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment