Esempio n. 1
0
arma::mat readMDS(const std::string& file_name, const std::vector<Sample>& sample_names)
{
   arma::mat MDS = readHDF5(file_name);

   // Check that the sample names match up
   std::string sample_name_file = file_name + sample_suffix;
   if (fileStat(sample_name_file))
   {
      std::ifstream samples_in(sample_name_file.c_str());
      if (samples_in)
      {
         arma::uvec keep_indices(sample_names.size());
         unsigned int sample_row = 0;
         unsigned int file_row = 0;

         while (samples_in)
         {
            std::string sample_name;
            samples_in >> sample_name;

            // Must be ordered, and lines in sample_names be a subset of what
            // is in the file. Otherwise a non-compatible mds will be returned
            // which will throw
            if (sample_name == sample_names.at(sample_row).iid())
            {
               keep_indices(sample_row) = file_row;
               if (++sample_row >= sample_names.size())
               {
                  break;
               }
            }
            ++file_row;
         }

         // Only keep the rows where the pheno file has data
         if (sample_row == sample_names.size())
         {
            MDS = MDS.rows(keep_indices);
         }
         else
         {
            throw std::runtime_error("Could not find all samples in input .pheno file in --struct mat. Was kmds run with all samples included?");
         }
      }
      else
      {
         std::cerr << "WARNING: Could not open sample file " + sample_name_file + ". Ensure kmds and seer -p inputs were identical" << std::endl;
      }
   }
Esempio n. 2
0
void cData2d::readHDF5(char* filename){
	char fieldname[100];
	strcpy(fieldname, "/data/data");
	readHDF5(filename, fieldname);
}