Example #1
0
void parse_timestamp(uint32_t time, uint8_t* year, uint8_t* month, uint8_t* day, uint8_t* hh, uint8_t* mm, uint8_t* ss)
{
    uint32_t temp = 0;

    *ss = time % 60;
    temp = time / 60;

    *mm = temp % 60;
    temp = temp / 60;

    *hh = temp % 24;
    temp = temp / 24;

    uint16_t total_day = temp;
    uint8_t tyear = 0;
    while(1)
    {
        if (tyear % 4 == 0)
        {
            if (total_day >= 366)
                total_day -= 366;
            else
                break;
        }
        else
        {
            if (total_day >= 365)
                total_day -= 365;
            else
                break;
        }
        tyear++;
    }

    uint8_t i = 0;
    for (; i < count_elem(month_day_map); ++i)
    {
        if (tyear % 4 == 0 && i == 1)
        {
            if (total_day < month_day_map[i] + 1)
                break;
            total_day -= month_day_map[i] + 1;
        }
        else
        {
            if (total_day < month_day_map[i])
                break;
            total_day -= month_day_map[i];
        }
    }

    *year  = tyear;
    *month = i + 1;
    *day   = total_day;

}
Example #2
0
    template<class T> inline double Locus_data<T>::maf(detail::Marker_type mt) const
    {
        if (nValid() == 0) {
            return 0.0;
        }
        if (mt == detail::genotype) {
            // derive maf via genotype
            std::map<elem_t, count_t> m = this->unique_with_counts();
            m.erase(undef_); //undefined does not count

            // First we need to transform the domain, which could be of type
            // int but also of type string, char, etc... into countable type
            std::vector<count_t> vv; 
            vv.reserve(m.size());
            typename std::map<elem_t, count_t>::const_iterator itMap;
            for (itMap=m.begin(); itMap != m.end(); ++itMap) {
                try {
                    vv.push_back(boost::lexical_cast<count_t>(itMap->first));
                }
                catch (const boost::bad_lexical_cast& e) {
                    std::string s = "Bad data entry '";
                    s.append(boost::lexical_cast<std::string>(itMap->first));
                    s.append("' because it is not part of the genotype domain.\n");
                    throw std::domain_error(s);
                }
            }

            count_t max_sum = nValid()*(*max_element(vv.begin(), vv.end()));
            count_t sum = 0;
            typename Discrete_data<T>::unique_iterator it;
            for (it = this->unique_begin(); it != this->unique_end(); ++it) {
                elem_t g = it->first;    //the genotype
                bool isValid = g != undef_;
                if (isValid) {
                    //#alleles = genotype*(#occurrence)
                    sum += boost::lexical_cast<count_t>(g)*it->second; 
                }
            }
            double maf = double(sum)/double(max_sum);
            return maf > 0.5 ? 1.0 - maf : maf;
        }
        else { //or via alleles, which is simple to compute
            double maf = double(count_elem(minor_)) / double(nValid());
            return maf > 0.5 ? 1.0 - maf : maf;
        }
    }
Example #3
0
 size_t nValid() const { return this->size() - count_elem(undef_); }
Example #4
0
 size_t nMiss() const { return count_elem(undef_); }
Example #5
0
 bool hasMissings() const { return count_elem(undef_) > 0; }