Example #1
0
class SearchGridT(DataGrid):
    #    fields = [("User","get_username"),("Cell Type", lambda obj:genshi.Markup(obj.sample_cell_type)),
    #        ("Species",lambda obj:genshi.Markup(obj.sample_species)),
    #         ("Ab target", lambda obj:genshi.Markup(obj.sample_ab_target)),("Bio bg",lambda obj:genshi.Markup(obj.sample_bio_bg)),
    #        ("Type",lambda obj:genshi.Markup(obj.sample_type)),("DataType",lambda obj:genshi.Markup(obj.measurement_type)),
    #        ("Description",lambda obj:genshi.Markup(obj.description)),
    #        ("Action", lambda obj:genshi.Markup(
    #        get_info_link(obj.id,obj.description)
    #        +get_dl_link(obj.id)
    #        +get_UCSC_link(obj.id)
    #        +get_GDV_link(obj.id)
    #        +get_SPAN_id(obj.id)
    #    ))]
    # -----------------------------   old version           ---------------
    # fields = [("User", "get_username"),
    #     ("Samples", lambda obj:genshi.Markup(obj.samples_display)), ("Type", lambda obj:genshi.Markup(obj.sample_type)),
    #     ("Cell Type", lambda obj:genshi.Markup(obj.sample_cell_type)), ("Target", lambda obj:genshi.Markup(obj.sample_ab_target)),
    #     ("Bio bg", lambda obj:genshi.Markup(obj.sample_bio_bg)), ("Stage", lambda obj:genshi.Markup(obj.sample_stage)),
    #     ("Measurements", "name"), ("Assembly", "assembly"),
    #     ("DataType", lambda obj:genshi.Markup(obj.measurement_type)), ("Date", "created"), ("Final", lambda obj:genshi.Markup(obj.flag_final_type)),
    #     ("Description", lambda obj:genshi.Markup(obj.description)),
    #     ("Action", lambda obj:genshi.Markup(
    #         get_info_link(obj.id, obj.description)
    #         + get_dl_link(obj.id)
    #         + get_UCSC_link(obj.id)
    #         + get_GDV_link(obj.id)
    #         + get_SPAN_id(obj.id)
    #     ))]

    fields = [
        ("User", "get_username"),
        ("Samples", lambda obj: genshi.Markup(obj.samples_display)),
        ("Type", lambda obj: genshi.Markup(obj.sample_type)),
        ("Measurements", "name"),
        ("DataType", lambda obj: genshi.Markup(obj.measurement_type)),
        ("Date", "created"),
        ("Action", lambda obj: genshi.Markup(
            get_info_link(obj.id, obj.description) + get_dl_link(obj.id) +
            get_UCSC_link(obj.id) + get_GDV_link(obj.id) + get_SPAN_id(obj.id))
         )
    ]
