void ResultsJsInterface::cbSetResultstMeta(const QVariant &vMetaData)
{
	Json::Reader parser;
	parser.parse(fq(vMetaData.toString()), _resultsMeta);

	emit getResultsMetaCompleted();
}
Exemple #2
0
void BamToFastq::SingleFastq() {
    // open the 1st fastq file for writing
    ofstream fq(_fastq1.c_str(), ios::out);
    if ( !fq ) {
        cerr << "Error: The first fastq file (" << _fastq1 << ") could not be opened.  Exiting!" << endl;
        exit (1);
    }
    // open the BAM file
    BamReader reader;
    reader.Open(_bamFile);
    BamAlignment bam;
    while (reader.GetNextAlignment(bam)) {
        // extract the sequence and qualities for the BAM "query"
        string seq  = bam.QueryBases;
        string qual = bam.Qualities;
        if (bam.IsReverseStrand() == true) {
            reverseComplement(seq);
            reverseSequence(qual);
        }
        fq << "@" << bam.Name << endl;
        fq << seq << endl;
        fq << "+" << endl;
        fq << qual << endl;
    }
}
Exemple #3
0
/** Function get_seeds()
 *
 * Produce seeds: rID-> (s0, s1, s2...) for each fragment given two
 * fq files f and f2
 */
void get_seeds (ii64vec_t& list_seeds, const std::string& f,
		const std::string& f2, int seed_len, int batch, bool silent) {

	std::ifstream fh, fh2;
	xny::openfile<std::ifstream>(fh, f);
	xny::openfile<std::ifstream>(fh2, f2);
	bio::fastq_input_iterator<> fq(fh), end, fq2(fh2);

	int total_read_pairs = 0;
	strvec_t pairs;

	while (fq != end && fq2 != end) {

 		add_fq_reads_only (pairs, batch/2, fq, end);
		add_fq_reads_only (pairs, batch/2, fq2, end);

		generate_seeds (list_seeds, pairs, seed_len);

		total_read_pairs += pairs.size()/2;

		pairs.clear();

	} // while

	if (!silent) {
		std::cout << "\t\ttotal frags: " << total_read_pairs <<  "\n";
	}

	xny::closefile(fh);
	xny::closefile(fh2);
} // get_seeds
Exemple #4
0
/**	Function get_super_sketches
 *
 */
void get_super_sketches (std::vector<sketch_t>& super_sketches,
	const std::string& f, const std::string& f2, xny::sketch_list& slistgen,
	xny::super_sketch& ssgen, jaz::murmur264& hashfunc, int batch, bool silent) {

	std::ifstream fh, fh2;
	xny::openfile<std::ifstream>(fh, f);
	xny::openfile<std::ifstream>(fh2, f2);
	bio::fastq_input_iterator<> fq(fh), end, fq2(fh2);

	int total_read_pairs = 0;
	strvec_t pairs;

	while (fq != end && fq2 != end) {

 		add_fq_reads_only (pairs, batch/2, fq, end);
		add_fq_reads_only (pairs, batch/2, fq2, end);

		generate_super_sketches (super_sketches, pairs, slistgen,
				ssgen, hashfunc);

		total_read_pairs += pairs.size()/2;

		pairs.clear();

	} // while

	if (!silent) {
		std::cout << "\t\t\ttotal pairs, super_sketches: " << total_read_pairs
				<< ", " 	<< super_sketches.size() <<  "\n";
	}

	xny::closefile(fh);
	xny::closefile(fh2);
} // get_super_sketches
TEST(Fastq, ConstructorWithValues)
{
    Fastq fq("name", "ACGT", "IIGH");
    EXPECT_EQ(0, fq.name().compare("name"));
    EXPECT_EQ(0, fq.seq().compare("ACGT"));
    EXPECT_EQ(0, fq.qual().compare("IIGH"));
}
Exemple #6
0
void MainWindow::saveSelected(const QString &filename)
{
	if (_analyses->count() > 0)
	{
		QWebElement element =  ui->webViewResults->page()->mainFrame()->documentElement();
		QString qHTML = element.toOuterXml();
		_package->analysesHTML = fq(qHTML);

		Json::Value analysesData = Json::arrayValue;
		for (Analyses::iterator itr = _analyses->begin(); itr != _analyses->end(); itr++)
		{
			Analysis *analysis = *itr;
			if (analysis != NULL && analysis->visible())
			{
				Json::Value analysisData = analysis->asJSON();
				analysisData["options"] = analysis->options()->asJSON();
				analysesData.append(analysisData);
			}
		}

		_package->analysesData = analysesData;
		_package->hasAnalyses = true;
	}

	_loader.save(filename, _package);
	_alert->show();
}
void ResultsJsInterface::saveTempImage(int id, QString path, QByteArray data)
{
	QByteArray byteArray = QByteArray::fromBase64(data);

	QString fullpath = tq(tempfiles_createSpecific_clipboard(fq(path)));

	QFile file(fullpath);
	file.open(QIODevice::WriteOnly);
	file.write(byteArray);
	file.close();

	QString eval = QString("window.imageSaved({ id: %1, fullPath: '%2'});").arg(id).arg(fullpath);
	runJavaScript(eval);
}
Exemple #8
0
/**	Function clean_dupl_frag ()
 *
 */
