Retrieve gender from metadata, codified as male/female/unknown.
333304
def get_gender(data):
    
    g = str(dd.get_gender(data))
    if g and str(g).lower() in ["male", "m", "1"]:
        return "male"
    elif g and str(g).lower() in ["female", "f", "2"]:
        return "female"
    else:
        return "unknown"
474880
def genderize(name, api_token=None):
    """"""

    GENDERIZE_API_URL = "https://api.genderize.io/"
    TOTAL_RETRIES = 10
    MAX_RETRIES = 5
    SLEEP_TIME = 0.25
    STATUS_FORCELIST = [502]

    params = {
        'name': name
    }

    if api_token:
        params['apikey'] = api_token

    session = requests.Session()

    retries = urllib3.util.Retry(total=TOTAL_RETRIES,
                                 connect=MAX_RETRIES,
                                 status=MAX_RETRIES,
                                 status_forcelist=STATUS_FORCELIST,
                                 backoff_factor=SLEEP_TIME,
                                 raise_on_status=True)

    session.mount('http://', requests.adapters.HTTPAdapter(max_retries=retries))
    session.mount('https://', requests.adapters.HTTPAdapter(max_retries=retries))

    r = session.get(GENDERIZE_API_URL, params=params)
    r.raise_for_status()
    result = r.json()

    gender = result['gender']
    prob = result.get('probability', None)

    acc = int(prob * 100) if prob else None

    return gender, acc
1374238
def getMetadataId(self, metadata):
        
        return str(datamodel.VariantSetMetadataCompoundId(
            self.getCompoundId(), 'metadata:' + metadata.key))
241518
def __meta_metadata(self, field, key):
        """"""
        mf = ''
        try:
            mf = str([f[key] for f in self.metadata
                     if f['field_name'] == field][0])
        except IndexError:
            print("%s not in metadata field:%s" % (key, field))
            return mf
        else:
            return mf
720138
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'url') and self.url is not None:
            _dict['url'] = self.url
        if hasattr(self, 'gender') and self.gender is not None:
            _dict['gender'] = self.gender
        if hasattr(self, 'name') and self.name is not None:
            _dict['name'] = self.name
        if hasattr(self, 'language') and self.language is not None:
            _dict['language'] = self.language
        if hasattr(self, 'description') and self.description is not None:
            _dict['description'] = self.description
        if hasattr(self, 'customizable') and self.customizable is not None:
            _dict['customizable'] = self.customizable
        if hasattr(
                self,
                'supported_features') and self.supported_features is not None:
            _dict['supported_features'] = self.supported_features._to_dict()
        if hasattr(self, 'customization') and self.customization is not None:
            _dict['customization'] = self.customization._to_dict()
        return _dict
235415
def autogender(self, api_token=None, genderize_all=False):
        
        name_cache = {}
        no_gender = not genderize_all
        pattern = re.compile(r"(^\w+)\s\w+")

        profiles = api.search_profiles(self.db, no_gender=no_gender)

        for profile in profiles:
            if not profile.name:
                continue

            name = profile.name.strip()
            m = pattern.match(name)

            if not m:
                continue

            firstname = m.group(1).lower()

            if firstname in name_cache:
                gender_data = name_cache[firstname]
            else:
                try:
                    gender, acc = genderize(firstname, api_token)
                except (requests.exceptions.RequestException,
                        requests.exceptions.RetryError) as e:
                    msg = "Skipping '%s' name (%s) due to a connection error. Error: %s"
                    msg = msg % (firstname, profile.uuid, str(e))
                    self.warning(msg)
                    continue

                gender_data = {
                    'gender': gender,
                    'gender_acc': acc
                }
                name_cache[firstname] = gender_data

            if not gender_data['gender']:
                continue

            try:
                api.edit_profile(self.db, profile.uuid, **gender_data)
                self.display('autogender.tmpl',
                             uuid=profile.uuid, name=profile.name,
                             gender_data=gender_data)
            except (NotFoundError, InvalidValueError) as e:
                self.error(str(e))
                return e.code

        return CMD_SUCCESS
