Convert a variant to a proper update
        
        Args:
            variant(dict)
        
        Returns:
            update(dict)
184968
def _get_update(self, variant):
        
        update = {
                '$inc': {
                    'homozygote': variant.get('homozygote', 0),
                    'hemizygote': variant.get('hemizygote', 0),
                    'observations': 1
                },
                '$set': {
                    'chrom': variant.get('chrom'),
                    'start': variant.get('pos'),
                    'end': variant.get('end'),
                    'ref': variant.get('ref'),
                    'alt': variant.get('alt'),
                }
             }
        if variant.get('case_id'):
            update['$push'] = {
                                'families': {
                                '$each': [variant.get('case_id')],
                                '$slice': -50
                                }
                            }
        return update
1282786
def composite_update(item, update_dict, soft=False):
        
        item = Composite(item)

        for part in item.get_content():
            if soft:
                for key, value in update_dict.items():
                    if key not in part:
                        part[key] = value
            else:
                part.update(update_dict)
        return item
90431
def create(self, request):
        
        variant_id = request.data.get("variant_id", None)

        if variant_id is not None:
            variant = ProductVariant.objects.get(id=variant_id)

            quantity = int(request.data.get("quantity", 1))
            items, bid = utils.get_basket_items(request)

            # Check if the variant is already in the basket
            in_basket = False
            for item in items:
                if item.variant.id == variant.id:
                    item.increase_quantity(quantity)
                    in_basket = True
                    break
            if not in_basket:
                item = BasketItem(variant=variant, quantity=quantity, basket_id=bid)
                item.save()

            serializer = BasketItemSerializer(self.get_queryset(request), many=True)
            response = Response(data=serializer.data,
                                status=status.HTTP_201_CREATED)

        else:
            response = Response(
                {"message": "Missing 'variant_id'"},
                status=status.HTTP_400_BAD_REQUEST)

        return response
1217484
def _updateMetadata(self, variantFile):
        
        metadata = self._getMetadataFromVcf(variantFile)
        if self._metadata is None:
            self._metadata = metadata
1305445
def annotate_variant(variant, var_obj=None):
    
    if var_obj:
    
        variant.INFO['Obs'] = var_obj['observations']
        if var_obj.get('homozygote'):
            variant.INFO['Hom'] = var_obj['homozygote']
        if var_obj.get('hemizygote'):
            variant.INFO['Hem'] = var_obj['hemizygote']
    
    return variant
132642
def iter_variants(self):
        """"""
        for v in self.get_vcf():
            yield Variant(v.ID, v.CHROM, v.POS, {v.REF} | set(v.ALT))
167913
def update_product_version(id, **kwargs):
    
    content = update_product_version_raw(id, **kwargs)
    if content:
        return utils.format_json(content)
43030
def _add_thousand_g(self, variant_obj, info_dict):
        
        thousand_g = info_dict.get('1000GAF')
        if thousand_g:
            logger.debug("Updating thousand_g to: {0}".format(
                thousand_g))
            variant_obj.thousand_g = float(thousand_g)
            variant_obj.add_frequency('1000GAF', variant_obj.get('thousand_g'))
526149
def build_profile_variant(variant):
    

    chrom = variant.CHROM
    if chrom.startswith(('chr', 'CHR', 'Chr')):
        chrom = chrom[3:]

    pos = int(variant.POS)

    variant_id = get_variant_id(variant)

    ref = variant.REF
    alt = variant.ALT[0]

    maf = get_maf(variant)

    profile_variant = ProfileVariant(
        variant_id=variant_id,
        chrom=chrom,
        pos=pos,
        ref=ref,
        alt=alt,
        maf=maf,
        id_column = variant.ID
    )

    return profile_variant
62558
def runGetVariant(self, id_):
        
        compoundId = datamodel.VariantCompoundId.parse(id_)
        dataset = self.getDataRepository().getDataset(compoundId.dataset_id)
        variantSet = dataset.getVariantSet(compoundId.variant_set_id)
        gaVariant = variantSet.getVariant(compoundId)
        # TODO variant is a special case here, as it's returning a
        # protocol element rather than a datamodel object. We should
        # fix this for consistency.
        jsonString = protocol.toJson(gaVariant)
        return jsonString
