/**
 * @brief
 *
 */
void SalomeOptimizationDialog::on_noIterationsLineEdit_editingFinished()
{
    resetColumns();
    _noIterations = ui->noIterationsLineEdit->text().toInt();
    addColumns();
    updateHeader();
}
예제 #2
0
void EGS_ParticleTrackContainer::flushBuffer() {
    int save = 0;
    if ( m_trspFile ) {
        for (int i = 0; i < m_nTracks; i++) {
            // if the particle is not being scored anymore
            if (!m_isScoring[i]) {
                // output it to the file and free memory
                if (!m_buffer[i]->writeTrack(m_trspFile)) m_totalTracks++;
                m_buffer[i]->clearTrack();
            } else {
                // still scoring it -> save the particle
                m_buffer[save] = m_buffer[i];
                m_isScoring[i] = false;
                m_isScoring[save] = true;
                for (int idx = 0; idx < m_bufferSize; idx++) {
                    if (m_stackMap[idx] == i) {
                        m_stackMap[idx] = save;
                        break;
                    }
                }
                save++;
            }
        }
        updateHeader();
    }
    m_nTracks = save;
}
예제 #3
0
int DiskMultiMap::erase(const std::string& key, const std::string& value, const std::string& context){
    
    Header head;
    m_bf.read(head, 0);
    
    size_t hashedKey = hashKey(key);
    int index = hashToOffset(hashedKey);
    HashTableBucket bucket;
    m_bf.read(bucket, index); //read to proper bucket
    
    Node node;
    int address = bucket.m_start;
    
    int deletedBuckets = 0;
    
    while(address != -1){
        m_bf.read(node, address); //go through bucket
        int nextIndex = node.m_next;
        
        string m_Key = node.m_key; string m_Value = node.m_value; string m_Context = node.m_context;
        if(m_Key == key && m_Value == value && m_Context == context){
            
            deletedBuckets++;
            
            int temp = head.m_deleted; //keep track of the prior deleted node location
            head.m_deleted = address; //update the deleted location for the Header
            node.m_next = temp; //update the nodes next position
            
            updateNode(node, address);
            updateHeader(head);
        }
        address = nextIndex;
    }
    return deletedBuckets;
}
예제 #4
0
int MRC::createMRC(short *data, int nx, int ny, int nz)
{
	m_header.nx=nx;
	m_header.ny=ny;
	m_header.nz=nz;
	m_header.mode=1;
	m_header.cellb[0]=90;
	m_header.cellb[1]=90;
	m_header.cellb[2]=90;
	m_header.mapc=1;
	m_header.mapr=2;
	m_header.maps=3;
	size_t i,size=nx*ny*nz;
	short min=data[0],max=data[0];
	double mean=0;
	for(i=0;i<size;i++)
	{
		if(min>data[i]) min=data[i];
		if(max<data[i]) max=data[i];
		mean+=data[i];
	}
	mean/=size;
	m_header.dmin=min;
	m_header.dmax=max;
	m_header.dmean=mean;
	updateHeader();
	
	size_t ImSize=size*sizeof(short);
	size_t offset=1024+getSymdatasize();
	if(fseek(m_fp, offset, SEEK_SET)!=0) return 0;
	return fwrite(data, 1, ImSize, m_fp);
}
예제 #5
0
void CSXParser::importCsx(std::string origCsxFilename, std::string tlCsxFilename, std::deque<std::string> utfFilenames) {
    std::cout << "Parsing CSX..." << std::endl;
    parseCsx(origCsxFilename);
    std::cout << "Extracting scenario..." << std::endl;
    image.extractStrings();
    std::cout << "Scenario has " << image.messages.size() << " messages and " << image.choices.size() << " choices." << std::endl;
    std::cout << "Parsing TXT files..." << std::endl;
    TxtParser txt;
    TxtParser::Stats totalStats;
    for (size_t i = 0; i < utfFilenames.size(); ++i) {
        TxtParser::Stats fileStats = txt.parseTxt(utfFilenames[i]);
        totalStats += fileStats;
        std::cout << "File " << utfFilenames[i] << ": " << fileStats << std::endl;
    }
    std::cout << "Total: " << totalStats << std::endl;
    std::cout << "Updating scenario..." << std::endl;
    image.substituteStrings(txt.messages, txt.choices);
    std::cout << "Updating short jump offsets..." << std::endl;
    image.updateShortHops();
    std::cout << "Updating long jump offsets..." << std::endl;
    function.updateOffsets(image.positionsComputer());
    std::cout << "Updating header..." << std::endl;
    updateHeader();
    std::cout << "Writing CSX file..." << std::endl;
    writeCsx(tlCsxFilename);
}
예제 #6
0
void RawCameraDlg::slotSearchTextChanged(const SearchTextSettings& settings)
{
    bool query     = false;
    int  results   = 0;
    QString search = settings.text.toLower();

    QTreeWidgetItemIterator it(listView());

    while (*it)
    {
        QTreeWidgetItem* const item  = *it;

        if (item->text(0).toLower().contains(search, settings.caseSensitive))
        {
            ++results;
            query = true;
            item->setHidden(false);
        }
        else
        {
            item->setHidden(true);
        }

        ++it;
    }

    updateHeader(results);
    d->searchBar->slotSearchResult(query);
}
예제 #7
0
RawCameraDlg::RawCameraDlg(QWidget* const parent)
    : InfoDlg(parent),
      d(new Private)
{
    setWindowTitle(i18n("List of supported RAW cameras"));

    QStringList list = RawEngine::DRawDecoder::supportedCamera();

    // --------------------------------------------------------

    d->header    = new QLabel(this);
    d->searchBar = new SearchTextBar(this, QLatin1String("RawCameraDlgSearchBar"));
    updateHeader();

    listView()->setColumnCount(1);
    listView()->setHeaderLabels(QStringList() << QLatin1String("Camera Model")); // Header is hidden. No i18n here.
    listView()->header()->hide();

    for (QStringList::const_iterator it = list.constBegin() ; it != list.constEnd() ; ++it)
    {
        new QTreeWidgetItem(listView(), QStringList() << *it);
    }

    // --------------------------------------------------------

    QGridLayout* const  grid = dynamic_cast<QGridLayout*>(mainWidget()->layout());
    grid->addWidget(d->header,    1, 0, 1, -1);
    grid->addWidget(d->searchBar, 3, 0, 1, -1);

    // --------------------------------------------------------

    connect(d->searchBar, SIGNAL(signalSearchTextSettings(SearchTextSettings)),
            this, SLOT(slotSearchTextChanged(SearchTextSettings)));
}
예제 #8
0
void DocumentListSelectionPage::updateFinished()
{
    largeDocuments->clear();

    selectedSize = 0;
    selectedDocuments = 0;
    for (int i = 0; i < documents->count(); i++) {
        const QContent content = documents->content(i);
        if (content.size() >= field("documentsTypeSelectionPage_minimumSize").toInt() * 1024) {
            largeDocuments->add(content);

            selectedSize += content.size();
            selectedDocuments++;
        }
    }

    list->resizeColumnsToContents();
    list->setColumnWidth(0, list->viewport()->size().width() - list->columnWidth(1) - 10);
    list->setCurrentIndex(largeModel->index(0, 0));

    updateHeader();

    if (waitWidget) {
        delete waitWidget;
        waitWidget = 0;
    }
}
예제 #9
0
void ImportCsvDialogue::changeColumnIndex(QTreeWidgetItem *item)
{
    item->setText(1, QString::number(
            QInputDialog::getInt(this, tr("Change column index"),
                                 tr("Index of column %1 (zero if not present):").arg(item->text(0)),
                                 item->text(1).toInt(), 0, tw_content->columnCount())));
    updateHeader();
}
예제 #10
0
int bamsplit(libmaus2::util::ArgInfo const & arginfo)
{
	if ( isatty(STDIN_FILENO) )
	{
		::libmaus2::exception::LibMausException se;
		se.getStream() << "Refusing read binary data from terminal, please redirect standard input to pipe or file." << std::endl;
		se.finish();
		throw se;
	}

	int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel()));
	int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
	uint64_t const n = arginfo.getValue<int>("n",getDefaultN());
	std::string const prefix = arginfo.getUnparsedValue("prefix",getDefaultFilePrefix(arginfo));

	libmaus2::bambam::BamDecoder bamdec(std::cin);
	libmaus2::bambam::BamAlignment const & algn = bamdec.getAlignment();
	libmaus2::bambam::BamHeader const & header = bamdec.getHeader();
	::libmaus2::bambam::BamHeader::unique_ptr_type uphead(updateHeader(arginfo,header));

	libmaus2::aio::OutputStreamInstance::unique_ptr_type COS;
	libmaus2::bambam::BamWriter::unique_ptr_type writer;

	uint64_t c = 0;
	uint64_t f = 0;
	while ( bamdec.readAlignment() )
	{
		if ( c++ % n == 0 )
		{
			writer.reset();
			if ( COS )
				COS->flush();
			COS.reset();

			std::ostringstream fnostr;
			fnostr << prefix << "_" << std::setw(6) << std::setfill('0') << f++ << std::setw(0) << ".bam";
			std::string const fn = fnostr.str();

			libmaus2::aio::OutputStreamInstance::unique_ptr_type tCOS(new libmaus2::aio::OutputStreamInstance(fn));
			COS = UNIQUE_PTR_MOVE(tCOS);

			libmaus2::bambam::BamWriter::unique_ptr_type twriter(new libmaus2::bambam::BamWriter(*COS,*uphead,level));
			writer = UNIQUE_PTR_MOVE(twriter);

			if ( verbose )
				std::cerr << "[V] opened file " << fn << std::endl;
		}

		algn.serialise(writer->getStream());
	}

	writer.reset();
	if ( COS )
		COS->flush();
	COS.reset();

	return EXIT_SUCCESS;
}
예제 #11
0
void InstrumentTree::updateModel()
{
    if(!m_instrument)
    {
        _patchModel->clear();
        return;
    }
    m_instrument->populatePatchModel(_patchModel, 0, song->mtype(), false);
    updateHeader();
}
예제 #12
0
void PackagesPage::onPackageAdd()
{
    PackageDialog* dlg = new PackageDialog(_model, this);
    if(dlg->exec()==QDialog::Accepted)
    {
        _model->select();
        _ui->_listPackages->scrollToBottom();
        updateHeader();
    }
    delete dlg;
}
void ALFloaterRegionTracker::removeRegions()
{
	typedef std::vector<LLScrollListItem*> item_t;
	item_t items = mRegionScrollList->getAllSelected();
	for (item_t::const_iterator it = items.begin(); it != items.end(); ++it)
	{
		mRegionMap.erase((*it)->getValue().asString());
	}
	mRegionScrollList->deleteSelectedItems();
	saveToJSON();
	updateHeader();
}
예제 #14
0
void PackagesPage::onEditPackage(QModelIndex index)
{
    PackageDialog* dlg = new PackageDialog(_model, this);
    dlg->setData(index);
    if(dlg->exec()==QDialog::Accepted)
    {
        _model->select();
        _ui->_listPackages->scrollToBottom();
        updateHeader();
    }
    delete dlg;
}
예제 #15
0
 void Soundfile::blank(double duration)
 {
   seekSeconds(0.0);
   std::vector<double> frame;
   frame.resize(getChannelsPerFrame());
   int framesToWrite = int(duration * getFramesPerSecond());
   for (int i = 0; i < framesToWrite; i++) {
     sf_writef_double(sndfile, &frame.front(), 1);
   }
   updateHeader();
   seekSeconds(0.0);
 }