364223
def _guess_group(info):
    """"""
    value = "fake"
    if "metadata" in info:
        if info["metadata"]:
            return ",".join(map(str, info["metadata"].values()))
    return value
744720
def determine_metadata(self, request, view):
        """"""
        metadata = super(
            DynamicMetadata,
            self).determine_metadata(
            request,
            view)
        metadata['features'] = getattr(view, 'features', [])
        if hasattr(view, 'get_serializer'):
            serializer = view.get_serializer(dynamic=False)
            if hasattr(serializer, 'get_name'):
                metadata['resource_name'] = serializer.get_name()
            if hasattr(serializer, 'get_plural_name'):
                metadata['resource_name_plural'] = serializer.get_plural_name()
        metadata['properties'] = self.get_serializer_info(serializer)
        return metadata
854192
def filter_vcf_by_sex(vcf_file, items):
    
    out_file = "%s-ploidyfix%s" % utils.splitext_plus(vcf_file)
    if not utils.file_exists(out_file):
        genders = list(_configured_genders(items))
        is_female = len(genders) == 1 and genders[0] and genders[0] in ["female", "f"]
        if is_female:
            orig_out_file = out_file
            out_file = orig_out_file.replace(".vcf.gz", ".vcf")
            with file_transaction(items[0], out_file) as tx_out_file:
                with open(tx_out_file, "w") as out_handle:
                    with utils.open_gzipsafe(vcf_file) as in_handle:
                        for line in in_handle:
                            if line.startswith("#"):
                                out_handle.write(line)
                            else:
                                chrom = chromosome_special_cases(line.split("\t"))
                                if chrom != "Y":
                                    out_handle.write(line)
            if orig_out_file.endswith(".gz"):
                out_file = vcfutils.bgzip_and_index(out_file, items[0]["config"])
        else:
            out_file = vcf_file
    return out_file
354837
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'gender') and self.gender is not None:
            _dict['gender'] = self.gender
        if hasattr(self, 'gender_label') and self.gender_label is not None:
            _dict['gender_label'] = self.gender_label
        if hasattr(self, 'score') and self.score is not None:
            _dict['score'] = self.score
        return _dict
432587
def full_name(gender = :any)
      case gender
      when :any then rand(0..1) == 0 ? male_full_name : female_full_name
      when :male then male_full_name
      when :female then female_full_name
      else raise ArgumentError, 'Invalid gender, must be one of :any, :male, :female'
      end
    end
830149
public function getCustomerGender()
    {
        $genderId = $this->model->getGender();
        if (is_numeric($genderId)) {
            $gender = $this->model->getAttribute('gender')
                ->getSource()->getOptionText($genderId);

            return $gender;
        }

        return '';
    }
108222
def fetch_extra_data(resource):
    """"""
    person_id = resource.get('PersonID', [None])[0]
    identity_class = resource.get('IdentityClass', [None])[0]
    department = resource.get('Department', [None])[0]

    return dict(
        person_id=person_id,
        identity_class=identity_class,
        department=department
    )
696886
def interested_in(self):
        
        genders = []

        for gender in self.cache['interested_in']:
            genders.append(gender)

        return genders
372231
static public function gender($value=null)
    {
        if (!$value) return '保密';
        
        if (is_numeric($value)) {
            return $value == 1 ? '男' : ($value == 2 ? '女' : '保密');
        } else {
            return $value == '男' ? '男' : ($value == '女' ? '女' : '保密');
        }
    }
415986
def get_default_gentation(gender, orientation):
    """"""
    gender = gender.lower()[0]
    orientation = orientation.lower()
    return gender_to_orientation_to_gentation[gender][orientation]
817444
function genderVariables($object) {
        if (strstr($this->conditions, "@gender") == false)
            return array();

        if ($object == null)
            return array("@gender" => "unknown");

        $context = $this->language_case->language->contextByKeyword("gender");

        if ($context == null)
            return array("@gender" => "unknown");

        return $context->vars($object);
    }