diff options
author | Zachary Sloan | 2013-01-08 17:16:45 -0600 |
---|---|---|
committer | Zachary Sloan | 2013-01-08 17:16:45 -0600 |
commit | 34b0cc3a931e266b6382c961d6321ccc9b3ac430 (patch) | |
tree | 876b9b076b01c9448190c739333ab061cec15611 /wqflask/base | |
parent | c8a4719a83e3ee65a8c03b0b600a3cfea9ff17bf (diff) | |
download | genenetwork2-34b0cc3a931e266b6382c961d6321ccc9b3ac430.tar.gz |
Created IndChromosome class in species.py and wrote functions for
chromosome-related attributes
Began to try and pass qtlreaper results as js_data to use when
drawing graphs
Diffstat (limited to 'wqflask/base')
-rw-r--r-- | wqflask/base/species.py | 83 |
1 files changed, 67 insertions, 16 deletions
diff --git a/wqflask/base/species.py b/wqflask/base/species.py index 85f076ca..9d4cac4c 100644 --- a/wqflask/base/species.py +++ b/wqflask/base/species.py @@ -6,14 +6,17 @@ from flask import Flask, g #from MySQLdb import escape_string as escape +from utility import Bunch + from pprint import pformat as pf class TheSpecies(object): def __init__(self, dataset): self.dataset = dataset print("self.dataset is:", pf(self.dataset.__dict__)) - self.chromosomes = Chromosomes(self.dataset.group.name) - self.genome_length = self.chromosomes.get_genome_length() + self.chromosomes = Chromosomes(self.dataset) + self.genome_mb_length = self.chromosomes.get_genome_mb_length() + #@property #def chromosomes(self): @@ -27,10 +30,22 @@ class TheSpecies(object): # # return chromosomes +class IndChromosome(object): + def __init__(self, length): + self.length = length + + @property + def mb_length(self): + """Chromosome length in megabases""" + return self.length / 1000000 + + def set_cm_length(self, genofile_chr): + self.cm_length = genofile_chr[-1].cM - genofile_chr[0].cM class Chromosomes(object): - def __init__(self, group_name): + def __init__(self, dataset): + self.dataset = dataset self.chromosomes = collections.OrderedDict() results = g.db.execute(""" @@ -40,27 +55,63 @@ class Chromosomes(object): Chr_Length.SpeciesId = InbredSet.SpeciesId AND InbredSet.Name = %s Order by OrderId - """, group_name).fetchall() + """, self.dataset.group.name).fetchall() print("bike:", results) for item in results: - self.chromosomes[item.Name] = item.Length + self.chromosomes[item.Name] = IndChromosome(item.Length) + + self.set_mb_graph_interval() + self.get_cm_length_list() + + + def set_mb_graph_interval(self): + """Empirical megabase interval""" + + #if self.chromosomes: + assert self.chromosomes, "Have to add some code back in apparently to set it to 1" + self.mb_graph_interval = self.get_genome_mb_length()/(len(self.chromosomes)*12) + #else: + #self.mb_graph_interval = 1 - print("self.chromosomes:", self.chromosomes) + def get_genome_mb_length(self): + """Gets the sum of each chromosome's length in megabases""" - def get_mb_length(self): - """Gets the chromosome length in megabases""" + return sum([ind_chromosome.mb_length for ind_chromosome in self.chromosomes.values()]) - mb_lengths = chr_length/1000000.0 for name, chr_length in self.chromosomes - return mb_lengths + def get_genome_cm_length(self): + """Gets the sum of each chromosome's length in centimorgans""" - def get_genome_length(self): - """Gets the sum of each chromosome's length""" + return sum([ind_chromosome.cm_length for ind_chromosome in self.chromosomes.values()]) - genome_length = 0 - for name, value in self.chromosomes.items(): - genome_length += value + def get_cm_length_list(self): + """Chromosome length in centimorgans + + Calculates the length in centimorgans by subtracting the centimorgan position + of the last marker in a chromosome by the position of the first marker + + """ + + self.dataset.group.read_genotype_file() + + self.cm_length_list = [] + + for chromosome in self.dataset.group.genotype: + self.cm_length_list.append(chromosome[-1].cM - chromosome[0].cM) + + print("self.cm_length_list:", pf(self.cm_length_list)) + + assert len(self.cm_length_list) == len(self.chromosomes), "Uh-oh lengths should be equal!" + for counter, chromosome in enumerate(self.chromosomes.values()): + chromosome.cm_length = self.cm_length_list[counter] + #self.chromosomes[counter].cm_length = item + + for key, value in self.chromosomes.items(): + print("bread - %s: %s" % (key, pf(vars(value)))) + - return genome_length
\ No newline at end of file +# Testing +#if __name__ == '__main__': +# foo = dict(bar=dict(length))
\ No newline at end of file |