Module: Exodb::GeneLocationField

Extended by:
ActiveSupport::Concern
Included in:
Chrref, Generef
Defined in:
lib/exodb/datamodel/genelocfield.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#beginInteger

get the start position of gene rely on the genome



96
97
98
# File 'lib/exodb/datamodel/genelocfield.rb', line 96

def begin
	self[:strand] == '+' ? self[:start] : self[:stop]
end

#chromosomeInteger

get the chromosome



110
111
112
# File 'lib/exodb/datamodel/genelocfield.rb', line 110

def chromosome
	self[:chr]
end

#dl_seq!Object

Download sequence from web service please use by caution. NCBI will block scamming sequest



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/exodb/datamodel/genelocfield.rb', line 66

def dl_seq!
	
	case self.chrrefseq
	when /\Aurn:miriam:refseq:/
		self.sequence = Bio::FastaFormat.new(Bio::NCBI::REST.efetch(self.chrrefseq.split(':', 4), {"db"=>"nucleotide", "rettype"=>"fasta", "retmode"=>"text", "seq_start"=>self.start, "seq_stop"=>self.end})).seq
	else 
		self.sequence = Exodb::Ensembl::REST.sequence_region()
	end
	
	self.save!
	
end

#endInteger

get the start position of gene rely on the genome



103
104
105
# File 'lib/exodb/datamodel/genelocfield.rb', line 103

def end
	self[:strand] == '+' ? self[:stop] : self[:start]
end

#get_splice(arr, strand = nil) ⇒ String

join exon or cds position into a string



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/exodb/datamodel/genelocfield.rb', line 160

def get_splice(arr, strand = nil)
	
	strand = strand || self[:strand]
	
	reducer = self[:seqlocation]['start'] - 1
	
	str = []
	
	arr.each do |e|
		str.push("#{e[0] - reducer}..#{e[1] - reducer}")
	end
	
	return strand == '+' ? self.to_seq.splicing("join(#{str.join(',')})") : self.to_seq.splicing("complement(join(#{str.join(',')}))")
	
end

#location=(loc) ⇒ Object

Assign location



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/exodb/datamodel/genelocfield.rb', line 117

def location=(loc)
	if loc.is_a?(String)
		
		begin
			loc.parse_loc.delete_if {|k, v| k == 'pos'}.each_pair do |k, v|
				self[k.to_sym] = v
			end
		rescue
			
		end
		
	end
end

#location_strString Also known as: locstr

Return location



134
135
136
# File 'lib/exodb/datamodel/genelocfield.rb', line 134

def location_str
	return "#{self.chromosome}:#{[self.start, self.stop].uniq.join('..')}"
end

#startInteger

get the start position of gene rely on the genome



82
83
84
# File 'lib/exodb/datamodel/genelocfield.rb', line 82

def start
	self[:start]
end

#stopInteger

get the end position of gene rely on the genome



89
90
91
# File 'lib/exodb/datamodel/genelocfield.rb', line 89

def stop
	self[:stop]
end

#to_seqBio::Sequence

Return gene sequence



143
144
145
# File 'lib/exodb/datamodel/genelocfield.rb', line 143

def to_seq
	whole_seq.splice("#{self[:start] - self[:seqstart] + 1}..#{self[:stop] - self[:seqstart] + 1}")
end

#whole_seqBio::Sequence

Return whole deposited sequence



150
151
152
# File 'lib/exodb/datamodel/genelocfield.rb', line 150

def whole_seq
	Bio::Sequence::NA.new(self[:sequence])
end