def genotype_details(genotype_id): """ Flask function to return genotype info, dashboard, etc. """ var_mgr = variant_manager(db="test",conn=g.conn) data = var_mgr.get_variant(genotype_id) if "EFF" in data["annotations"]: for ix, row in enumerate(data["annotations"]["EFF"]): data["annotations"]["EFF"][ix]["effect_code"] = VARIANT_EFFECTS[row["e"]] data["dashboard"] = {} data["dashboard"]["gatk"] = [] data["dashboard"]["gatk"].append({"title": "QUAL", "score": data["qual"]}) #data["dashboard"]["gatk"].append({"title": "DATA", "score": data["data"]}) data["dashboard"]["gatk"].append({"title": "FILTER", "score": "GATK_filter" in data["filter"]}) for name, value in data["annotations"].items(): if name in ["MQ", "DP", "AB"]: data["dashboard"]["gatk"].append({"title": name, "score": value}) if "dbNSFP" in data["annotations"]: data["dashboard"]["scores"] = [] for score_name, score_value in data["annotations"]["dbNSFP"].items(): print score_name, score_value data["dashboard"]["scores"].append({"title":score_name, "score": score_value}) data["dashboard"]["freq"] = [{"title": "ESP", "freqs": [{"pop":"AA", "freq": round(data["annotations"]["dbNSFP"].get("ESPaa", 0),3)}, {"pop":"EA", "freq": round(data["annotations"]["dbNSFP"].get("ESPea", 0),3)}]}, {"title": "1KG", "overallfreq": data["annotations"]["dbNSFP"].get("1gALLac", 0), "freqs": [{"pop":"AFR", "freq": data["annotations"]["dbNSFP"].get("1gAFRac",0)}, {"pop":"EUR", "freq": data["annotations"]["dbNSFP"].get("1gEURac",0)}, {"pop":"ASN", "freq": data["annotations"]["dbNSFP"].get("1gASNac",0)}, {"pop":"AMR", "freq": data["annotations"]["dbNSFP"].get("1gAMRac",0)}]}] return render_template("genotype_details.html", data=data)
def variants(): """ Flask function for variants home page. Various stats on the database are returned, not much else. A search box is provided as well. """ var_mgr = variant_manager(db="test",conn=g.conn) stats = var_mgr.get_db_stats() return render_template("variants.html", stats=stats)
def variant_details(chrom, start, end=None): """ Flask function to render the variant-level (not genotype) details Currently returns list of samples with this genotype. """ var_mgr = variant_manager(db="test",conn=g.conn) if end is None: genotype_data = var_mgr.get_variants_by_position(chrom, start) else: genotype_data = var_mgr.get_variants_by_position(chrom, start, end) variant_data = var_mgr.get_variant(genotype_data[0]["_id"]) for ix, row in enumerate(variant_data["annotations"]["EFF"]): variant_data["annotations"]["EFF"][ix]["effect_code"] = VARIANT_EFFECTS[row["e"]] return render_template("variant_details.html", variant_data=variant_data, genotype_data=genotype_data)
def __init__(self, db, conn): super(GaussQuery, self).__init__() self.db = db self.conn = conn self.var_mgr = variant_manager(db=self.db, conn=self.conn) self.filter_mgr = filter_manager(db=self.db, conn=self.conn) self.column_list = ["chrom", "start", "end", "sample_name", "id", "ref", "alt"] self.custom_column_list = [] self.projection = {k: True for k in self.column_list} #del self.projection["end"] # may not be necessary self.projection["filter"] = True # can add to column_list? self.projection["annotations.EFF"] = True # can add to column list? self.grouped = False self.skip = 0 self.limit = 1000 self.query = defaultdict(lambda: defaultdict(list))
def samples_info(sample_id): """ Flask function to return sample info page. Returns a summary of the number of variants in this sample, as well as the files attached to this sample and metadata. """ mgr = sample_manager(db="test",conn=g.conn) var_mgr = variant_manager(db="test",conn=g.conn) data = mgr.get_sample(sample_id = sample_id) effect_summary = var_mgr.get_sample_variant_summary(data["_id"]) for row in effect_summary: eff_code = row["_id"] eff_type = VARIANT_EFFECTS[eff_code] eff_rank = VARIANT_RANKS[eff_type] row["effect_str"] = Markup("<span class='label impact-tag %s'>%s</span>" % (eff_type, VARIANT_SHORTNAMES[eff_code])) row["effect_rank"] = eff_rank rank_sort = np.argsort(map(operator.itemgetter("effect_rank"), effect_summary)) data["variant_summary"] = [effect_summary[i] for i in rank_sort[::-1]] return render_template("sample_info.html", sample_id=sample_id, info=data)