449839
def show(self, item, variant):
        
        url = self._build_url(self.endpoint.show(item, variant))
        return self._get(url)
325976
def create(self, request):
        

        variant_id = request.data.get("variant_id", None)
        if variant_id is not None:
            variant = ProductVariant.objects.get(id=variant_id)
            product_request = ProductRequest(variant=variant)
            product_request.save()
            serializer = self.serializer_class(product_request)
            response = Response(data=serializer.data, status=status.HTTP_201_CREATED)
        else:
            response = Response(
                {"message": "Missing 'variant_id'"},
                status=status.HTTP_400_BAD_REQUEST)

        return response
552495
def convertVariant(self, record, callSetIds):
        
        variant = self._createGaVariant()
        variant.reference_name = record.contig
        if record.id is not None:
            variant.names.extend(record.id.split(';'))
        variant.start = record.start          # 0-based inclusive
        variant.end = record.stop             # 0-based exclusive
        variant.reference_bases = record.ref
        if record.alts is not None:
            variant.alternate_bases.extend(list(record.alts))
        filterKeys = record.filter.keys()
        if len(filterKeys) == 0:
            variant.filters_applied = False
        else:
            variant.filters_applied = True
            if len(filterKeys) == 1 and filterKeys[0] == 'PASS':
                variant.filters_passed = True
            else:
                variant.filters_passed = False
                variant.filters_failed.extend(filterKeys)
        # record.qual is also available, when supported by GAVariant.
        for key, value in record.info.iteritems():
            if value is None:
                continue
            if key == 'SVTYPE':
                variant.variant_type = value
            elif key == 'SVLEN':
                variant.svlen = int(value[0])
            elif key == 'CIPOS':
                variant.cipos.extend(value)
            elif key == 'CIEND':
                variant.ciend.extend(value)
            elif isinstance(value, str):
                value = value.split(',')
            protocol.setAttribute(
                variant.attributes.attr[key].values, value)
        for callSetId in callSetIds:
            callSet = self.getCallSet(callSetId)
            pysamCall = record.samples[str(callSet.getSampleName())]
            variant.calls.add().CopyFrom(
                self._convertGaCall(callSet, pysamCall))
        variant.id = self.getVariantId(variant)
        return variant
626359
def admin_update_variant_columns    
      return if !user_is_allowed('products', 'edit')
      session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil?
      
      resp = Caboose::StdClass.new({'attributes' => {}})
      product = Product.find(params[:id])    
      
      save = true    
      params.each do |name,value|
        value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
        case name
          when 'option1'        ,
            'option2'           ,
            'option3'           ,
            'status'            ,
            'alternate_id'      ,
            'sku'               ,                        
            'barcode'           , 
            'price'             ,
            'quantity_in_stock' ,
            'weight'            , 
            'length'            , 
            'width'             , 
            'height'            , 
            'cylinder'          , 
            'requires_shipping' ,
            'allow_backorder'   ,
            'taxable'      
            session['variant_cols'][name] = value
        end
      end
      resp.success = save && product.save
      render :json => resp
    end
1371670
def print_variant(variant, include, exclude):
    
    if include:
        for info in variant.INFO:
            key = info[0]
            if not key in include:
                del variant.INFO[key]
    if exclude:
        for exc in exclude:
            if variant.INFO.get(exc):
                del variant.INFO[exc]
                
    print_string = str(variant).rstrip()
    click.echo(print_string)
1255650
def dynamic_content_item_variant_update(self, item_id, id, data, **kwargs):
        ""
        api_path = "/api/v2/dynamic_content/items/{item_id}/variants/{id}.json"
        api_path = api_path.format(item_id=item_id, id=id)
        return self.call(api_path, method="PUT", data=data, **kwargs)
1266291
def update(self, u):
        ''' 
        '''
        for k, v in u.iteritems():
            if isinstance(v, collections.Mapping):
                r = nested_dict.from_dict(self.get(k, {}))
                r.update(v)
                self[k] = r
            elif isinstance(self, collections.Mapping):
                self[k] = u[k]
            else:
                self.__dict__ = dict(k = u[k])