Module: Exodb::VarLocationField

Extended by:
ActiveSupport::Concern
Included in:
Variant, Variantref
Defined in:
lib/exodb/datamodel/varlocfield.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#chromosomeInteger

get the chromosome

Returns:

  • (Integer)

    chromosome



36
37
38
# File 'lib/exodb/datamodel/varlocfield.rb', line 36

def chromosome
	self[:location]['chr']
end

#convlocation=(loc) ⇒ Object

Assign location

Parameters:

  • location (String, Hash)

    string in chromosome:start..stop or chromosome:start-stop format



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/exodb/datamodel/varlocfield.rb', line 91

def convlocation=(loc)
	
	if loc.is_a?(String)
		
		begin
			self[:convlocation].push(parse_locstr(loc).delete_if {|k, v| ['start', 'stop'].include?(k)})
		rescue
			
		end
		
	end
	
end

#location=(loc) ⇒ Object

Assign location

Parameters:

  • location (String, Hash)

    string in chromosome:start..stop or chromosome:start-stop format



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/exodb/datamodel/varlocfield.rb', line 75

def location=(loc)
	
	if loc.is_a?(String)
		
		begin
			self[:location] = parse_locstr(loc).delete_if {|k, v| ['start', 'stop'].include?(k)}
		rescue
			
		end
		
	end
end

#location_str(assembly = nil) ⇒ String

Return location from specific genome assembly

Parameters:

  • assembly (String) (defaults to: nil)

    version

Returns:

  • (String)

    location string in chromosome:position



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/exodb/datamodel/varlocfield.rb', line 59

def location_str(assembly = nil)
	
	result = nil
	
	if assembly == nil || Exodb::ASSEMBLY[assembly] == self[:location]['assembly']
		result = "#{self[:location]['chr']}:#{self[:location]['position']}:#{self[:location]['assembly']}"
	else
		self[:convlocation].each {|e| result = "#{[e['chr'], e['position'], e['assembly']].join(':')}" if e['assembly'] == Exodb::ASSEMBLY[assembly]}
	end
	
	return result
end

#parse_locstr(loc_str) ⇒ Object

Assign gene location in format of chromosome_number:pos;build

Parameters:

  • gene (String)

    location in format of chromosome_number:start..stop



43
44
45
46
47
48
49
50
51
52
# File 'lib/exodb/datamodel/varlocfield.rb', line 43

def parse_locstr(loc_str)
	
	dat = loc_str.split(/:/)
	
	return {'chr' => dat[0],
		'position' => dat[1].to_i,
		'assembly' => dat[2] ? Exodb::ASSEMBLY.has_key?(dat[2]) ? Exodb::ASSEMBLY[dat[2]] : dat[2] : Exodb::DEFAULTASSEMBLY
	}
	
end