Exemple #1
0
def get_features_within_interval_patch(contig,
                                       beg,
                                       end,
                                       quicksect_obj,
                                       fname_corr=None):
    """
    Query a quicksect object for features overlapping
    the given interval on a chromosome
    """
    all_overlaps = []
    for feature_type, feature_quicksect in quicksect_obj.iteritems():
        if fname_corr:
            fname = fname_corr[feature_type]
        else:
            fname = feature_type
        overlaps = feature_quicksect.find(
            quicksect.Feature(beg, end, chr=contig))
        if not overlaps:
            continue
        for e in overlaps:
            all_overlaps.append(
                (fname, e.info["gene_id"], str(e.info["start"]),
                 str(e.info["end"]), e.info[fname + "_number"],
                 e.info["source"], e.info["strand"], e.info))
    return all_overlaps
Exemple #2
0
def make_composite(tr_list):
    if not tr_list:
        return 0, 0, 0
    features = []
    feature_sizes = {'cds': 0, '3utr': 0, '5utr': 0}
    starts, stops, strands, names = range(4)
    all_breaks = []
    for tr in tr_list:
        exon, cds, utr5, utr3 = make_transcript(tr, what='model')
        all_breaks.extend(cds[starts] + utr5[starts] + utr3[starts] +
                          cds[stops] + utr5[stops] + utr3[stops])
        #print cds, utr5, utr3
        #for (start, stop, strand, name) in zip(zip(*cds) + zip(*utr5) + zip(*utr3)):
        #interval = interval.insert(quicksect.Feature(start, stop, strand, name))
        try:
            features += [
                quicksect.Feature(start, stop - 1, strand, name)
                for (start, stop, strand,
                     name) in zip(*cds) + zip(*utr5) + zip(*utr3)
            ]
        except Exception, e:
            sys.stderr.write('Problem during packing @ {}: {}\n'.format(
                tr, str(e)))
            sys.stderr.write('exons: {}\n'.format(exon))
            sys.stderr.write('CDSs: {}\n'.format(cds))
            sys.stderr.write('5UTRs: {}\n'.format(utr5))
            sys.stderr.write('3UTRs: {}\n'.format(utr3))
Exemple #3
0
def get_features_within_interval(contig, beg, end, quicksect_obj):
    """
    Query a quicksect object for features overlapping
    the given interval on a chromosome
    """
    all_overlaps = []
    for feature_type, feature_quicksect in quicksect_obj.iteritems():
        overlaps = feature_quicksect.find(
            quicksect.Feature(beg, end, chr=contig))
        if not overlaps:
            continue
        for e in overlaps:
            all_overlaps.append(
                (feature_type, e.info["gene_id"], str(e.info["start"]),
                 str(e.info["end"]), e.info["source"], e.info["strand"],
                 e.info["attr"]))
    return all_overlaps
Exemple #4
0
def create_quicksect(loci, feature_types):
    """
    Create quicksect dictionary for looking up only exons from each single locus
    """
    quicksect_obj = {
        feature_type: quicksect.IntervalTree()
        for feature_type in feature_types
    }
    for locus in loci:
        for feature_type in feature_types:
            for feature in loci[locus].features[feature_type]:
                quicksect_obj[feature_type].insert(
                    quicksect.Feature(feature.iv.start,
                                      feature.iv.end - 1,
                                      chr=feature.iv.chrom,
                                      info=getInfo(feature)))
    return quicksect_obj
Exemple #5
0
def create_quicksect_patch(loci, feature_types):
    """
    Create quicksect dictionary for looking up only exons from each single locus
    """
    quicksect_obj = {
        feature_type: quicksect.IntervalTree()
        for feature_type in feature_types
    }
    for locus in loci:
        for feature_type in feature_types:
            for feature in loci[locus]['features'][feature_type]:
                quicksect_obj[feature_type].insert(
                    quicksect.Feature(feature['start'],
                                      feature['end'] - 1,
                                      chr=feature['chrom'],
                                      info=feature))
    return quicksect_obj