class Bio::Util::SynReport

Public Class Methods

new(opts) click to toggle source

attr_accessor :cdshash, :cds_list, :mRNAhash, :seqhash

# File lib/bio/utils/bio-synreport.rb, line 97
def initialize(opts)
  cdses = []
  mrna_list = []
  seqs = Hash.new
  
  Bio::FastaFormat.open(opts[:fasta]).each { |seq| seqs[seq.entry_id] = seq.to_seq }
  $stderr.puts "Loaded Seq..." if opts[:verbose]
  
  
  @mrnas = Hash.new  {|h,k| h[k] = Hash.new}
  File.open(opts[:gff], "r").each do |gffline|
    record = Bio::GFF::GFF3::Record.new(gffline)
    if record.feature_type == 'mRNA'
      mrna_list << Bio::Util::MrnaModel.new(gffline)
    elsif record.feature_type =='CDS'
      cdses << record
    end
  end
  
  mrna_list.each do |mrna|
    mrna_id = mrna.get_attributes("ID")
    $stderr.puts "No ID for #{cds}" if mrna_id.empty?
    mrna_id = mrna_id.first
    @mrnas[mrna.seqname][mrna_id] = mrna
    @mrnas[mrna.seqname][mrna_id].seq = seqs[mrna_id].seq
  end
  
  cdses.each do |cds|
    cds_parent = cds.get_attributes("Parent")
    $stderr.puts "No Parent for #{cds}" if cds_parent.empty?
    cds_parent = cds_parent.first
    @mrnas[cds.seqname][cds_parent].cds << [cds.start,cds.end]
  end
  $stderr.puts "Loaded GFF..." if opts[:verbose]


end

Public Instance Methods

is_in_cds?(chr,point) click to toggle source
# File lib/bio/utils/bio-synreport.rb, line 135
def is_in_cds?(chr,point)
  self.mutation_info(chr,point,"a") ? true : false
end
mutation_info(chr,pos,alt) click to toggle source

returns mutation info if point in CDS, if not in CDS returns false

# File lib/bio/utils/bio-synreport.rb, line 140
def mutation_info(chr,pos,alt)
  pos = pos.to_i
  #cant do indels ...
  return nil if alt.length > 1
  begin
    @mrnas[chr].each_pair do |mrna_id, mrna|
      if mrna.includes?(chr,pos)
        return mrna.substitution_info(pos,alt)   
      end
   end
    false
  rescue
    #somthing unpredicatable went wrong and we couldnt do the conversion ...
    return nil
  end
end