Example #2
0
File: util.py Project: bbcf/biorepo
    def to_json_test(self):
        static_fields = {
                'Description': self.meas.description,
                'User': self.get_name(),
                'Measurements': self.get_meas_name(),
                'description': self.meas.description,
                'Created': self.date.strftime(date_format),
                'Samples': ' ; '.join(['%s' % (sample.name) for sample in self.samples]),
                'Projects': self.get_projects(),
                'Type': self.get_sample_type(),
                'DataType': self.get_measurement_type(),
                'scroll_info': genshi.Markup(self.get_img_scroll()),
                'Attachment': self.get_extension,
                'Actions': get_info_link(self.id) + get_dl_link(self.id) + get_public_link(self.id) + get_UCSC_link(self.id) + get_GViz_link(self.id) + get_SPAN_id(self.id)
            }
        #find None statics fields to change the display in datatables
        for sf in static_fields.keys():
            if static_fields[sf] is None or static_fields[sf] == "":
                static_fields[sf] = None

        dyn_in_searchgrid = session.get("search_grid_fields", [])
        labo = session.get("current_lab")
        for d in dyn_in_searchgrid:
            new = d.replace("_", " ")
            dyn_in_searchgrid.remove(d)
            dyn_in_searchgrid.append(new)
        meas_dynamic_fields = {}
        samples_dynamic_fields = {}
        attributs_meas = [a.to_json() for a in self.meas.attributs if not a.deprecated]
        list_avalues_meas = self.meas.a_values

        for avm in list_avalues_meas:
            for am in attributs_meas:
                key = am["key"].replace("_", " ")
                if str(am["id"]) == str(avm.attribut_id):
                    if am["widget"] != "checkbox" and am["widget"] != "hiding_checkbox":
                        meas_dynamic_fields[key] = avm.value
                    else:
                        if check_boolean(avm.value):
                            meas_dynamic_fields[key] = key
                        else:
                            meas_dynamic_fields[key] = "NOT " + str(key)

        attributs_samples = self.get_attributs_samples_json()
        if len(self.samples) < 2:
            for s in self.samples:
                list_avalues_samples = s.a_values
                for avs in list_avalues_samples:
                    for a_s in attributs_samples:
                        key = a_s["key"].replace("_", " ")
                        if str(a_s["id"]) == str(avs.attribut_id):
                            if a_s["widget"] != "checkbox" and a_s["widget"] != "hiding_checkbox":
                                samples_dynamic_fields[key] = avs.value
                            else:
                                if check_boolean(avs.value):
                                    samples_dynamic_fields[key] = key
                                else:
                                    samples_dynamic_fields[key] = "NOT " + str(key)
        else:
            for s in self.samples:
                list_avalues_samples = s.a_values
                for avs in list_avalues_samples:
                    for a_s in attributs_samples:
                        key = a_s["key"].replace("_", " ")
                        if str(a_s["id"]) == str(avs.attribut_id):
                            if a_s["widget"] != "checkbox" and a_s["widget"] != "hiding_checkbox":
                                if key not in samples_dynamic_fields.keys():
                                    samples_dynamic_fields[key] = [avs.value]
                                else:
                                    if avs.value not in samples_dynamic_fields[key]:
                                        samples_dynamic_fields[key].append(avs.value)
                            else:
                                if check_boolean(avs.value):
                                    if key not in samples_dynamic_fields.keys():
                                        samples_dynamic_fields[key] = [key]
                                    else:
                                        samples_dynamic_fields[key].append(key)
                                else:
                                    if key not in samples_dynamic_fields.keys():
                                        samples_dynamic_fields[key] = ["NOT " + str(key)]
                                    else:
                                        samples_dynamic_fields[key].append("NOT " + str(key))
            for k in samples_dynamic_fields.keys():
                samples_dynamic_fields[k] = " ; ".join(samples_dynamic_fields[k])

        #Sorting dynamic fields with conf file to display in searchgrid
        dyn_fields = {}
        for k in samples_dynamic_fields:
            if k in dyn_in_searchgrid:
                dyn_fields[k.capitalize()] = samples_dynamic_fields[k]
        for key in meas_dynamic_fields:
            if key in dyn_in_searchgrid:
                dyn_fields[key.capitalize()] = meas_dynamic_fields[key]
        #for the empty fields
        for k in dyn_in_searchgrid:
            if k.capitalize() not in dyn_fields.keys():
                k_db = k.replace(" ", "_")
                lab = DBSession.query(Labs).filter(Labs.name == labo).first()
                lab_id = lab.id
                k_obj = DBSession.query(Attributs).filter(and_(Attributs.key == k_db, Attributs.lab_id == lab_id)).first()
                if k_obj.widget != "checkbox" and k_obj.widget != "hiding_checkbox":
                    dyn_fields[k.capitalize()] = None
                else:
                    dyn_fields[k.capitalize()] = ["NOT " + str(k)]

        final = dict(static_fields.items() + dyn_fields.items())
        return final
