void Skin::save (const gdx_cpp::files::FileHandle& skinFile) { String text = getJsonLoader(null).prettyPrint(this, true); Writer writer = skinFile.writer(false); try { writer.write(text); writer.close(); } catch (IOException ex) { } }
void Partition::write(const char* output_file_name) throw (Exception) { Writer* writer = NULL; block block; const char* first_marker = NULL; const char* last_marker = NULL; unsigned int start_bp = 0u; unsigned int end_bp = 0u; unsigned int n_markers = 0u; unsigned int n_haps = 0u; unsigned int n_unique_haps = 0u; unsigned int n_common_haps = 0u; double haps_diversity = 0.0; try { writer = WriterFactory::create(Writer::TEXT); writer->set_file_name(output_file_name); writer->open(false); writer->write("# VERSION: %s\n", LDEXPLORER_VERSION); writer->write("# PHASE FILE: %s\n", db->hap_file_name); writer->write("# MAP FILE: %s\n", db->map_file_name == NULL ? "NA" : db->map_file_name); if ((db->start_position > 0u) || (db->end_position != numeric_limits<unsigned long int>::max())) { writer->write("# REGION: [%u, %u]\n", db->start_position, db->end_position); } else { writer->write("# REGION: NA\n"); } writer->write("# MAF FILTER: > %g\n", db->maf_threshold); writer->write("# ALL SNPs: %u\n", db->n_unfiltered_markers); writer->write("# FILTERED SNPs: %u\n",db->n_markers); writer->write("# HAPLOTYPES: %u\n", db->n_haplotypes); if (!rsq_blocks) { writer->write("# D' CI COMPUTATION METHOD: %s\n", ci_method); if (likelihood_density > 0u) { writer->write("# D' LIKELIHOOD DENSITY: %u\n", likelihood_density); } else { writer->write("# D' LIKELIHOOD DENSITY: NA\n"); } writer->write("# D' CI LOWER BOUND FOR STRONG LD: >= %g\n", strong_pair_cl); writer->write("# D' CI UPPER BOUND FOR STRONG LD: >= %g\n", strong_pair_cu); writer->write("# D' CI UPPER BOUND FOR RECOMBINATION: <= %g\n", recomb_pair_cu); } else { writer->write("# WEAK LD r^2: < %g\n", weak_pair_rsq); writer->write("# STRONG LD r^2: >= %g\n", strong_pair_rsq); } writer->write("# FRACTION OF STRONG LD SNP PAIRS: >= %g\n", strong_pairs_fraction); writer->write("# PRUNING METHOD: %s\n", pruning_method); if (window > 0u) { writer->write("# WINDOW: %ld\n", window); } else { writer->write("# WINDOW: NA\n", window); } writer->write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", "BLOCK_NAME", "FIRST_SNP", "LAST_SNP", "FIRST_SNP_ID", "LAST_SNP_ID", "START_BP", "END_BP", "N_SNPS", "N_HAPS", "N_UNIQUE_HAPS", "N_COMMON_HAPS", "HAPS_DIVERSITY"); for (unsigned int b = 0u; b < n_blocks; ++b) { block = blocks[b]; first_marker = db->markers[block.start]; last_marker = db->markers[block.end]; start_bp = db->positions[block.start]; end_bp = db->positions[block.end]; n_markers = block.end - block.start + 1u; get_block_diversity(b, &n_haps, &n_unique_haps, &n_common_haps, &haps_diversity); writer->write("BLOCK%07u\t%s\t%s\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%u\t%g\n", b + 1u, first_marker, last_marker, block.start, block.end, start_bp, end_bp, n_markers, n_haps, n_unique_haps, n_common_haps, haps_diversity); } writer->close(); delete writer; } catch (Exception &e) { if (writer != NULL) { delete writer; } throw; } }
String AbstractContextI::loadValueFromURL(const String& urlstring) const throw (Exception) { String result; StringBuffer buf; buf->append(urlstring); if (0 == buf->indexOf(L"http://")) { URL url = new URLI(urlstring); HttpURLConnection httpurlconnection; url->openConnection()->downcast(httpurlconnection); if (verboseOutput()) cout << "JNDI context : Get response from url : " << urlstring << endl; int rc = httpurlconnection->getResponseCode(); UTF8StringBuffer cbuf; #if defined (_WINDOWS_SOURCE) cbuf->append(getenv("TEMP")); cbuf->append("\\"); cbuf->append(getenv("USERNAME")); cbuf->append("."); #else cbuf->append(getenv("USER_HOME")); cbuf->append("/."); #endif cbuf->append(urlstring->toMD5()); cbuf->append(".properties"); String cachefilepath = cbuf->toString()->toLowerCase(); if (200 != rc) { if (verboseOutput()) cout << "JNDI context : HTTP status = " << rc << endl; if (verboseOutput()) cout << "JNDI context : Trying to load from cached file : " << cachefilepath << endl; InputStream file = new FileInputStreamI(cachefilepath); UTF8String content; file->read(content, 0); file->close(); result = content->toString(); } else { String response = httpurlconnection->getResponseMessage(); Writer file = new FileWriterI(cachefilepath); file->write(response); file->close(); if (verboseOutput()) cout << "JNDI context : Caching to file : " << cachefilepath << endl; result = response; } } else if (0 == buf->indexOf(L"file://")) { result = loadValueFromFile(urlstring); } else { throw NamingException(WITHDETAILS(L"Unsupported URI format: " + urlstring)); } StringBuffer b = result; while (-1 < b->indexOf(L"${")) { InitialContext initialcontext = InitialContext::newInstance(); int bpos = 0; int epos = 0; while (bpos < b->length()) { bpos = b->indexOf(L"${", bpos); if (-1 == bpos) break; epos = b->indexOf(L"}", bpos); String variablename = b->substring(bpos + 2, epos); StringAnything variablevalue ; initialcontext->lookup(L"/" + variablename, variablevalue); StringBuffer value = variablevalue->toString(); if (-1 < value->indexOf(L"${" + variablename + L"}") ) throw Exception(WITHDETAILS(L"Recursive reference found : ${" + variablename + L"}")); b->replace(bpos, epos + 1, value->toString()); bpos = epos + 1; } } return b->toString(); }