void clean_dupl_frag (const std::string& ifq, const std::string& ifq2,
	std::ofstream& ofhfq, std::ofstream& ofhfq2, const iset_t& duplIDs,
	xny::low_complexity& lc, int batch){

	std::ifstream ifhfq, ifhfq2;
	xny::openfile<std::ifstream>(ifhfq, ifq);
	xny::openfile<std::ifstream>(ifhfq2, ifq2);
	bio::fastq_input_iterator<> fq(ifhfq), end, fq2(ifhfq2);

	int total_read_pairs = 0;
	std::vector<fqtuple_t> pairs;

	int num_lc = 0;
	int fragID = 0;
	while (fq != end && fq2 != end) {

 		add_fq_reads (pairs, batch/2, fq, end);
		add_fq_reads (pairs, batch/2, fq2, end);
		iset_t low_complex_frag;
		check_low_complexity (low_complex_frag, fragID, pairs, lc);
		num_lc += low_complex_frag.size();
		int fragnum = pairs.size()/2;
		for (int i = 0; i < fragnum; ++ i) {
			if ( (!duplIDs.count(fragID)) &&
				 (!low_complex_frag.count(fragID))) { // output
				ofhfq << "@" << std::get<0>(pairs[i]) << "\n";
				ofhfq << std::get<1>(pairs[i]) << "\n";
				ofhfq << "+\n";
				ofhfq << std::get<2>(pairs[i]) << "\n";

				ofhfq2 << "@" << std::get<0>(pairs[i + fragnum]) << "\n";
				ofhfq2 << std::get<1>(pairs[i + fragnum]) << "\n";
				ofhfq2 << "+\n";
				ofhfq2 << std::get<2>(pairs[i + fragnum]) << "\n";
			}
			++ fragID;
		}

		total_read_pairs += pairs.size()/2;

		pairs.clear();

	} // while

	std::cout << "\t\tlow complexity fragments: " << num_lc << "\n\n";
	xny::closefile(ifhfq);
	xny::closefile(ifhfq2);

} // clean_dupl_frag
Exemple #9
0
void testFasta1() {
  Fasta fa("../../data/test1.fa");
  Fasta fq("../../data/test1.fq");

  TAP_TEST(fa.size() == fq.size(), TEST_FASTA_SIZE, "");
  for (int i=0; i < fa.size(); i++) {
    TAP_TEST(fa.label(i) == fq.label(i), TEST_FASTA_LABEL, "");
    TAP_TEST(fa.label_full(i) == fq.label_full(i), TEST_FASTA_LABEL_FULL, "");
    TAP_TEST(fa.sequence(i) == fq.sequence(i), TEST_FASTA_SEQUENCE, "");
  }
  TAP_TEST(fa.label(2) == "seq3", TEST_FASTA_LABEL, "");
  TAP_TEST(fa.sequence(2) == "A", TEST_FASTA_SEQUENCE, "");
  TAP_TEST(fa.label(4) == "", TEST_FASTA_LABEL, "");
  TAP_TEST(fa.sequence(4) == "AATN", TEST_FASTA_SEQUENCE, "");
}
Exemple #10
0
void testOnlineFasta1() {
  OnlineFasta fa("../../data/test1.fa");
  OnlineFasta fq("../../data/test1.fq");
  int nb_seq = 0;

  TAP_TEST(fa.getLineNb() == 1, TEST_O_FASTA_LINE_NB, "");
  TAP_TEST(fq.getLineNb() == 1, TEST_O_FASTA_LINE_NB, "");

  while (fa.hasNext()) {
    TAP_TEST(fq.hasNext(), TEST_O_FASTA_HAS_NEXT, "");
    fa.next();
    fq.next();
    Sequence s1 = fa.getSequence();
    Sequence s2 = fq.getSequence();
    TAP_TEST(s1.label == s2.label && s1.label_full == s2.label_full
             && s1.sequence == s2.sequence, TEST_O_FASTA_GET_SEQUENCE, "fa: " << fa.getSequence() << endl << "fq: " << fq.getSequence());
    nb_seq++;
  }
  TAP_TEST(fq.getLineNb() == 20, TEST_O_FASTA_LINE_NB, "");
  TAP_TEST(! fq.hasNext(), TEST_O_FASTA_HAS_NEXT, "");
  TAP_TEST(nb_seq == 5, TEST_O_FASTA_HAS_NEXT, "");
}
Exemple #11
0
template<typename KernelType> int som_core::adjust_f(KernelType const& kern,
 typename KernelType::result_type rhs_,
 typename KernelType::result_type error_bars_,
 double norm,
 std::function<bool()> const& stop_callback) {

 if(params.verbosity >= 1) {
  std::cout << "Adjusting the number of global updates F using "
            << params.adjust_f_l << " particular solutions ..." << std::endl;
 }
 objective_function<KernelType> of(kern, rhs_, error_bars_);
 fit_quality<KernelType> fq(kern, rhs_, error_bars_);

 int F = params.adjust_f_range.first;

 int l_good;
 for(l_good = 0;;l_good = 0, F *= 2) {
  // Upper bound of adjust_f_range is reached
  if(F >= params.adjust_f_range.second) {
   F = params.adjust_f_range.second;
   if(params.verbosity >= 1)
    warning("Upper bound of adjust_f_range has been reached, will use F = " + std::to_string(F));
   break;
  }

  solution_worker<KernelType> worker(of,norm,ci,params,stop_callback,F);
  auto & rng = worker.get_rng();

  int n_sol;
  for(int i = 0; (n_sol = comm.rank() + i*comm.size()) < params.adjust_f_l; ++i) {
   if(params.verbosity >= 2) {
    std::cout << "[Node " << comm.rank() << "] Accumulation of particular solution "
              << n_sol << std::endl;
   }

   auto solution = worker(1 + rng(params.max_rects));
   double kappa = fq(solution);

   if(kappa > params.adjust_f_kappa) ++l_good;
   if(params.verbosity >= 2) {
    std::cout << "[Node " << comm.rank() << "] Particular solution "
              << n_sol << " is " << (kappa > params.adjust_f_kappa ? "" : "not ")
              << "good (\\kappa = " << kappa
              << ", D = " << worker.get_objf_value() << ")." << std::endl;
   }
  }
  comm.barrier();
  l_good = mpi_all_reduce(l_good,comm);

  if(params.verbosity >= 1)
   std::cout << "F = " << F << ", "
             << l_good<< " solutions with \\kappa > " << params.adjust_f_kappa
             << " (out of " << params.adjust_f_l << ")" << std::endl;

  // Converged
  if(l_good > params.adjust_f_l/2) {
   if(params.verbosity >= 1) std::cout << "F = " << F << " is enough." << std::endl;
   break;
  }
 }

 return F;
}
void ResultsJsInterface::showAnalysesMenu(QString options)
{
	Json::Value menuOptions;

	Json::Reader parser;
	parser.parse(fq(options), menuOptions);

	QIcon _copyIcon = QIcon(":/icons/copy.png");
	QIcon _citeIcon = QIcon(":/icons/cite.png");
	QIcon _codeIcon = QIcon(":/icons/code-icon.png");
	QIcon _collapseIcon = QIcon(":/icons/collapse.png");
	QIcon _expandIcon = QIcon(":/icons/expand.png");
	QIcon _saveImageIcon = QIcon(":/icons/document-save-as.png");
	QIcon _editImageIcon = QIcon(":/icons/editImage.png");

	_analysisMenu->clear();

	QString objName = tq(menuOptions["objectName"].asString());

	if (menuOptions["hasCollapse"].asBool())
	{
		Json::Value collapseOptions = menuOptions["collapseOptions"];
		QIcon icon = collapseOptions["collapsed"].asBool() ? _expandIcon : _collapseIcon;
		_analysisMenu->addAction(icon, tq(collapseOptions["menuText"].asString()), this, SLOT(collapseSelected()));
		_analysisMenu->addSeparator();
	}

	if (menuOptions["hasEditTitle"].asBool())
	{
		_analysisMenu->addAction("Edit Title", this, SLOT(editTitleSelected()));
		_analysisMenu->addSeparator();
	}

	if (menuOptions["hasCopy"].asBool())
		_analysisMenu->addAction(_copyIcon, "Copy", this, SLOT(copySelected()));

	if (menuOptions["hasLaTeXCode"].asBool())  // TODO: || menuOptions["hasPlainText"].asBool())
	{
		_copySpecialMenu = _analysisMenu->addMenu(tr("&Copy special"));

		_copySpecialMenu->addAction(_codeIcon, "LaTeX code", this, SLOT(latexCodeSelected()));

		QAction *copyTextAction = new QAction("Copy text");
		// connect(copyTextAction, SIGNAL(triggered), this, SLOT(copyTextSelected));
		copyTextAction->setEnabled(false);
		_copySpecialMenu->addAction(copyTextAction);
	}

	if (menuOptions["hasCite"].asBool())
	{
		_analysisMenu->addSeparator();
		_analysisMenu->addAction(_citeIcon, "Copy Citations", this, SLOT(citeSelected()));
	}

	if (menuOptions["hasSaveImg"].asBool())
	{
		_analysisMenu->addAction(_saveImageIcon, "Save Image As", this, SLOT(saveImage()));
	}
#ifdef JASP_DEBUG
    if (menuOptions["hasEditImg"].asBool())
    {
        _analysisMenu->addAction(_editImageIcon, "Edit Image", this, SLOT(editImage()));
    }
#endif

	if (menuOptions["hasNotes"].asBool())
	{
		_analysisMenu->addSeparator();

		Json::Value noteOptions = menuOptions["noteOptions"];

		for (Json::ValueIterator iter = noteOptions.begin(); iter != noteOptions.end(); iter++)
		{
			Json::Value noteOption = *iter;
			QAction *a1 = _analysisMenu->addAction(tq(noteOption["menuText"].asString()), this, SLOT(noteSelected()));

			a1->setDisabled(noteOption["visible"].asBool());


			QString call = QString("window.notesMenuClicked('%1', %2);").arg(tq(noteOption["key"].asString())).arg(noteOption["visible"].asBool() ? "false" : "true");

			a1->setData(call);
		}
	}


	if (menuOptions["hasRemove"].asBool())
	{
		_analysisMenu->addSeparator();
		_analysisMenu->addAction("Remove " + objName, this, SLOT(removeSelected()));
	}

	if (menuOptions["hasRemoveAllAnalyses"].asBool())
	{
		_analysisMenu->addSeparator();
		_analysisMenu->addAction("Remove All ", _mainWindow, SLOT(removeAllAnalyses()));
	}

	if (menuOptions["hasRefreshAllAnalyses"].asBool())
	{
		_analysisMenu->addSeparator();
		_analysisMenu->addAction("Refresh All ", _mainWindow, SLOT(refreshAllAnalyses()));
	}

	QPoint point = _webViewResults->mapToGlobal(QPoint(round(menuOptions["rX"].asInt() * _webViewZoom), round(menuOptions["rY"].asInt() * _webViewZoom)));

	_analysisMenu->move(point);
	_analysisMenu->show();
}
Exemple #13
0
/** Function duplicate_removal ()
 *
 * Input: a list of paired fastq files
 * Output: a list of paired fastq files with duplicate removed. If the
 * num of output files is equal to the input, then dupl removal is applied
 * to each input pair; otherwise, 2 paired fastq output files should be
 * specified, and the output are combined in these two files.
 *
 * Randomly mutate 'N's in each read into 'A'. This will
 * result in reads containing a small number of Ns being considered for
 * clustering whereas reads containing a lot of Ns will not be considered
 * anyway.
 */