예제 #16
0
//_______________________________________________________
// End movie
//_______________________________________________________
uint8_t aviWrite::setEnd (void)
{

  // First close the movie
  LMovie->End ();
  delete LMovie;
  LMovie = NULL;



  printf ("\n writing %lu index parts", curindex);
  printf ("\n received %lu video parts", vframe);

// Updating compared to what has been really written
//

  // Write index  
  LAll->Write32 ("idx1");
  LAll->Write32 (curindex * 16);

  for (uint32_t i = 0; i < curindex; i++)
    {
      LAll->Write32 (myindex[i].fcc);
      LAll->Write32 (myindex[i].flags);
      LAll->Write32 (myindex[i].offset);	// abs position
      LAll->Write32 (myindex[i].len);
    }
  // Close movie


  LAll->End ();
  delete
    LAll;
  LAll = NULL;
 printf ("\n Updating headers...\n");
  _mainheader.dwTotalFrames = vframe;
  _videostream.dwLength = vframe;
  //astream.dwLength = asize;

// Update Header
  updateHeader (&_mainheader, &_videostream, NULL);


	printf("\n End of movie, \n video frames : %lu\n audio frames : %lu",vframe,asize);
  // need to update headers now
  // AUDIO SIZE ->TODO

  fclose (_out);
  _out = NULL;
  return 1;

}
예제 #17
0
bool DiskMultiMap::insert(const std::string& key, const std::string& value, const std::string& context){
    
    if(key.size() > 120 || value.size() > 120 || context.size() > 120){
        return false;
    }
    
    MultiMapTuple tuple;
    tuple.key = key;
    tuple.value = value;
    tuple.context = context;
    
    Node nodeToAdd(tuple);
    int lastNode = -1; //this is to track the deleted nodes
    
    size_t index_hash = hashKey(key);
    int bucketIndex = hashToOffset(index_hash);
    HashTableBucket bucket;
    m_bf.read(bucket, bucketIndex);
    
    Header head;
    m_bf.read(head, 0);
    
    string k = nodeToAdd.m_key;
    string v = nodeToAdd.m_value;
    string c = nodeToAdd.m_context;
    
    if(head.m_deleted == -1){
        lastNode = head.m_tail;
        head.m_tail += sizeof(Node);
    }else{
        lastNode = head.m_deleted;
        Node newNode;
        m_bf.read(newNode, head.m_deleted);
        head.m_deleted = newNode.m_next;
    }
    
    nodeToAdd.m_next = bucket.m_start;
    bucket.m_start = lastNode;
    
    updateBucket(bucket, bucketIndex);
    
    if(!updateHeader(head)){
        return false;
    }
    
    if(updateNode(nodeToAdd, lastNode)){
        return true;
    }else{
        return false;
    }
}
예제 #18
0
bool ADM_audioWriteWav::close(void)
{
    if(_file)
    {
        updateHeader();
    }
    if(writter)
    {
        writter->end();
        delete writter;
        writter=NULL;
    }
    return ADM_audioWrite::close();
}
예제 #19
0
void MediaView::updateControls() {
	if (!_photo) return;

	_close.show();
	if (_photo->full->loaded()) {
		_save.show();
	} else {
		_save.hide();
	}
	if (_history) {
		HistoryItem *item = App::histItemById(_msgid);
		if (dynamic_cast<HistoryMessage*>(item)) {
			_forward.show();
		} else {
			_forward.hide();
		}
		_delete.show();
	} else {
		_forward.hide();
		if ((App::self() && _photo && App::self()->photoId == _photo->id) || (_photo->chat && _photo->chat->photoId == _photo->id)) {
			_delete.show();
		} else {
			_delete.hide();
		}
	}
	QDateTime d(date(_photo->date)), dNow(date(unixtime()));
	if (d.date() == dNow.date()) {
		_dateText = lang(lng_status_lastseen_today).replace(qsl("{time}"), d.time().toString(qsl("hh:mm")));
	} else if (d.date().addDays(1) == dNow.date()) {
		_dateText = lang(lng_status_lastseen_yesterday).replace(qsl("{time}"), d.time().toString(qsl("hh:mm")));
	} else {
		_dateText = lang(lng_status_lastseen_date_time).replace(qsl("{date}"), d.date().toString(qsl("dd.MM.yy"))).replace(qsl("{time}"), d.time().toString(qsl("hh:mm")));
	}
	int32 nameWidth = _from->nameText.maxWidth(), maxWidth = _delete.x() - _forward.x() - _forward.width(), dateWidth = st::medviewDateFont->m.width(_dateText);
	if (nameWidth > maxWidth) {
		nameWidth = maxWidth;
	}
	_nameNav = QRect(_forward.x() + _forward.width() + (maxWidth - nameWidth) / 2, _forward.y() + st::medviewNameTop, nameWidth, st::msgNameFont->height);
	_dateNav = QRect(_forward.x() + _forward.width() + (maxWidth - dateWidth) / 2, _forward.y() + st::medviewDateTop, dateWidth, st::medviewDateFont->height);
	updateHeader();
	_leftNavVisible = (_index > 0 || (_index == 0 && _history && _history->_photosOverview.size() < _history->_photosOverviewCount));
	_rightNavVisible = (_index >= 0 && (
		(_history && _index + 1 < _history->_photosOverview.size()) ||
		(_user && (_index + 1 < _user->photos.size() || _index + 1 < _user->photosCount))));
	updateOver(mapFromGlobal(QCursor::pos()));
	update();
}
예제 #20
0
void ImportCsvDialogue::load()
{
    QString encoding = cb_encoding->itemData(cb_encoding->currentIndex(), Qt::UserRole).toString();
    QTextCodec *codec = NULL;
    if (encoding != "System") {
        codec = QTextCodec::codecForName(encoding.toUtf8());
    } else {
        codec = QTextCodec::codecForLocale();
    }

    QFile file(file_path);
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
        QMessageBox::critical(this, tr("Import CSV - Leaklog"), tr("Cannot read file %1:\n%2.").arg(file_path).arg(file.errorString()));
        reject();
        return;
    }

    QTextStream in(&file);
    in.setCodec(codec);

    MTCSVParser parser(&in);
    parser.setSkipLines(spb_skip_lines->value());
    parser.setFieldSeparator(cb_separator->itemData(cb_separator->currentIndex(), Qt::UserRole).toChar());

    file_content.clear();
    int num_columns = 0, num_rows = 0;
    while (parser.hasNextRow()) {
        QStringList row = parser.nextRow();
        file_content << row;
        if (num_columns < row.count())
            num_columns = row.count();
        num_rows++;
    }

    tw_content->clear();
    tw_content->setColumnCount(num_columns);
    tw_content->setRowCount(num_rows);
    for (int r = 0; r < num_rows; ++r) {
        for (int c = 0; c < num_columns; ++c) {
            tw_content->setItem(r, c, new QTableWidgetItem(c >= file_content.at(r).count() ? "-----" : file_content.at(r).at(c)));
        }
    }

    updateHeader();

    id_bb->button(QDialogButtonBox::Ok)->setEnabled(true);
}
예제 #21
0
LCMSBOOL cmmSetProfileHeader(LPLCMSICCPROFILE hProfile, LPBYTE data) {

  seekMemBuffer(hProfile->stream, 0);

  writeMemBuffer(hProfile->stream, sizeof(icHeader), data);

  

  if(!updateHeader(hProfile))

    return FALSE;



  return TRUE;

}
예제 #22
0
void DocumentListSelectionPage::dataChanged(const QModelIndex &topLeft,
                                            const QModelIndex &bottomRight)
{
    for (int i = topLeft.row(); i <= bottomRight.row(); i++) {
        QModelIndex index = largeModel->index(i, 0);

        qint64 fileSize = largeModel->content(index).size();

        if (largeModel->data(index, Qt::CheckStateRole) == Qt::Checked) {
            selectedSize += fileSize;
            selectedDocuments++;
        } else {
            selectedSize -= fileSize;
            selectedDocuments--;
        }
    }

    updateHeader();
}
BOOL ALFloaterRegionTracker::postBuild()
{
	mRefreshRegionListBtn = getChild<LLButton>("refresh");
	mRefreshRegionListBtn->setClickedCallback(boost::bind(&ALFloaterRegionTracker::refresh, this));

	mRemoveRegionBtn = getChild<LLButton>("remove");
	mRemoveRegionBtn->setClickedCallback(boost::bind(&ALFloaterRegionTracker::removeRegions, this));

	mOpenMapBtn = getChild<LLButton>("open_map");
	mOpenMapBtn->setClickedCallback(boost::bind(&ALFloaterRegionTracker::openMap, this));

	mRegionScrollList = getChild<LLScrollListCtrl>("region_list");
	mRegionScrollList->setCommitOnSelectionChange(TRUE);
	mRegionScrollList->setCommitCallback(boost::bind(&ALFloaterRegionTracker::updateHeader, this));
	mRegionScrollList->setDoubleClickCallback(boost::bind(&ALFloaterRegionTracker::openMap, this));

	updateHeader();

	return LLFloater::postBuild();
}
예제 #24
0
void PlaybackFile::close() {
	delete _readStream;
	_readStream = NULL;
	if (_writeStream != NULL) {
		dumpRecordsToFile();
		_writeStream->finalize();
		delete _writeStream;
		_writeStream = NULL;
		updateHeader();
	}
	if (_screenshotsFile != NULL) {
		_screenshotsFile->finalize();
		delete _screenshotsFile;
		_screenshotsFile = NULL;
	}
	for (HashMap<String, SaveFileBuffer>::iterator  i = _header.saveFiles.begin(); i != _header.saveFiles.end(); ++i) {
		free(i->_value.buffer);
	}
	_header.saveFiles.clear();
	_mode = kClosed;
}
예제 #25
0
int main(int argc, char * argv[])
{
	try
	{
		libmaus::util::ArgInfo const arginfo(argc,argv);

		std::vector<std::string> const & inputfilenames = arginfo.restargs;
		libmaus::bambam::BamMergeCoordinate bamdec(inputfilenames /* ,true */);
		libmaus::bambam::BamAlignment const & algn = bamdec.getAlignment();
		libmaus::bambam::BamHeader const & header = bamdec.getHeader();
		::libmaus::bambam::BamHeader::unique_ptr_type uphead(updateHeader(arginfo,header));
		libmaus::bambam::BamWriter writer(std::cout,*uphead);
		libmaus::bambam::BamWriter::stream_type & bamoutstr = writer.getStream();
		while ( bamdec.readAlignment() )
			algn.serialise(bamoutstr);
	}
	catch(std::exception const & ex)
	{
		std::cerr << ex.what() << std::endl;
		return EXIT_FAILURE;
	}
}
예제 #26
0
void ImportCsvDialogue::loadTableColumns(int index)
{
    trw_columns->clear();
    ImportDialogueTable *table = tables.at(index);
    current_table = table;
    if (!table) return;

    int n = 1;
    for (int i = 0; i < table->count(); ++i) {
        trw_columns->addTopLevelItem(columnItem(table->at(i)->name(), table->at(i)->id(), n));
    }

    for (int i = 0; i < table->childTablesCount(); ++i) {
        for (int k = 0; k < table->childTableAt(i)->count(); ++k) {
            trw_columns->addTopLevelItem(columnItem(table->childTableAt(i)->at(k)->name(), table->childTableAt(i)->at(k)->id(), n));
        }
    }

    QMenu *menu = btn_add_linked_table->menu();
    if (menu) {
        menu->clear();
    } else {
        menu = new QMenu(btn_add_linked_table);
        btn_add_linked_table->setMenu(menu);
        btn_add_linked_table->setPopupMode(QToolButton::InstantPopup);
        QObject::connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(addLinkedTable(QAction*)));
    }

    for (int i = 0; i < table->childTemplatesCount(); ++i) {
        QAction *action = new QAction(table->childTemplateAt(i)->name(), menu);
        action->setData(i);
        menu->addAction(action);
    }

    updateHeader();
}
예제 #27
0
int bamsplitmod(libmaus::util::ArgInfo const & arginfo)
{
    if ( isatty(STDIN_FILENO) )
    {
        ::libmaus::exception::LibMausException se;
        se.getStream() << "Refusing read binary data from terminal, please redirect standard input to pipe or file." << std::endl;
        se.finish();
        throw se;
    }

    int const level = libmaus::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel()));
    int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
    uint64_t const div = arginfo.getValue<int>("div",getDefaultDiv());
    std::string const prefix = arginfo.getUnparsedValue("prefix",getDefaultFilePrefix(arginfo));

    if ( ! div )
    {
        ::libmaus::exception::LibMausException se;
        se.getStream() << "div cannot be 0." << std::endl;
        se.finish();
        throw se;
    }

    libmaus::bambam::BamDecoder bamdec(std::cin);
    libmaus::bambam::BamAlignment const & algn = bamdec.getAlignment();
    libmaus::bambam::BamHeader const & header = bamdec.getHeader();
    ::libmaus::bambam::BamHeader::unique_ptr_type uphead(updateHeader(arginfo,header));

    libmaus::autoarray::AutoArray<libmaus::aio::CheckedOutputStream::unique_ptr_type> COS(div);
    libmaus::autoarray::AutoArray<libmaus::bambam::BamWriter::unique_ptr_type> writers(div);
    std::vector < std::string > filenames;
    for ( uint64_t i = 0; i < div; ++i )
    {
        std::ostringstream ostr;
        ostr << prefix << "_" << std::setw(6) << std::setfill('0') << i << std::setw(0) << ".bam";

        libmaus::aio::CheckedOutputStream::unique_ptr_type tCOS(new libmaus::aio::CheckedOutputStream(ostr.str()));
        COS[i] = UNIQUE_PTR_MOVE(tCOS);
        libmaus::bambam::BamWriter::unique_ptr_type twriter(new libmaus::bambam::BamWriter(*COS[i],*uphead,level));
        writers[i] = UNIQUE_PTR_MOVE(twriter);
    }

    uint64_t c = 0;
    if ( verbose )
    {
        while ( bamdec.readAlignment() )
        {
            algn.serialise ( writers [ (c++) % div ] -> getStream() );

            if ( ((c) & ((1ull<<20)-1)) == 0 )
                std::cerr << "[V] " << c << std::endl;
        }
        std::cerr << "[V] " << c << std::endl;
    }
    else
    {
        while ( bamdec.readAlignment() )
            algn.serialise ( writers [ (c++) % div ] -> getStream() );
    }

    for ( uint64_t i = 0; i < div; ++i )
    {
        writers[i].reset();
        COS[i]->flush();
        COS[i].reset();
    }

    return EXIT_SUCCESS;
}
예제 #28
0
파일: bamcat.cpp 프로젝트: dozy/biobambam
int bamcat(libmaus::util::ArgInfo const & arginfo)
{
	if ( isatty(STDOUT_FILENO) )
	{
		::libmaus::exception::LibMausException se;
		se.getStream() << "Refusing write binary data to terminal, please redirect standard output to pipe or file." << std::endl;
		se.finish();
		throw se;
	}

	int const level = arginfo.getValue<int>("level",getDefaultLevel());
	int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
	
	switch ( level )
	{
		case Z_NO_COMPRESSION:
		case Z_BEST_SPEED:
		case Z_BEST_COMPRESSION:
		case Z_DEFAULT_COMPRESSION:
			break;
		default:
		{
			::libmaus::exception::LibMausException se;
			se.getStream()
				<< "Unknown compression level, please use"
				<< " level=" << Z_DEFAULT_COMPRESSION << " (default) or"
				<< " level=" << Z_BEST_SPEED << " (fast) or"
				<< " level=" << Z_BEST_COMPRESSION << " (best) or"
				<< " level=" << Z_NO_COMPRESSION << " (no compression)" << std::endl;
			se.finish();
			throw se;
		}
			break;
	}

	std::vector<std::string> inputfilenames = arginfo.getPairValues("I");
	
	for ( uint64_t i = 0; i < arginfo.restargs.size(); ++i )
		inputfilenames.push_back(arginfo.restargs[i]);
	
	libmaus::bambam::BamCat bamdec(inputfilenames /* ,true */);
	libmaus::bambam::BamAlignment const & algn = bamdec.getAlignment();
	libmaus::bambam::BamHeader const & header = bamdec.getHeader();
	::libmaus::bambam::BamHeader::unique_ptr_type uphead(updateHeader(arginfo,header));

	/*
	 * start index/md5 callbacks
	 */
	std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
	std::string const tmpfileindex = tmpfilenamebase + "_index";
	::libmaus::util::TempFileRemovalContainer::addTempFile(tmpfileindex);

	std::string md5filename;
	std::string indexfilename;

	std::vector< ::libmaus::lz::BgzfDeflateOutputCallback * > cbs;
	::libmaus::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
	if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
	{
		if ( arginfo.hasArg("md5filename") &&  arginfo.getUnparsedValue("md5filename","") != "" )
			md5filename = arginfo.getUnparsedValue("md5filename","");
		else
			std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;

		if ( md5filename.size() )
		{
			::libmaus::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus::lz::BgzfDeflateOutputCallbackMD5);
			Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
			cbs.push_back(Pmd5cb.get());
		}
	}
	libmaus::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
	if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
	{
		if ( arginfo.hasArg("indexfilename") &&  arginfo.getUnparsedValue("indexfilename","") != "" )
			indexfilename = arginfo.getUnparsedValue("indexfilename","");
		else
			std::cerr << "[V] no filename for index given, not creating index" << std::endl;

		if ( indexfilename.size() )
		{
			libmaus::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
			Pindex = UNIQUE_PTR_MOVE(Tindex);
			cbs.push_back(Pindex.get());
		}
	}
	std::vector< ::libmaus::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
	if ( cbs.size() )
		Pcbs = &cbs;
	/*
	 * end md5/index callbacks
	 */


	::libmaus::bambam::BamWriter::unique_ptr_type writer(new ::libmaus::bambam::BamWriter(std::cout,*uphead,level,Pcbs));
	libmaus::bambam::BamWriter::stream_type & bamoutstr = writer->getStream();
	if ( verbose )
	{
		uint64_t c = 0;
		while ( bamdec.readAlignment() )
		{
			algn.serialise(bamoutstr);
			
			if ( ((++c) & ((1ull<<20)-1)) == 0 )
				std::cerr << "[V] " << c << std::endl;
		}
		
		std::cerr << "[V] " << c << std::endl;
	}
	else
		while ( bamdec.readAlignment() )
			algn.serialise(bamoutstr);

	writer.reset();

	if ( Pmd5cb )
	{
		Pmd5cb->saveDigestAsFile(md5filename);
	}
	if ( Pindex )
	{
		Pindex->flush(std::string(indexfilename));
	}

	return EXIT_SUCCESS;
}
예제 #29
0
 VarTreeModel::VarTreeModel() : QStandardItemModel()
 {
   resetViewOptions();
   updateHeader();
 }
