// Private member functions: // The images are stored in the image list, one image path per row. // This function reads the images into image_vec_ and their aspect // ratios into image_alpha_vec_. bool CollageBasic::ReadImageList(std::string input_image_list) { std::ifstream input_list(input_image_list.c_str()); if (!input_list) { std::cout << "Error: ReadImageList()" << std::endl; return false; } while (!input_list.eof()) { std::string img_path; std::getline(input_list, img_path); // std::cout << img_path <<std::endl; cv::Mat img = cv::imread(img_path.c_str()); image_vec_.push_back(img); float img_alpha = static_cast<float>(img.cols) / img.rows; image_alpha_vec_.push_back(img_alpha); image_path_vec_.push_back(img_path); } input_list.close(); return true; }
int main(int argc, char *argv[]) { char *action; char *name; char *prefix; int ret; int fail = 0; char *state; if (argc != 4 || (strcmp(argv[1], "load") && strcmp(argv[1], "save") && strcmp(argv[1], "save+"))) { printf("Brain manipulation\n"); printf("Usage: %s load <name> <filename prefix>\n", argv[0]); printf(" %s save <name> <filename prefix>\n", argv[0]); printf(" %s save+ <name> <filename prefix>\n", argv[0]); return 1; } action = argv[1]; name = argv[2]; prefix = argv[3]; state = "db_connect"; ret = db_connect(); if (ret) goto fail; else log_info("brain", ret, state); state = "db_begin"; ret = db_begin(); if (ret) goto fail; else log_info("brain", ret, state); if (!strcmp(action, "load")) { state = "input_list aux"; ret = input_list(name, prefix, "aux", LIST_AUX); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); state = "input_list ban"; ret = input_list(name, prefix, "ban", LIST_BAN); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); state = "input_list grt"; ret = input_list(name, prefix, "grt", LIST_GREET); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); state = "input_map swp"; ret = input_map(name, prefix, "swp", MAP_SWAP); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); state = "input_brain"; ret = input_brain(name, prefix); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); } else if (!strcmp(action, "save") || !strcmp(action, "save+")) { enum file_type type = FILETYPE_MEGAHAL8; if (!strcmp(action, "save+")) type = FILETYPE_SQLHAL0; state = "output_list aux"; ret = output_list(name, prefix, "aux", LIST_AUX); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); state = "output_list ban"; ret = output_list(name, prefix, "ban", LIST_BAN); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); state = "output_list grt"; ret = output_list(name, prefix, "grt", LIST_GREET); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); state = "output_map swp"; ret = output_map(name, prefix, "swp", MAP_SWAP); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); state = "output_brain"; ret = output_brain(name, type, prefix); if (ret) { log_warn("brain", ret, state); fail = 1; } else log_info("brain", ret, state); } else { fail = 1; } if (fail) { state = "db_rollback"; ret = db_rollback(); if (ret) goto fail; else log_info("brain", ret, state); } else { state = "db_commit"; ret = db_commit(); if (ret) goto fail; else log_info("brain", ret, state); } state = "db_disconnect"; ret = db_disconnect(); if (ret) goto fail; else log_info("brain", ret, state); return 0; fail: log_fatal("brain", ret, state); return 1; }
int main(int argc, char** args) { // check the range of the values in this mesh ParameterReader pd; bool use_mesh_file = atof(pd.getData("use_mesh_file").c_str()); if(use_mesh_file) { // this works for a single mesh PangaeaMeshData inputMesh; std::string input_file = pd.getData("input_mesh_file"); std::string output_file = pd.getData("output_mesh_file"); PangaeaMeshIO::loadfromFile(input_file, inputMesh); vector<vector<double> > bbox; getMeshBoundingBox(inputMesh, bbox); double xrange = bbox[0][1] - bbox[0][0]; double yrange = bbox[1][1] - bbox[1][0]; double zrange = bbox[2][1] - bbox[2][0]; cout << "x_range: " << xrange << endl; cout << "y_range: " << yrange << endl; cout << "z_range: " << zrange << endl; double factor = 400.0 / zrange; cout << "scaling factor is: " << factor << endl; // scale the mesh up scaleMeshUp(inputMesh, factor); PangaeaMeshIO::writeToFile(output_file, inputMesh); }else { // this works for a heirachy of meshes PangaeaMeshData inputMesh; std::string input_format = pd.getData("input_mesh_format"); std::string output_format = pd.getData("output_mesh_format"); std::string input_list_str = pd.getData("input_list"); std::stringstream input_list(input_list_str); int number; vector<int> input_list_vector; input_list >> number; while( !input_list.fail() ) { input_list_vector.push_back(number); input_list >> number; } double factor = 0; char buffer[BUFFER_SIZE]; for(int i = 0; i < input_list_vector.size(); ++i) { stringstream input_file; sprintf(buffer, input_format.c_str(), input_list_vector[i]); input_file << buffer; //memset(&buffer[0], 0, sizeof(buffer)); stringstream output_file; sprintf(buffer, output_format.c_str(), input_list_vector[i]); output_file << buffer; //memset(&buffer[0], 0, sizeof(buffer)); PangaeaMeshIO::loadfromFile(input_file.str(), inputMesh); if(factor == 0) // if this is the first frame { vector<vector<double> > bbox; getMeshBoundingBox(inputMesh, bbox); double xrange = bbox[0][1] - bbox[0][0]; double yrange = bbox[1][1] - bbox[1][0]; double zrange = bbox[2][1] - bbox[2][0]; cout << "x_range: " << xrange << endl; cout << "y_range: " << yrange << endl; cout << "z_range: " << zrange << endl; factor = 400.0 / zrange; cout << "scaling factor is: " << factor << endl; } // scale the mesh up scaleMeshUp(inputMesh, factor); PangaeaMeshIO::writeToFile(output_file.str(), inputMesh); } } }
int main(int argc, const char * argv[]) { std::string chrom_path, output_path, list_path; // TODO(jl): remove requirement for bin_size int bin; if (argc < 5) { printf("Usage: correlation {input_list} " "{chrom_sizes} " "{output.results} " "{bin_size}\n"); return 1; } list_path = argv[1]; chrom_path = argv[2]; output_path = argv[3]; bin = std::stoi(argv[4], NULL, 10); InputList input_list(list_path); ChromSize chrom_size = ChromSize(chrom_path); Hdf5Dataset* hdf5_dataset; std::vector<std::string> chroms = chrom_size.get_chrom_list(); // read hdf5 std::map<std::string, GenomicDataset> data; for (uint64_t i = 0; i < input_list.size(); ++i) { try { Hdf5Reader hdf5_reader = Hdf5Reader(input_list[i].first); data.emplace(input_list[i].second, GenomicDataset(input_list[i].second)); for (const std::string& chrom : chroms) { std::string name = input_list[i].second + "/" + chrom; if (hdf5_reader.IsValid(name)) { hdf5_dataset = hdf5_reader.GetDataset(name, bin); data[input_list[i].second].add_chromosome(chrom, *hdf5_dataset); } } } catch (...) { std::cout<< "Could not open file: "<< input_list[i].first<< std::endl; } } // generate all file pairs to correlate std::vector<std::pair<std::string, std::string>> pairs; for (uint64_t i = 0; i < input_list.size(); ++i) { for (uint64_t j = 0; j <= i; ++j) { pairs.push_back(std::make_pair(input_list[i].second, input_list[j].second)); } } // compute correlation for every pair std::ofstream output_file; output_file.open(output_path); int pair_count = 0; std::string sizes = ""; while(sizes == ""){ sizes = data[pairs[pair_count].first].get_sizes(); ++pair_count; } output_file << sizes << std::endl; std::string first, second; std::map<std::string, float> result; #pragma omp parallel for private(first, second, result) for (uint64_t i = 0; i < pairs.size(); ++i) { first = pairs[i].first; second = pairs[i].second; result = data[first].Correlate(data[second], chroms); std::string name = first + ":" + second; write_entry(output_file, name, result); } output_file.close(); return 0; }