Class: Bio::Ngs::Cufflinks::Transcript

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/appl/ngs/cufflinks/gtf/transcript.rb

Constant Summary collapse

Fields =
%w(seqname source feature start stop score strand frame)
Attr_to_Float =
%w(FPKM frac conf_lo conf_hi cov)
Attr_to_Integer =
%w(exon_number)
ChrNotation =
{ensembl:"", ucsc:"chr"}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTranscript

Returns a new instance of Transcript.



13
14
15
16
17
18
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 13

def initialize()
  @tra = nil
  @exons = []
  @attributes = {}
  @chr_notation = :ensembl #ensembl/ucsc
end

Instance Attribute Details

#chr_notationObject

Returns the value of attribute chr_notation.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def chr_notation
  @chr_notation
end

#featureObject

Returns the value of attribute feature.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def feature
  @feature
end

#frameObject

Returns the value of attribute frame.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def frame
  @frame
end

#scoreObject

Returns the value of attribute score.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def score
  @score
end

#seqnameObject

Returns the value of attribute seqname.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def seqname
  @seqname
end

#sourceObject

Returns the value of attribute source.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def source
  @source
end

#startObject

Returns the value of attribute start.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def start
  @start
end

#stopObject

Returns the value of attribute stop.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def stop
  @stop
end

#strandObject

Returns the value of attribute strand.



11
12
13
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 11

def strand
  @strand
end

Instance Method Details

#annotated_isoform?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 135

def annotated_isoform?
  attributes[:gene_id]!~/CUFF\.\d+/ && attributes[:transcript_id]!~/CUFF\.\d+\.\d+/
end

#attributesObject



38
39
40
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 38

def attributes
  @attributes
end

#brand_new_isoform?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 127

def brand_new_isoform?
  attributes[:gene_id]=~/CUFF\.\d+/ && attributes[:transcript_id]=~/CUFF\.\d+\.\d+/
end

#byte_lengthObject



139
140
141
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 139

def byte_length
  exons.map{|e| e.length}.sum + tra.length
end

#clearObject



122
123
124
125
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 122

def clear
  @tra=""
  @exons.clear
end

#exonsObject



30
31
32
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 30

def exons
  @exons
end

#exons=(ary) ⇒ Object



34
35
36
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 34

def exons=(ary)
  @exons=ary
end

#mono_exon?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 68

def mono_exon?
  exons.size == 1
end

#multi_exons?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 64

def multi_exons?
  exons.size > 1
end

#new_isoform?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 131

def new_isoform?
  attributes[:gene_id]=~/CUFF\.\d+/ && attributes[:transcript_id]!~/CUFF\.\d+\.\d+/
end

#set_ensembl_notationObject



147
148
149
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 147

def set_ensembl_notation
  @chr_notation = :ensembl
end

#set_ucsc_notationObject



143
144
145
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 143

def set_ucsc_notation
  @chr_notation = :ucsc
end

#sizeObject



72
73
74
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 72

def size
  @stop-@start+1
end

#to_bed(only_exons = true) ⇒ Object



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
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 96

def to_bed(only_exons=true)
  bed_str=""
  unless only_exons
#          puts seqname
#TODO fix seqname does not print the right  transcript line
    if @chr_notation == :ensembl && seqname=~/^chr(.*)/
      seqname="#{ChrNotation[:ensembl]}#{$1}"
    elsif @chr_notation == :ucsc && seqname=~/^(.*)/
      seqname="#{ChrNotation[:ucsc]}#{$1}"
    end

    bed_str<<"#{seqname}\t#{start}\t#{stop}\t#{attributes[:gene_id]}_#{attributes[:transcript_id]}\n"
  end
  exons.each do |e|
    data = e.tr('";','').split
    if @chr_notation == :ensembl && data[0]=~/^chr(.*)/
      data[0]="#{ChrNotation[:ensembl]}#{$1}"
    elsif @chr_notation == :ucsc && data[0]=~/^(.*)/
      data[0]="#{ChrNotation[:ucsc]}#{$1}"
    end

    bed_str<<"#{data[0]}\t#{data[3]}\t#{data[4]}\t#{data[9]}_#{data[11]}\n"
  end
  bed_str
end

#to_sObject

add last ā€œnā€ to last row.



91
92
93
94
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 91

def to_s
  s=tra #+"\n"
  s << exons.join #("\n") #<< "\n"
end

#traObject



20
21
22
23
24
25
26
27
28
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 20

def tra
  if @chr_notation == :ensembl && @tra=~/^chr(.*?)\s/
    "#{ChrNotation[:ensembl]}#{$1}"
  elsif @chr_notation == :ucsc && @tra=~/^(.*?)\s/
    "#{ChrNotation[:ucsc]}#{$1}"
  else
    @tra
  end
end

#tra=(line) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bio/appl/ngs/cufflinks/gtf/transcript.rb', line 41

def tra=(line)
    @tra = line
    data=line.split
    @seqname = data[0]
    @source = data[1]
    @feature = data[2]
    @start = data[3].to_i
    @stop = data[4].to_i
    @score = data[5]
    @strand = data[6]
    @frame = data[7]
    data[8..-1].join(" ").split(';').each do |attribute|
      data_attr=attribute.tr('"','').split
      @attributes[data_attr[0].to_sym]= if Attr_to_Float.include? data_attr[0]
      data_attr[1].to_f
    elsif Attr_to_Integer.include? data_attr[0]
      data_attr[1].to_i
    else
      data_attr[1]
    end
  end
end