Esempio n. 1
0
def get_edge_weight(from_node, to_node, children_coords, parent, args):
    node_overlap = get_node_overlap(from_node, to_node)
    unaligned_range = [
        from_node.query_block_end + 1,
        to_node.query_block_start + node_overlap - 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, min(unaligned_range[0],
                                        unaligned_range[1]),
            max(unaligned_range[0], unaligned_range[1]))
        if overlap == 1 and unaligned_range[0] == unaligned_range[1] + 1 and from_node.reference_name == \
                to_node.reference_name:
            unaligned_exon_bases += ((to_node.reference_block_start + node_overlap) - from_node.reference_block_end \
                                     - 1) * args.gap_extend
        else:
            unaligned_exon_bases += max(0, overlap) * args.gap_extend
    if unaligned_exon_bases > 0:
        unaligned_exon_bases += (args.gap_open - args.gap_extend
                                 )  # gap open penalty
    return unaligned_exon_bases
Esempio 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
Esempio n. 3
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.strand and target_chrm == coords.seqid:
            if liftoff_utils.count_overlap(coords.start-1, coords.end-1, from_node.reference_block_end,
                                           to_node.reference_block_start) > 0:
                return True
    return False
Esempio n. 4
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
Esempio n. 5
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
def overlaps_in_ref_annotation(ref_feature1, ref_feature2):
    if ref_feature1.seqid != ref_feature2.seqid:
        return False
    if ref_feature1.strand != ref_feature2.strand:
        return False
    if ref_feature1.id == ref_feature2.id:
        return False
    else:
        return liftoff_utils.count_overlap(
            ref_feature1.start, ref_feature1.end, ref_feature2.start,
            ref_feature2.end) > 0
Esempio n. 7
0
def find_overlapping_children(aln, children_coords, parent):
    overlapping_children = []
    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:
            overlapping_children.append(child_start)
            overlapping_children.append(child_end)
    return overlapping_children
Esempio n. 8
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