Class: Bio::Util::SynReport

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/utils/bio-synreport.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ SynReport

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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/bio/utils/bio-synreport.rb', line 71

def initialize(opts)
  @gene_array = []
  @cdshash = Hash.new {|h,k| h[k] = Hash.new {|a,b| a[b] = [] } }
  @mRNAhash = Hash.new {|h,k| h[k] = Hash.new {|a,b| a[b] = [] } }
  File.open(opts[:gff], "r").each do |gffline|
    record=Bio::GFF::GFF3::Record.new(gffline)
    if(record.feature_type == 'gene')
        @gene_array << [record.seqname, record.id]
    elsif(record.feature_type == 'CDS' or record.feature_type == 'mRNA')
      parents = record.get_attributes('Parent')
      parents.each do |parent|  
        if record.feature_type == 'CDS'
          @cdshash[record.seqname][parent] << record
        else
          @mRNAhash[record.seqname][parent] << record
        end
      end
    end
  end
  $stderr.puts "Loaded GFF..." if opts[:verbose]
  @seqhash = {}
  Bio::FastaFormat.open(opts[:fasta]).each { |seq| @seqhash[seq.entry_id] = seq.to_seq }
  $stderr.puts "Loaded Seq..." if opts[:verbose]
  
  @models = Hash.new {|h,k| h[k] =  []  }
  $stderr.puts "Building models..." if opts[:verbose] 
  @gene_array.each do |gene|

    mRNAs=@mRNAhash[gene.first][gene.last]
    mRNAs.each do |mRNA|
      next if @seqhash[gene.first].nil?
      cdsa = []
      seqs = []
      cdsary=@cdshash[gene.first][mRNA.id]
      cdsary.each {|c| cdsa << [c.start, c.end]} 
      cdsa.sort!
      cdsa.reverse! if mRNA.strand == '-'
      
      cdsa.each do |cds|

        #cdsa << [cds.start, cds.end]
        if mRNA.strand == '+'
          seqs << Bio::Sequence::NA.new(@seqhash[mRNA.seqname].splicing("#{cds.first}..#{cds.last}") )
        elsif mRNA.strand == "-"
          seqs << Bio::Sequence::NA.new(@seqhash[mRNA.seqname].splicing("#{cds.first}..#{cds.last}") ).complement
        end
      end
      @models[mRNA.seqname] << Bio::Util::MrnaModel.new(mRNA.seqname, mRNA.id, mRNA.strand, cdsa, seqs )
      #pp @models[mRNA.seqname][-1].cds if mRNA.id == 'AT2G17530.1' or mRNA.id == 'AT2G17550.1'
    end
  end
  $stderr.puts "Models built..." if opts[:verbose]
end

Instance Method Details

#is_in_cds?(chr, point) ⇒ Boolean

init end

Returns:

  • (Boolean)


125
126
127
# File 'lib/bio/utils/bio-synreport.rb', line 125

def is_in_cds?(chr,point)
  @self.mutation_info(chr,point) ? true : false
end

#mutation_info(chr, pos, alt) ⇒ Object

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



130
131
132
133
134
135
136
137
138
# File 'lib/bio/utils/bio-synreport.rb', line 130

def mutation_info(chr,pos,alt)

  @models[chr].each do |m|
     if m.includes?(chr,pos)
       return m.substitution_info(chr,pos,alt)   
     end
  end
  false
end