Esempio n. 1
0
def build_table(args, handle, counts):
    references = collect_references(args, handle)

    table = {}
    for (key, readgroup) in collect_readgroups(args, handle).iteritems():
        sample = readgroup["SM"]
        library = readgroup["LB"]

        # Exclude counts for reads with no read-groups, if none such were seen
        if key is None and not args.ignore_readgroups:
            for reference in references:
                subtable = counts.get(reference, {}).get(key)
                if subtable is not None and subtable.has_values():
                    break
            else:
                continue

        for (reference, size) in references.iteritems():
            subtable_key = (args.target_name, sample, library, reference)
            subtable = create_or_get_subtable(table, subtable_key, size)

            statistics = counts.get(reference, {}).get(key)
            if statistics is not None:
                subtable.add(statistics)

    return table
Esempio n. 2
0
def build_table(args, handle, counts):
    references = collect_references(args, handle)

    table = {}
    for (key, readgroup) in collect_readgroups(args, handle).iteritems():
        sample = readgroup["SM"]
        library = readgroup["LB"]

        # Exclude counts for reads with no read-groups, if none such were seen
        if key is None and not args.ignore_readgroups:
            for reference in references:
                subtable = counts.get(reference, {}).get(key)
                if subtable is not None and subtable.has_values():
                    break
            else:
                continue

        for (reference, size) in references.iteritems():
            subtable_key = (args.target_name, sample, library, reference)
            subtable = create_or_get_subtable(table, subtable_key, size)

            statistics = counts.get(reference, {}).get(key)
            if statistics is not None:
                subtable.add(statistics)

    return table
Esempio n. 3
0
def build_key_struct(args, handle):
    structure = collections.defaultdict(set)
    for readgroup in collect_readgroups(args, handle).itervalues():
        lb_key = readgroup["LB"]
        sm_key = readgroup["SM"]
        structure[sm_key].add(lb_key)

    return structure
Esempio n. 4
0
def build_key_struct(args, handle):
    structure = collections.defaultdict(set)
    for readgroup in collect_readgroups(args, handle).itervalues():
        lb_key = readgroup["LB"]
        sm_key = readgroup["SM"]
        structure[sm_key].add(lb_key)

    return structure
Esempio n. 5
0
def build_table(args, handle, counts):
    table = {}
    for (key, readgroup) in collect_readgroups(args, handle).iteritems():
        sample = readgroup["SM"]
        library = readgroup["LB"]

        for (reference, size) in collect_references(args, handle).iteritems():
            subtable_key = (args.target_name, sample, library, reference)
            subtable = create_or_get_subtable(table, subtable_key, size)

            statistics = counts.get(reference, {}).get(key, {})
            for (stat, value) in statistics.iteritems():
                subtable[stat] += value

    return table
Esempio n. 6
0
def build_rg_to_smlbid_keys(args, handle):
    """Returns a dictionary which maps a readgroup ID to an index value,
    as well as a list containing a tuple (samples, library) corresponding
    to each index. Typically, this list will be shorter than the map of read-
    groups, as multiple read-groups will map to the same sample / library.
    """

    rg_to_lbsmid = {}
    lbsm_to_lbsmid = {}
    lbsmid_to_smlb = []
    for (key_rg, readgroup) in collect_readgroups(args, handle).iteritems():
        key_sm = readgroup["SM"]
        key_lb = readgroup["LB"]

        key_lbsm = (key_sm, key_lb)
        if key_lbsm not in lbsm_to_lbsmid:
            lbsm_to_lbsmid[key_lbsm] = len(lbsm_to_lbsmid)
            lbsmid_to_smlb.append(key_lbsm)

        rg_to_lbsmid[key_rg] = lbsm_to_lbsmid[key_lbsm]
    return rg_to_lbsmid, lbsmid_to_smlb
Esempio n. 7
0
def build_rg_to_smlbid_keys(args, handle):
    """Returns a dictionary which maps a readgroup ID to an index value,
    as well as a list containing a tuple (samples, library) corresponding
    to each index. Typically, this list will be shorter than the map of read-
    groups, as multiple read-groups will map to the same sample / library.
    """

    rg_to_lbsmid = {}
    lbsm_to_lbsmid = {}
    lbsmid_to_smlb = []
    for (key_rg, readgroup) in collect_readgroups(args, handle).iteritems():
        key_sm = readgroup["SM"]
        key_lb = readgroup["LB"]

        key_lbsm = (key_sm, key_lb)
        if key_lbsm not in lbsm_to_lbsmid:
            lbsm_to_lbsmid[key_lbsm] = len(lbsm_to_lbsmid)
            lbsmid_to_smlb.append(key_lbsm)

        rg_to_lbsmid[key_rg] = lbsm_to_lbsmid[key_lbsm]
    return rg_to_lbsmid, lbsmid_to_smlb
Esempio n. 8
0
def build_region_template(args, handle):
    template = {}
    for key in collect_readgroups(args, handle):
        template[key] = dict(READGROUP_TEMPLATE)
    return template
Esempio n. 9
0
def build_region_template(args, handle):
    template = {}
    for key in collect_readgroups(args, handle):
        template[key] = ReadGroup()
    return template
Esempio n. 10
0
def build_region_template(args, handle):
    template = {}
    for key in collect_readgroups(args, handle):
        template[key] = ReadGroup()
    return template