Example #3
0
def build_search_grid(measurements):
    search_grid = BootstrapGrid()
    #static end
    end_fields = [('Attachment', lambda obj: genshi.Markup(obj.get_extension)),
                  ('Description', "description"), ("Date", "created"),
                  ("Action", lambda obj: genshi.Markup(
                      get_info_link(obj.id) + get_dl_link(obj.id) +
                      get_public_link(obj.id) + get_UCSC_link(obj.id) +
                      get_GViz_link(obj.id) + get_SPAN_id(obj.id)))]
    #static and dynamic fields
    fields = []
    fields_static = [("", "scroll_info"), ("User", "user"), ("Projects", lambda obj:genshi.Markup(obj.projects_display)), ("Samples", lambda obj:genshi.Markup(
        obj.samples_display)), ("Type", lambda obj:genshi.Markup(obj.sample_type)),\
        ("Measurements", lambda obj:genshi.Markup(obj.name)), ("DataType", lambda obj:genshi.Markup(obj.measurement_type))]
    fields_dyn = []
    list_searchable = []
    positions_not_searchable = []
    hidden_list = []
    lab_id = None
    if not isinstance(measurements, list):
        measurements = [measurements]
    if len(measurements) > 0:
        meas = measurements[0]
        #dyn meas
        for att in meas.attributs:
            #get the lab_id
            lab_id = att.lab_id
            vals = lambda obj, a=att: obj.get_values_from_attributs_meas(a)
            fields_dyn.append((att.key, vals))
            if att.searchable == True:
                list_searchable.append(att.key)
        #dyn sample
        if len(meas.samples) > 0:
            sample = (meas.samples)[0]
            for att in sample.attributs:
                val = lambda obj, a=att: obj.get_values_from_attributs_sample(a
                                                                              )
                fields_dyn.append((att.key, val))
                if att.searchable == True:
                    list_searchable.append(att.key)
    ############## CUSTOMIZE THE SEARCH GRID BY LAB #######################
    #/!\ the grid begins at 0
    #to customize hidden fields by lab
    lab = DBSession.query(Labs).filter(Labs.id == lab_id).first()
    movable_fields = fields_static + fields_dyn
    if lab:
        if lab.name == "ptbb":
            pass
        elif lab.name == "updub":
            pass
        elif lab.name == "lvg":
            #move some field in the grid
            for f in movable_fields:
                if f[0] == "flag_final":
                    new_list = value_travel_into_da_list(
                        movable_fields, movable_fields.index(f),
                        len(movable_fields))
                    movable_fields = new_list
            for f in movable_fields:
                if f[0] == "quality":
                    new_list = value_travel_into_da_list(
                        movable_fields, movable_fields.index(f),
                        len(movable_fields))
                    movable_fields = new_list

            #hide Samples name
            for f in movable_fields:
                if f[0] == "Samples":
                    i = movable_fields.index(f)
                    hidden_list.append(i)
            for f in movable_fields:
                if f[0] == "ab_source":
                    i = movable_fields.index(f)
                    hidden_list.append(i)
        elif lab.name == "upnae":
            fields_to_hide = ["replica_id", "drug_dose", "lane_id", "paired_end_id", "strand",\
            "source", "machine", "starting_material", "treatment", "paired_end", "polya", "strand_specific",\
            "viewpoint", "protein_bait", "technical_replica_id", "feeding_type", "light_condition"]
            for f in movable_fields:
                if f[0] in fields_to_hide:
                    i = movable_fields.index(f)
                    hidden_list.append(i)
        elif lab.name == "stutz":
            fields_to_hide = ["article_title", "strain", "time_point", "antibody", "treatment_time",\
             "phase", "medium", "background"]
            for f in movable_fields:
                if f[0] in fields_to_hide:
                    i = movable_fields.index(f)
                    hidden_list.append(i)
        elif lab.name == "shore":
            fields_to_hide = [
                "article_title", "year", "time_point", "sequencing_method",
                "treatment_time", "phase"
            ]
            for f in movable_fields:
                if f[0] in fields_to_hide:
                    i = movable_fields.index(f)
                    hidden_list.append(i)

    #addition with the 3 common end-fields
    fields = movable_fields + end_fields
    #build the list (positions_not_searchable) to send to the js for the searchable buttons
    for f in fields:
        search_grid.fields.append(f)
    for i, item in enumerate(search_grid.fields):
        if item[0] not in list_searchable:
            positions_not_searchable.append(i)

    for f in fields_static:
        for i, item in enumerate(movable_fields):
            #and i not in list_tmp
            if f[0] == item[0] and f[
                    0] != '' and f in fields_static and i in positions_not_searchable:
                positions_not_searchable.remove(i)

    #build the list (ignored_list) for the ignored fields
    total = len(search_grid.fields) - 1
    hidden_list.append(total - 2)

    #positions_not_searchable = delete the search button of the field
    #hidden_list = the field does not appear anymore into the searchgrid and its search button disappears BUT it is still searchable !
    return search_grid, hidden_list, positions_not_searchable
