def get_individuals_by_variant(variant_id):
    """
    Return variants that have been called in an individual
    """
    db_session = orm.get_session()

    try:
        var = db_session.query(orm.models.Variant)\
            .filter(orm.models.Variant.id == variant_id)\
            .one_or_none()
    except orm.ORMException as e:
        err = _report_search_failed('variant', e, variant_id=variant_id)
        return err, 500

    if not var:
        err = Error(message="No variant found: "+str(variant_id), code=404)
        return err, 404

    try:
        individuals = [call.individual for call in var.calls
                       if call.individual is not None]
    except orm.ORMException as e:
        err = _report_search_failed('individuals', e, by_variant_id=variant_id)
        return err, 500

    return [orm.dump(i) for i in individuals], 200
def get_variants_by_individual(individual_id):
    """
    Return variants that have been called in an individual
    """
    db_session = orm.get_session()
    ind_id = individual_id

    try:
        ind = db_session.query(orm.models.Individual)\
            .filter(orm.models.Individual.id == ind_id)\
            .one_or_none()
    except orm.ORMException as e:
        err = _report_search_failed('individual', e, individual_id=individual_id)
        return err, 500

    if not ind:
        err = Error(message="No individual found: "+str(ind_id), code=404)
        return err, 404

    try:
        variants = [call.variant for call in ind.calls if call.variant]
    except orm.ORMException as e:
        err = _report_search_failed('variants', e, by_individual_id=individual_id)
        return err, 500

    return [orm.dump(v) for v in variants], 200
def get_calls():
    """
    Return all calls
    """
    try:
        q = Call().query.all()
    except orm.ORMException as e:
        err = _report_search_failed('call', e, call_id='all')
        return err, 500

    return [orm.dump(p) for p in q], 200
def get_individuals():
    """
    Return all individuals
    """
    try:
        q = Individual().query.all()
    except orm.ORMException as e:
        err = _report_search_failed('individuals', e, ind_id="all")
        return err, 500

    return [orm.dump(p) for p in q], 200
def get_variants(chromosome, start, end):
    """
    Return all variants between [chrom, start) and (chrom, end]
    """
    db_session = orm.get_session()
    try:
        q = db_session.query(orm.models.Variant)\
            .filter(models.Variant.chromosome == chromosome)\
            .filter(and_(models.Variant.start >= start, models.Variant.start <= end))
    except orm.ORMException as e:
        err = _report_search_failed('variant', e, chromosome=chromosome, start=start, end=end)
        return err, 500

    return [orm.dump(p) for p in q], 200
def get_one_call(call_id):
    """
    Return single call object
    """
    try:
        q = Call().query.get(call_id)
    except Error as e:
        err = _report_search_failed('call', e, call_id=str(call_id))
        return err, 500

    if not q:
        err = Error(message="No call found: "+str(call_id), code=404)
        return err, 404

    return orm.dump(q), 200
def get_one_individual(individual_id):
    """
    Return single individual object
    """
    try:
        q = Individual().query.get(individual_id)
    except orm.ORMException as e:
        err = _report_search_failed('individual', e, ind_id=str(individual_id))
        return err, 500

    if not q:
        err = Error(message="No individual found: "+str(individual_id), code=404)
        return err, 404

    return orm.dump(q), 200
def get_one_variant(variant_id):
    """
    Return single variant object
    """
    db_session = orm.get_session()
    try:
        q = db_session.query(models.Variant).get(variant_id)
    except orm.ORMException as e:
        err = _report_search_failed('variant', e, var_id=str(variant_id))
        return err, 500

    if not q:
        err = Error(message="No variant found: "+str(variant_id), code=404)
        return err, 404

    return orm.dump(q), 200
Beispiel #9
0
def are_equivalent(ormobj1, ormobj2):
    """
    Are dict representations of two objects equal?
    """
    return dump(ormobj1, nonulls=True) == dump(ormobj2, nonulls=True)