Ejemplo n.º 1
0
def compare_nearby_features(nearby_features, parent_list, feature, remap_features, original_parent_order, new_parent_order):
    for nearby_feature in nearby_features:
        if nearby_feature.attributes["copy_id"][0] != feature.attributes["copy_id"][0] and feature.strand == nearby_feature.strand:
            if nearby_feature.seqid != feature.seqid or nearby_feature.start > feature.end:
                break
            if nearby_feature.end < feature.start:
                continue
            else:
                original_nearby_feature, original_feature = parent_list[nearby_feature.id], parent_list[feature.id]
                if original_nearby_feature.seqid != original_feature.seqid or original_nearby_feature.strand != original_feature.strand or original_nearby_feature.id == original_feature.id:
                    original_overlap = -1
                else:
                    original_overlap = liftoff_utils.count_overlap(original_feature.start, original_feature.end,
                                                                   original_nearby_feature.start,
                                                                   original_nearby_feature.end)
                lifted_overlap = liftoff_utils.count_overlap(feature.start, feature.end, nearby_feature.start,
                                                             nearby_feature.end)

                if lifted_overlap >0 and original_overlap <= 0:
                    if feature.attributes["copy_id"][0] in remap_features:
                        feature_to_remap, feature_to_keep = feature, nearby_feature
                    elif nearby_feature.attributes["copy_id"][0] in remap_features:
                        feature_to_remap, feature_to_keep = nearby_feature, feature

                    else:
                        feature_to_remap, feature_to_keep = find_feature_to_remap(feature, nearby_feature,
                                                                              original_parent_order, new_parent_order)

                    remap_features[feature_to_remap.attributes["copy_id"][0]]=[feature_to_keep.start - 1,
                                                                                      feature_to_keep.end - 1,
                                                                                      feature_to_keep.seqid,
                                                                                      feature_to_keep.strand]
    return remap_features
Ejemplo n.º 2
0
def contains_child(aln, children_coords, parent):
    for child_interval in children_coords:
        relative_start = liftoff_utils.get_relative_child_coord(parent, child_interval[0], aln.is_reverse)
        relative_end = liftoff_utils.get_relative_child_coord(parent, child_interval[1], aln.is_reverse)
        child_start, child_end = min(relative_start, relative_end), max(relative_start, relative_end)
        overlap = liftoff_utils.count_overlap(child_start, child_end, aln.query_block_start, aln.query_block_end)
        if overlap > 0:
            return True
    return False
Ejemplo n.º 3
0
def find_overlapping_features(overlapping_features, feature_list):
    for feature in feature_list:
        if feature.strand == overlapping_features[
                3] and feature.seqid == overlapping_features[2]:
            if liftoff_utils.count_overlap(feature.start, feature.end,
                                           overlapping_features[0],
                                           overlapping_features[1]) > 0:
                return True
    return False
Ejemplo n.º 4
0
def spans_overlap_region(from_node, to_node, coords_to_exclude, parent):
    target_chrm = from_node.reference_name
    strand = get_strand(from_node, parent)
    for coords in coords_to_exclude:
        if strand == coords[3] and target_chrm == coords[2]:
            if liftoff_utils.count_overlap(coords[0], coords[1],
                                           from_node.reference_block_end,
                                           to_node.reference_block_start) > 0:
                return True
    return False
Ejemplo n.º 5
0
def get_edge_weight(from_node, to_node, children_coords, parent):
    unaligned_range = [
        from_node.query_block_end + 1, to_node.query_block_start - 1
    ]
    unaligned_exon_bases = 0
    for child_interval in children_coords:
        if from_node.reference_name == "start":
            is_reverse = to_node.is_reverse
        else:
            is_reverse = from_node.is_reverse
        relative_start = liftoff_utils.get_relative_child_coord(
            parent, child_interval[0], is_reverse)
        relative_end = liftoff_utils.get_relative_child_coord(
            parent, child_interval[1], is_reverse)
        child_start, child_end = min(relative_start, relative_end), max(
            relative_start, relative_end)
        overlap = liftoff_utils.count_overlap(child_start, child_end,
                                              unaligned_range[0],
                                              unaligned_range[1])
        if overlap == 1 and unaligned_range[0] == unaligned_range[1]:
            unaligned_exon_bases += to_node.reference_block_start - from_node.reference_block_end + 1
        else:
            unaligned_exon_bases += max(0, overlap)
    return unaligned_exon_bases + 1