Exemple #1
0
def seperate_parents_and_children(feature_db, parent_types_to_lift):
    c = feature_db.conn.cursor()
    relations = [
        list(feature) for feature in c.execute(
            '''SELECT * FROM relations join features as a on 
    a.id = relations.parent join features as b on b.id = relations.child''')
        if feature[0] != feature[1]
    ]
    all_ids = [
        list(feature)[0] for feature in c.execute('''SELECT * FROM features''')
    ]
    all_children_ids = [relation[1] for relation in relations]
    all_parent_ids = [relation[0] for relation in relations]
    lowest_children = np.setdiff1d(all_ids, all_parent_ids)
    highest_parents = np.setdiff1d(all_ids, all_children_ids)
    intermediates = set(all_children_ids).intersection(set(all_parent_ids))
    parent_dict, child_dict, intermediate_dict = {}, {}, {}
    add_parents(parent_dict, child_dict, highest_parents, parent_types_to_lift,
                feature_db)
    add_children(parent_dict, child_dict, lowest_children, feature_db)
    add_intermediates(intermediates, intermediate_dict, feature_db)
    parent_order = liftoff_utils.find_parent_order([
        parent for parent in list(parent_dict.values()) if parent is not None
    ])
    ref_feature_hierarchy = feature_hierarchy.feature_hierarchy(
        parent_dict, intermediate_dict, child_dict)
    return ref_feature_hierarchy, parent_order
def seperate_parents_and_children(feature_db, parent_types_to_lift):
    parent_dict, child_dict, intermediate_dict = {}, {}, {}
    feature_types = feature_db.featuretypes()
    parent_types, child_types, intermediate_types = find_feature_type_hierarchy(feature_types, feature_db)
    filtered_parents = [parent for parent in parent_types if parent in parent_types_to_lift]
    for parent_type in filtered_parents:
        for parent in feature_db.features_of_type(featuretype=parent_type):
            add_parent(parent_dict, parent, child_dict)
            add_children(child_types, parent, feature_db, child_dict)
    add_intermediates(intermediate_types, intermediate_dict, feature_db)
    parent_order = liftoff_utils.find_parent_order(
        [parent for parent in list(parent_dict.values()) if parent is not None])
    ref_feature_hierarchy = feature_hierarchy.feature_hierarchy(parent_dict, intermediate_dict, child_dict)
    return ref_feature_hierarchy, parent_order
def check_homologues(all_lifted_features, lifted_features_to_check,
                     parent_dict, ref_parent_order, inter):
    all_feature_list = liftoff_utils.get_parent_list(all_lifted_features)
    features_to_check_list = liftoff_utils.get_parent_list(
        lifted_features_to_check)
    target_parent_order = liftoff_utils.find_parent_order(all_feature_list)
    remap_features = {}
    if inter == None:
        inter = build_interval_list(all_feature_list)
    for feature in features_to_check_list:
        overlaps = find_overlaps(feature.start, feature.end, feature.seqid,
                                 feature.strand,
                                 feature.attributes["copy_id"][0], inter)
        for overlap in overlaps:
            feature_to_compare = overlap[2][1]
            compare_overlapping_feature(feature_to_compare, parent_dict,
                                        feature, remap_features,
                                        ref_parent_order, target_parent_order)
    return remap_features
def check_homologues(all_lifted_features, lifted_features_to_check,
                     parent_dict, ref_parent_order, max_overlap):
    all_feature_list = liftoff_utils.get_parent_list(all_lifted_features)
    features_to_check_list = liftoff_utils.get_parent_list(
        lifted_features_to_check)
    target_parent_order = liftoff_utils.find_parent_order(all_feature_list)
    remap_features = set()
    feature_locations = build_interval_list(all_feature_list)
    for feature in features_to_check_list:
        overlaps = liftoff_utils.find_overlaps(
            feature.start - 1, feature.end - 1, feature.seqid, feature.strand,
            feature.attributes["copy_id"][0], feature_locations, parent_dict,
            all_lifted_features, max_overlap)
        for overlap in overlaps:
            if overlap[2][0] != feature.attributes["copy_id"][0]:
                feature_to_compare = overlap[2][1]
                compare_overlapping_feature(feature_to_compare, feature,
                                            remap_features, ref_parent_order,
                                            target_parent_order)
    return remap_features, feature_locations
def check_homologues(all_lifted_features, lifted_features_to_check,
                     parent_dict, original_parent_order):
    all_feature_list = liftoff_utils.get_parent_list(all_lifted_features,
                                                     parent_dict)
    features_to_check_list = liftoff_utils.get_parent_list(
        lifted_features_to_check, parent_dict)
    all_feature_list.sort(key=lambda x: (x.seqid, x.start))
    new_parent_order = liftoff_utils.find_parent_order(all_feature_list)
    chrom_index_dict = {}
    feature_index = 0
    for feature in all_feature_list:
        if feature.seqid not in chrom_index_dict:
            chrom_index_dict[feature.seqid] = feature_index
        feature_index += 1
    remap_features = {}
    for feature in features_to_check_list:
        nearby_features = all_feature_list[chrom_index_dict[feature.seqid]:]
        compare_nearby_features(nearby_features, parent_dict, feature,
                                remap_features, original_parent_order,
                                new_parent_order)
    return remap_features