Example #4
0
def build_search_grid(measurements):
    search_grid = BootstrapGrid()
    #static end
    end_fields = [('Attachment', lambda obj: genshi.Markup(obj.get_extension)), ('Description', "description"), ("Date", "created"), ("Action", lambda obj: genshi.Markup(
        get_info_link(obj.id)
        + get_dl_link(obj.id)
        + get_public_link(obj.id)
        + get_UCSC_link(obj.id)
        + get_GViz_link(obj.id)
        + get_SPAN_id(obj.id)
    ))]
    #static and dynamic fields
    fields = []
    fields_static = [("", "scroll_info"), ("User", "user"), ("Projects", lambda obj:genshi.Markup(obj.projects_display)), ("Samples", lambda obj:genshi.Markup(
        obj.samples_display)), ("Type", lambda obj:genshi.Markup(obj.sample_type)),\
        ("Measurements", lambda obj:genshi.Markup(obj.name)), ("DataType", lambda obj:genshi.Markup(obj.measurement_type))]
    fields_dyn = []
    list_searchable = []
    positions_not_searchable = []
    hidden_list = []
    lab_id = None
    if not isinstance(measurements, list):
        measurements = [measurements]
    if len(measurements) > 0:
        meas = measurements[0]
        #dyn meas
        for att in meas.attributs:
            #get the lab_id
            lab_id = att.lab_id
            vals = lambda obj, a=att: obj.get_values_from_attributs_meas(a)
            fields_dyn.append((att.key, vals))
            if att.searchable == True:
                list_searchable.append(att.key)
        #dyn sample
        if len(meas.samples) > 0:
            sample = (meas.samples)[0]
            for att in sample.attributs:
                val = lambda obj, a=att: obj.get_values_from_attributs_sample(a)
                fields_dyn.append((att.key, val))
                if att.searchable == True:
                    list_searchable.append(att.key)
    ############## CUSTOMIZE THE SEARCH GRID BY LAB #######################
    #/!\ the grid begins at 0
    #to customize hidden fields by lab
    lab = DBSession.query(Labs).filter(Labs.id == lab_id).first()
    movable_fields = fields_static + fields_dyn
    if lab:
        if lab.name == "ptbb":
            pass
        elif lab.name == "updub":
            pass
        elif lab.name == "lvg":
            #move some field in the grid
            for f in movable_fields:
                if f[0] == "flag_final":
                    new_list = value_travel_into_da_list(movable_fields, movable_fields.index(f), len(movable_fields))
                    movable_fields = new_list
            for f in movable_fields:
                if f[0] == "quality":
                    new_list = value_travel_into_da_list(movable_fields, movable_fields.index(f), len(movable_fields))
                    movable_fields = new_list

            #hide Samples name
            for f in movable_fields:
                if f[0] == "Samples":
                    i = movable_fields.index(f)
                    hidden_list.append(i)
            for f in movable_fields:
                if f[0] == "ab_source":
                    i = movable_fields.index(f)
                    hidden_list.append(i)
        elif lab.name == "upnae":
            fields_to_hide = ["replica_id", "drug_dose", "lane_id", "paired_end_id", "strand",\
            "source", "machine", "starting_material", "treatment", "paired_end", "polya", "strand_specific",\
            "viewpoint", "protein_bait", "technical_replica_id", "feeding_type", "light_condition"]
            for f in movable_fields:
                if f[0] in fields_to_hide:
                    i = movable_fields.index(f)
                    hidden_list.append(i)
        elif lab.name == "stutz":
            fields_to_hide = ["article_title", "strain", "time_point", "antibody", "treatment_time",\
             "phase", "medium", "background"]
            for f in movable_fields:
                if f[0] in fields_to_hide:
                    i = movable_fields.index(f)
                    hidden_list.append(i)
        elif lab.name == "shore":
            fields_to_hide = ["article_title", "year", "time_point", "sequencing_method", "treatment_time", "phase"]
            for f in movable_fields:
                if f[0] in fields_to_hide:
                    i = movable_fields.index(f)
                    hidden_list.append(i)

    #addition with the 3 common end-fields
    fields = movable_fields + end_fields
    #build the list (positions_not_searchable) to send to the js for the searchable buttons
    for f in fields:
        search_grid.fields.append(f)
    for i, item in enumerate(search_grid.fields):
        if item[0] not in list_searchable:
            positions_not_searchable.append(i)

    for f in fields_static:
        for i, item in enumerate(movable_fields):
            #and i not in list_tmp
            if f[0] == item[0] and f[0] != '' and f in fields_static and i in positions_not_searchable:
                positions_not_searchable.remove(i)

    #build the list (ignored_list) for the ignored fields
    total = len(search_grid.fields) - 1
    hidden_list.append(total - 2)

    #positions_not_searchable = delete the search button of the field
    #hidden_list = the field does not appear anymore into the searchgrid and its search button disappears BUT it is still searchable !
    return search_grid, hidden_list, positions_not_searchable