예제 #30
0
int bamrecalculatecigar(libmaus2::util::ArgInfo const & arginfo)
{
	if ( isatty(STDOUT_FILENO) )
	{
		::libmaus2::exception::LibMausException se;
		se.getStream() << "Refusing write binary data to terminal, please redirect standard output to pipe or file." << std::endl;
		se.finish();
		throw se;
	}

	int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
	// input decoder wrapper
	libmaus2::bambam::BamAlignmentDecoderWrapper::unique_ptr_type decwrapper(
		libmaus2::bambam::BamMultiAlignmentDecoderFactory::construct(
			arginfo,false // put rank
		)
	);

	libmaus2::bambam::BamAlignmentDecoder & bamdec = decwrapper->getDecoder();
	libmaus2::bambam::BamAlignment & algn = bamdec.getAlignment();
	libmaus2::bambam::BamHeader const & header = bamdec.getHeader();
	::libmaus2::bambam::BamHeader::unique_ptr_type uphead(updateHeader(arginfo,header));

	/*
	 * start index/md5 callbacks
	 */
	std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
	std::string const tmpfileindex = tmpfilenamebase + "_index";
	::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);

	std::string md5filename;
	std::string indexfilename;

	std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
	::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
	if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
	{
		if ( arginfo.hasArg("md5filename") &&  arginfo.getUnparsedValue("md5filename","") != "" )
			md5filename = arginfo.getUnparsedValue("md5filename","");
		else
			std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;

		if ( md5filename.size() )
		{
			::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
			Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
			cbs.push_back(Pmd5cb.get());
		}
	}
	libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
	if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
	{
		if ( arginfo.hasArg("indexfilename") &&  arginfo.getUnparsedValue("indexfilename","") != "" )
			indexfilename = arginfo.getUnparsedValue("indexfilename","");
		else
			std::cerr << "[V] no filename for index given, not creating index" << std::endl;

		if ( indexfilename.size() )
		{
			libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
			Pindex = UNIQUE_PTR_MOVE(Tindex);
			cbs.push_back(Pindex.get());
		}
	}
	std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
	if ( cbs.size() )
		Pcbs = &cbs;
	/*
	 * end md5/index callbacks
	 */

	libmaus2::bambam::BamBlockWriterBase::unique_ptr_type writer(
		libmaus2::bambam::BamBlockWriterBaseFactory::construct(*uphead, arginfo, Pcbs)
	);

	libmaus2::autoarray::AutoArray<libmaus2::bambam::cigar_operation> cigopin;
	libmaus2::autoarray::AutoArray<char> readdata;
	libmaus2::bambam::BamAlignment::D_array_type T;

	if ( ! arginfo.hasArg("reference") )
	{
		libmaus2::exception::LibMausException se;
		se.getStream() << "reference key is missing." << std::endl;
		se.finish();
		throw se;
	}

	std::string const reference = arginfo.getUnparsedValue("reference","");

	if ( ! libmaus2::util::GetFileSize::fileExists(reference) )
	{
		libmaus2::exception::LibMausException se;
		se.getStream() << "file " << reference << " does not exist." << std::endl;
		se.finish();
		throw se;
	}

	libmaus2::fastx::FastAIndex::unique_ptr_type FAindex(libmaus2::fastx::FastAIndex::load(reference + ".fai"));
	libmaus2::aio::InputStreamInstance FAISI(reference);

	uint64_t c = 0;
	libmaus2::autoarray::AutoArray<char> ref;
	int64_t refloaded = -1;

	while ( bamdec.readAlignment() )
	{
		if ( algn.isMapped() )
		{
			assert ( algn.getRefID() >= 0 );
			if ( algn.getRefID() != refloaded )
			{
				if ( algn.getRefID() < refloaded )
				{
					libmaus2::exception::LibMausException lme;
					lme.getStream() << "bamrecalculatecigar: file is not sorted by coordinate" << std::endl;
					lme.finish();
					throw lme;
				}

				ref = FAindex->readSequence(FAISI,algn.getRefID());
				refloaded = algn.getRefID();
			}

			uint64_t const numcig = libmaus2::bambam::BamAlignmentDecoderBase::recalculateCigar(
				algn.D.begin(),
				ref.begin() + algn.getPos(),
				cigopin,
				readdata
			);
			algn.replaceCigarString(cigopin,numcig,T);
		}

		writer->writeAlignment(algn);

		if ( ((++c) & ((1ull<<20)-1)) == 0 && verbose )
			std::cerr << "[V] " << c << std::endl;
	}

	if ( verbose )
		std::cerr << "[V] " << c << std::endl;

	writer.reset();

	if ( Pmd5cb )
	{
		Pmd5cb->saveDigestAsFile(md5filename);
	}
	if ( Pindex )
	{
		Pindex->flush(std::string(indexfilename));
	}

	return EXIT_SUCCESS;
}