예제 #1
0
def get_genes(base, alleles=None):
    if alleles is None:  # take all of 'em
        alleles = [
            utils.allele(g) for g in glfo['seqs'][args.region]
            if base == get_base(g)
        ]
    return [
        args.locus.upper() + args.region.upper() + base + '*' + al
        for al in alleles
    ]
예제 #2
0
def get_mutfo_from_name(gene_name):
    allele_list = utils.allele(gene_name).split("+")
    if len(allele_list) != 2:
        raise Exception("couldn't get snp info from gene name %s" % gene_name)
    mutfo = {}
    for mutstr in allele_list[1].split("."):
        if len(mutstr) < 3:
            raise Exception("couldn't extract mutation info from %s" % mutstr)
        original, new = mutstr[0], mutstr[-1]
        if original not in utils.nukes or new not in utils.nukes:
            raise Exception("couldn't extract mutation info from %s" % mutstr)
        position = int(mutstr[1:-1])
        if position not in mutfo:
            mutfo[position] = {}
            mutfo[position]["original"] = original  # if it *is* already there, we want to *keep* the old 'original'
        mutfo[position]["new"] = new
        if mutfo[position]["new"] == mutfo[position]["original"]:  # reverted back to the original base
            del mutfo[position]

    return mutfo
예제 #3
0
def get_mutfo_from_name(gene_name):
    allele_list = utils.allele(gene_name).split('+')
    if len(allele_list) != 2:
        raise Exception('couldn\'t get snp info from gene name %s' % gene_name)
    mutfo = {}
    for mutstr in allele_list[1].split('.'):
        if len(mutstr) < 3:
            raise Exception('couldn\'t extract mutation info from %s' % mutstr)
        original, new = mutstr[0], mutstr[-1]
        if original not in utils.nukes or new not in utils.nukes:
            raise Exception('couldn\'t extract mutation info from %s' % mutstr)
        position = int(mutstr[1:-1])
        if position not in mutfo:
            mutfo[position] = {}
            mutfo[position]['original'] = original  # if it *is* already there, we want to *keep* the old 'original'
        mutfo[position]['new'] = new
        if mutfo[position]['new'] == mutfo[position]['original']:  # reverted back to the original base
            del mutfo[position]

    return mutfo
예제 #4
0
def get_new_allele_name_and_change_mutfo(template_gene, mutfo):
    if '+' in utils.allele(template_gene):  # template gene was already snp'd
        old_mutfo = get_mutfo_from_name(template_gene)
        for position, info in mutfo.items():
            if position not in old_mutfo:
                old_mutfo[position] = {}
                old_mutfo[position]['original'] = info['original']  # if it *is* already there, we want to *keep* the old 'original'
            old_mutfo[position]['new'] = info['new']
            if old_mutfo[position]['new'] == old_mutfo[position]['original']:  # reverted back to the original base
                del old_mutfo[position]
        final_mutfo = old_mutfo
        assert len(template_gene.split('+')) == 2
        template_gene = template_gene.split('+')[0]  # before we did any snp'ing
    else:
        final_mutfo = mutfo

    final_name = template_gene
    if len(final_mutfo) > 0:
        assert '+' not in final_name
        final_name += '+' + stringify_mutfo(final_mutfo)  # full, but possibly overly verbose
    return final_name, final_mutfo
예제 #5
0
파일: glutils.py 프로젝트: Annak17/partis
def get_new_allele_name_and_change_mutfo(template_gene, mutfo):
    if '+' in utils.allele(template_gene):  # template gene was already snp'd
        old_mutfo = get_mutfo_from_name(template_gene)
        for position, info in mutfo.items():
            if position not in old_mutfo:
                old_mutfo[position] = {}
                old_mutfo[position]['original'] = info['original']  # if it *is* already there, we want to *keep* the old 'original'
            old_mutfo[position]['new'] = info['new']
            if old_mutfo[position]['new'] == old_mutfo[position]['original']:  # reverted back to the original base
                del old_mutfo[position]
        final_mutfo = old_mutfo
        assert len(template_gene.split('+')) == 2
        template_gene = template_gene.split('+')[0]  # before we did any snp'ing
    else:
        final_mutfo = mutfo

    final_name = template_gene
    if len(final_mutfo) > 0:
        assert '+' not in final_name
        final_name += '+' + stringify_mutfo(final_mutfo)  # full, but possibly overly verbose
    return final_name, final_mutfo
예제 #6
0
sys.path.insert(1, partis_dir + '/python')

import utils
import glutils

parser = argparse.ArgumentParser()
parser.add_argument('--base', required=True)
parser.add_argument('--alleles')
parser.add_argument('--other-genes')
parser.add_argument('--region', default='v')
parser.add_argument('--chain', default='h')
parser.add_argument('--glfo-dir', default='data/germlines/human')
args = parser.parse_args()
glfo = glutils.read_glfo(args.glfo_dir, args.chain)
if args.alleles is None:
    args.alleles = [utils.allele(g) for g in glfo['seqs'][args.region] if args.base == utils.primary_version(g) + '-' + utils.sub_version(g)]
else:
    args.alleles = utils.get_arg_list(args.alleles)
args.other_genes = utils.get_arg_list(args.other_genes)

# for g, s in glfo['seqs']['v'].items():
#     print '%s  %3d' % (utils.color_gene(g, width=20), len(s) - glfo['cyst-positions'][g])
# sys.exit()

# base = '4-59'
# a1, a2 = '12', '01'
# gene1, gene2 = 'IGHV' + base + '*' + a1, 'IGHV' + base + '*' + a2

genes = ['IG' + args.chain.upper() + args.region.upper() + args.base + '*' + al for al in args.alleles]
if args.other_genes is not None:
    genes += args.other_genes
예제 #7
0
import utils
import glutils

parser = argparse.ArgumentParser()
parser.add_argument('--base', required=True)
parser.add_argument('--alleles')
parser.add_argument('--other-genes')
parser.add_argument('--region', default='v')
parser.add_argument('--locus', default='igh', choices=utils.loci.keys())
parser.add_argument('--glfo-dir', default='data/germlines/human')
args = parser.parse_args()
glfo = glutils.read_glfo(args.glfo_dir, args.locus)
if args.alleles is None:
    args.alleles = [
        utils.allele(g) for g in glfo['seqs'][args.region]
        if args.base == utils.primary_version(g) +
        ('-' +
         utils.sub_version(g) if utils.sub_version(g) is not None else '')
    ]
else:
    args.alleles = utils.get_arg_list(args.alleles)
if len(args.alleles) == 0:
    raise Exception(
        'couldn\'t find any alleles for --base %s. Other choices:\n    %s' %
        (args.base, ' '.join(glfo['seqs'][args.region])))
args.other_genes = utils.get_arg_list(args.other_genes)

# for g, s in glfo['seqs']['v'].items():
#     print '%s  %3d' % (utils.color_gene(g, width=20), len(s) - glfo['cyst-positions'][g])
# sys.exit()