Example #5
0
File: util.py Project: bbcf/biorepo
    def to_json_test(self):
        static_fields = {
            'Description':
            self.meas.description,
            'User':
            self.get_name(),
            'Measurements':
            self.get_meas_name(),
            'description':
            self.meas.description,
            'Created':
            self.date.strftime(date_format),
            'Samples':
            ' ; '.join(['%s' % (sample.name) for sample in self.samples]),
            'Projects':
            self.get_projects(),
            'Type':
            self.get_sample_type(),
            'DataType':
            self.get_measurement_type(),
            'scroll_info':
            genshi.Markup(self.get_img_scroll()),
            'Attachment':
            self.get_extension,
            'Actions':
            get_info_link(self.id) + get_dl_link(self.id) +
            get_public_link(self.id) + get_UCSC_link(self.id) +
            get_GViz_link(self.id) + get_SPAN_id(self.id)
        }
        #find None statics fields to change the display in datatables
        for sf in static_fields.keys():
            if static_fields[sf] is None or static_fields[sf] == "":
                static_fields[sf] = None

        dyn_in_searchgrid = session.get("search_grid_fields", [])
        labo = session.get("current_lab")
        for d in dyn_in_searchgrid:
            new = d.replace("_", " ")
            dyn_in_searchgrid.remove(d)
            dyn_in_searchgrid.append(new)
        meas_dynamic_fields = {}
        samples_dynamic_fields = {}
        attributs_meas = [
            a.to_json() for a in self.meas.attributs if not a.deprecated
        ]
        list_avalues_meas = self.meas.a_values

        for avm in list_avalues_meas:
            for am in attributs_meas:
                key = am["key"].replace("_", " ")
                if str(am["id"]) == str(avm.attribut_id):
                    if am["widget"] != "checkbox" and am[
                            "widget"] != "hiding_checkbox":
                        meas_dynamic_fields[key] = avm.value
                    else:
                        if check_boolean(avm.value):
                            meas_dynamic_fields[key] = key
                        else:
                            meas_dynamic_fields[key] = "NOT " + str(key)

        attributs_samples = self.get_attributs_samples_json()
        if len(self.samples) < 2:
            for s in self.samples:
                list_avalues_samples = s.a_values
                for avs in list_avalues_samples:
                    for a_s in attributs_samples:
                        key = a_s["key"].replace("_", " ")
                        if str(a_s["id"]) == str(avs.attribut_id):
                            if a_s["widget"] != "checkbox" and a_s[
                                    "widget"] != "hiding_checkbox":
                                samples_dynamic_fields[key] = avs.value
                            else:
                                if check_boolean(avs.value):
                                    samples_dynamic_fields[key] = key
                                else:
                                    samples_dynamic_fields[key] = "NOT " + str(
                                        key)
        else:
            for s in self.samples:
                list_avalues_samples = s.a_values
                for avs in list_avalues_samples:
                    for a_s in attributs_samples:
                        key = a_s["key"].replace("_", " ")
                        if str(a_s["id"]) == str(avs.attribut_id):
                            if a_s["widget"] != "checkbox" and a_s[
                                    "widget"] != "hiding_checkbox":
                                if key not in samples_dynamic_fields.keys():
                                    samples_dynamic_fields[key] = [avs.value]
                                else:
                                    if avs.value not in samples_dynamic_fields[
                                            key]:
                                        samples_dynamic_fields[key].append(
                                            avs.value)
                            else:
                                if check_boolean(avs.value):
                                    if key not in samples_dynamic_fields.keys(
                                    ):
                                        samples_dynamic_fields[key] = [key]
                                    else:
                                        samples_dynamic_fields[key].append(key)
                                else:
                                    if key not in samples_dynamic_fields.keys(
                                    ):
                                        samples_dynamic_fields[key] = [
                                            "NOT " + str(key)
                                        ]
                                    else:
                                        samples_dynamic_fields[key].append(
                                            "NOT " + str(key))
            for k in samples_dynamic_fields.keys():
                samples_dynamic_fields[k] = " ; ".join(
                    samples_dynamic_fields[k])

        #Sorting dynamic fields with conf file to display in searchgrid
        dyn_fields = {}
        for k in samples_dynamic_fields:
            if k in dyn_in_searchgrid:
                dyn_fields[k.capitalize()] = samples_dynamic_fields[k]
        for key in meas_dynamic_fields:
            if key in dyn_in_searchgrid:
                dyn_fields[key.capitalize()] = meas_dynamic_fields[key]
        #for the empty fields
        for k in dyn_in_searchgrid:
            if k.capitalize() not in dyn_fields.keys():
                k_db = k.replace(" ", "_")
                lab = DBSession.query(Labs).filter(Labs.name == labo).first()
                lab_id = lab.id
                k_obj = DBSession.query(Attributs).filter(
                    and_(Attributs.key == k_db,
                         Attributs.lab_id == lab_id)).first()
                if k_obj.widget != "checkbox" and k_obj.widget != "hiding_checkbox":
                    dyn_fields[k.capitalize()] = None
                else:
                    dyn_fields[k.capitalize()] = ["NOT " + str(k)]

        final = dict(static_fields.items() + dyn_fields.items())
        return final