void duplicate_removal (const strvec_t& ifqs, const drm_t& drm, int w,
		int w2, xny::low_complexity& lc, int batch, bool silent) {


	// sanity check
	if ((drm.op.size() != ifqs.size()) && (drm.op.size () != 2)) {
		abording ("duplicate_removal ofqs.size() != ifqs.size() and"
				"ofqs.size() != 2");
	}
	// first obtain the length of a read, double it to be fragment length
	std::ifstream fh_tmp;
	xny::openfile<std::ifstream>(fh_tmp, ifqs[0]);
	bio::fastq_input_iterator<> fq(fh_tmp);
	int frag_len = 2 * (std::get<1>(*fq)).length();
	xny::closefile(fh_tmp);

	// calculate the upper bound of mismatches can be tolerated,
	// number of seeds & seed length; max seed length will be bounded by 31
//	int ub_mismatch = std::min (drm.max_mismatch, frag_len * (100 - drm.perc_sim) /100),
	int ub_mismatch = frag_len * (100 - drm.perc_sim) /100,
		//num_seed = ub_mismatch + 1,
		seed_len = std::min(frag_len / (ub_mismatch + 1), 31);
		//num_seed = std::max(num_seed, frag_len/seed_len);

	//std::cout << max_mismatch << ", " << frag_len << ", " << perc_sim << "\n";
	//std::cout << "ub_mismatch = " << ub_mismatch << "\n";

	// process every pair of files
	int num_file_pairs = ifqs.size()/2;

	xny::sketch_list slistgen (w, false);
	xny::super_sketch ssgen (w2);

	std::ofstream ofhfq, ofhfq2;
	if (drm.op.size() == 2) {
		xny::openfile<std::ofstream> (ofhfq, drm.op[0]);
		xny::openfile<std::ofstream> (ofhfq2, drm.op[1]);
	}

	for (int i = 0; i < num_file_pairs; ++ i) {

		int fID = 2*i;

		if (! silent) {
			std::cout << "\tprocess files: " << ifqs[fID] << " and "
					<< ifqs[fID + 1] << "\n\n";
		}

		// --------------- generate seeds for each fragment -------------
		// ----------- a compressed form to represent fragments ---------
		if (! silent) std::cout << "\tgenerate seeds...\n";
		ii64vec_t list_seeds; // stores the list of seeds per fragment,
							  // the last element stores the fragment ID
		get_seeds (list_seeds, ifqs[fID], ifqs[fID + 1], seed_len,
				batch, silent);

		// ---- initialize the global union-find structure ----
		ivec_t uf_clst (list_seeds.size());
		for (unsigned int j = 0; j < list_seeds.size(); ++ j) uf_clst[j] = j;

		// ------------------ clustering via ss -------------------------

		if (! silent) std::cout << "\tclustering via super sketches ...\n";

		clustering_via_ss (uf_clst, list_seeds, ifqs[fID], ifqs[fID + 1],
				batch, slistgen, ssgen, ub_mismatch, silent);

		// --------------- clustering via seeds -----------------
		if (!silent) std::cout << "\tclustering via seeds ...\n";
		clustering_via_seeds (uf_clst, list_seeds, frag_len/seed_len,
				ub_mismatch, silent);


		// -------- generate final union find clusters --------------
		iivec_t clusters;
		uf_generate_cls (clusters, uf_clst);

		// ---- generate the duplicated fragment IDs ----------------
		iset_t duplIDs; // duplicate fragIDs
		int debug_counter = 0;
		for (int j = 0; j < (int) clusters.size(); ++ j) {
			duplIDs.insert(clusters[j].begin() + 1, clusters[j].end());

			/*{ // debug code print out clusters
				if (clusters[j].size() > 100) {
					debug_print_fragments (clusters[j], ifqs[fID], ifqs[fID+1]);
					++ debug_counter;
					if (debug_counter > 10) exit(1);
				}
			}*/
		}
		clusters.clear();

		if (!silent) std::cout << "\n\t\tnum duplicate frags: " << duplIDs.size()
				<< "(" << 100 * duplIDs.size()/ list_seeds.size() << "% total)" << "\n\n";

		if (!silent) std::cout << "\toutput non-redundant read-pairs...\n";

		// ----- output non-redundant read-pairs ---------
		if (drm.op.size() > 2) {

			xny::openfile<std::ofstream> (ofhfq, drm.op[fID]);
			xny::openfile<std::ofstream> (ofhfq2, drm.op[fID + 1]);
		}

		clean_dupl_frag (ifqs[fID], ifqs[fID+1], ofhfq, ofhfq2,
				 duplIDs, lc, batch);

		if (drm.op.size() > 2) {
			xny::closefile(ofhfq);
			xny::closefile(ofhfq2);
		}

	} // for (int i = 0

} // duplicate_removal
QString OnlineDataManager::getLocalPath(QString nodePath) const {

    QString name = QString(QCryptographicHash::hash(nodePath.toLatin1(),QCryptographicHash::Md5).toHex());
    std::string tempFile = tempfiles_createSpecific("online", fq(name));
    return tq(tempFile);
}
void TextModelLavaan::apply()
{
	//checkEverything();
	if (_boundTo != NULL && inError() == false)
		_boundTo->setValue(fq(this->toPlainText()));
}
void BoundTableWidget::updateTableValues(bool noSignal)
{
	if (_boundTo == NULL) {
		return;
	}

	int columnCount = this->columnCount();
	int rowCount = this->rowCount();

	_groups.clear();
	std::vector<std::string> verticalHeaders;

	// Get verticalHeaders
	for (int i = 0; i < rowCount; ++i) {
		QTableWidgetItem *verticalHeaderItem = this->verticalHeaderItem(i);
		QString header = "";
		if (verticalHeaderItem != NULL) {
			header = verticalHeaderItem->toolTip();  // Tooltip will have the entire text
		}
		verticalHeaders.push_back(fq(header));
	}

	for (int i = 0; i < columnCount; ++i) {
		Options *newRow = static_cast<Options *>(_boundTo->rowTemplate()->clone());
		OptionString *factorName = static_cast<OptionString *>(newRow->get("name"));
		QString header = "";
		QTableWidgetItem *horizontalHeaderItem = this->horizontalHeaderItem(i);

		if (horizontalHeaderItem != NULL) {
			header = horizontalHeaderItem->text();
		} else {
			// TODO: Revisit this part
			continue;
		}
		factorName->setValue(fq(header));

		OptionDoubleArray *option = static_cast<OptionDoubleArray *>(newRow->get("values"));
		OptionVariables *headers = static_cast<OptionVariables *>(newRow->get("levels"));
		headers->setValue(verticalHeaders);
		std::vector<double> values;
		std::vector<std::string> levels;

		for (int j = 0; j < rowCount; ++j) {
			QTableWidgetItem *rowItem = this->item(j, i);
			QString content = "";

			if (rowItem != NULL) {
				content = rowItem->text();
			}
			values.push_back(content.toDouble());
		}

		option->setValue(values);
		_groups.push_back(newRow);
	}

	if (noSignal)
		_boundTo->blockSignals(true);
	_boundTo->setValue(_groups);
	if (noSignal)
		_boundTo->blockSignals(false, false);
}