void TwoBitFile::populateSequenceMeta(TwoBitSequenceMeta& meta) { // seek to offset and read actual sequence meta data. file_.seekg(meta.offset_); meta.dnaSize_ = nextInt(); // length of sequence meta.dnaBytes_ = meta.dnaSize_ / 4 + (meta.dnaSize_ % 4 > 0); // read nRegions. readRegions(meta.nRegions); // N-regions readRegions(meta.mRegions); // mask regions // check. this number should be zero as per the spec. if (0 != nextInt()) { throw Exception(__PRETTY_FUNCTION__, "Unexpected data. Bad 2-bit file."); } // store start of packed data meta.packedPos_ = file_.tellg(); }
bool World::load(const std::string& dir) { fs::path world_dir(dir); fs::path region_dir = world_dir / "region"; if(!fs::exists(world_dir)) { std::cerr << "Error: World directory " << world_dir << " does not exist!" << std::endl; } else if(!fs::exists(region_dir)) { std::cerr << "Error: Region directory " << region_dir << " does not exist!" << std::endl; } else { return readRegions(region_dir.string()); } return false; }
/** * Loads a world from a directory. */ bool World::load(const std::string& dir, int rotation) { this->rotation = rotation; fs::path world_dir(dir); fs::path region_dir = world_dir / "region"; if(!fs::exists(world_dir)) { std::cerr << "World directory " << world_dir << " does not exists!" << std::endl; } else if(!fs::exists(region_dir)) { std::cerr << "Region directory " << region_dir << " does not exists!" << std::endl; } else { return readRegions(region_dir.string()); } return false; }
int main(int argc, char* argv[]){ if (argc != 3) printErrorAndDie("Script requires exactly 2 arguments"); std::string region_file = std::string(argv[1]); std::string vcf_file = std::string(argv[2]); // Read list of regions std::vector<Region> regions; readRegions(region_file, regions, 1000, "", std::cerr); vcflib::VariantCallFile ref_vcf; if(!ref_vcf.open(vcf_file)) printErrorAndDie("Failed to open VCF"); // Populate map with samples in VCF header std::map<std::string, int> sample_indices; for (unsigned int i = 0; i < ref_vcf.sampleNames.size(); i++) sample_indices[ref_vcf.sampleNames[i]] = i; std::vector<std::string> alleles; std::vector<bool> got_priors; int32_t pos; for (unsigned int i = 0; i < regions.size(); i++){ bool success; double* priors = extract_vcf_alleles_and_log_priors(&ref_vcf, &(regions[i]), sample_indices, alleles, got_priors, pos, success, std::cerr); if (success){ std::cerr << "Position=" << pos << std::endl; std::cerr << "Alleles:" << std::endl; for (unsigned int j = 0; j < alleles.size(); j++) std::cerr << alleles[j] << std::endl; } else { std::cerr << "Failed to read alleles and priors for region " << regions[i].str() << std::endl; } alleles.clear(); got_priors.clear(); delete [] priors; } }
int main (int argc, char **argv) { Options mergetr = readParameters (argc, argv); char filename_mesh_node[FILENAME_MAX]; char filename_mesh_ele[FILENAME_MAX]; char filename_otoczka[FILENAME_MAX]; char filename_output_node[FILENAME_MAX]; char filename_output_ele[FILENAME_MAX]; int no_of_meshes = argc-mergetr.args_start; strcpy (filename_otoczka, mergetr.input); if ( strstr (filename_otoczka, ".poly") == NULL) strcat (filename_otoczka, ".poly"); strcpy (filename_output_node, mergetr.output); strcat (filename_output_node, ".node"); strcpy (filename_output_ele, mergetr.output); strcat (filename_output_ele, ".ele"); fprintf(stdout, "************************************\n"); fprintf(stdout, "***** M * E * R * G * E * T * R ****\n"); fprintf(stdout, "************************************\n"); fprintf(stdout, "* Otoczka filename: %s\n", filename_otoczka); fprintf(stdout, "* Output filenames: %s & %s\n", filename_output_node, filename_output_ele); fprintf(stdout, "* Triangle options: %s\n", mergetr.tr_opt); fprintf(stdout, "************************************\n"); struct triangulateio *siatka; struct triangulateio otoczka; struct triangulateio out; EdgeList **v; PointList **p; int i; siatka = malloc ( no_of_meshes * sizeof *siatka); v = malloc ( no_of_meshes * sizeof **v ); p = malloc ( no_of_meshes * sizeof **p ); if (siatka == NULL || v == NULL || p == NULL) { fprintf (stderr, "** Error! Not enough memory!"); return -1; } initTriangulation (&otoczka); /* OTOCZKA */ FILE *file_otoczka = fopen( filename_otoczka, "r"); if (file_otoczka == NULL) { fprintf(stderr, "** Error while opening %s\n", filename_otoczka); return -100; } readPoints (file_otoczka, &otoczka); readSegments (file_otoczka, &otoczka); readHoles (file_otoczka, &otoczka); readRegions (file_otoczka, &otoczka); fclose (file_otoczka); /* MESHES */ for (i = 0; i < (argc - mergetr.args_start); i++) { strcpy (filename_mesh_node, argv[mergetr.args_start+i]); strcat (filename_mesh_node, ".node"); strcpy (filename_mesh_ele, argv[mergetr.args_start+i]); strcat (filename_mesh_ele, ".ele"); fprintf(stdout, "************************************\n"); fprintf(stdout, "* Mesh filenames: %s & %s\n", filename_mesh_node, filename_mesh_ele); fprintf(stdout, "************************************\n"); FILE *file_mesh_node = fopen( filename_mesh_node, "r"); FILE *file_mesh_ele = fopen( filename_mesh_ele, "r"); if (file_mesh_node == NULL) { fprintf(stderr, "** Error while opening %s\n", filename_mesh_node); return -101; } if (file_mesh_node == NULL) { fprintf(stderr, "** Error while opening %s\n", filename_mesh_ele); return -102; } initTriangulation (&siatka[i]); readPoints (file_mesh_node, &siatka[i]); readTriangles (file_mesh_ele, &siatka[i]); fclose (file_mesh_node); fclose (file_mesh_ele); v[i] = createEdgeList(siatka[i]); markBndEdges (siatka[i], v[i]); p[i] = makePointList (otoczka, siatka[i], v[i]); updatePoints (&otoczka, siatka[i], v[i], p[i]); updateSegments (&otoczka, siatka[i], v[i], p[i]); updateHoles (&otoczka, siatka[i]); } fprintf(stdout, "************************************\n"); /* TRIANGULAtE */ initTriangulation (&out); strcat (mergetr.tr_opt, "pYYQ"); triangulate (mergetr.tr_opt, &otoczka, &out, (struct triangulateio *) NULL); /* GLUE HOLES */ /* markNotBndEdges (siatka1, v); */ for (i = 0; i < no_of_meshes; i++) { glueNotBndPoints (&out, siatka[i], p[i]); /* DOKLEJANIE DO OUT */ fixPointListNumbers (&out, &siatka[i], p[i]); glueInteriorTriangles (&out, siatka[i], p[i]); removeHole (&out); } FILE *file_output_node = fopen (filename_output_node, "w"); FILE *file_output_ele = fopen (filename_output_ele, "w"); writePoints (file_output_node, out); writeTriangles (file_output_ele, out); fclose (file_output_node); fclose (file_output_ele); fprintf(stdout, "************************************\n"); free (p); free (v); freeTriangulation (&otoczka); freeTriangulation (&out); for (i = 0; i < no_of_meshes; i++) freeTriangulation (&siatka[i]); return 0; }