Example #1
0
File: main.cpp Project: CCJY/coliru
    void init(const fs::path &rErrEvtPath, const fs::path &rStatusPath) {
        // register common attributes - ThreadID, LineID, TimeStamp etc.
        logging::add_common_attributes();

        // Construct the sink for the "event_log" channel
        typedef sinks::synchronous_sink<sinks::text_ostream_backend> text_sink;
        auto sink = boost::make_shared<text_sink>();
        sink->locked_backend()->auto_flush(true);
        sink->locked_backend()->add_stream(boost::make_shared<std::ofstream>(rErrEvtPath.c_str()));
        sink->set_formatter(expr::format("%1% [%2%] tid[%3%] %4%") %
                            expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%H:%M:%S.%f") %
                            logging::trivial::severity % expr::attr<attrs::current_thread_id::value_type>("ThreadID") %
                            expr::smessage);
        sink->set_filter(expr::attr<std::string>("Channel") == "event");
        logging::core::get()->add_sink(sink);

        // Construct the sink for the "status_log" channel
        sink = boost::make_shared<text_sink>();
        sink->locked_backend()->auto_flush(true);
        sink->locked_backend()->add_stream(boost::make_shared<std::ofstream>(rStatusPath.c_str()));
        sink->set_formatter(expr::format("%1% [%2%] tid[%3%] %4%") %
                            expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%H:%M:%S.%f") %
                            logging::trivial::severity % expr::attr<attrs::current_thread_id::value_type>("ThreadID") %
                            expr::smessage);
        sink->set_filter(expr::attr<std::string>("Channel") == "status");
        logging::core::get()->add_sink(sink);
    }
Example #2
0
void filter_init(int argc, char** argv)
{
  if(argc > 0)
    usage("Too many arguments.");
  set_filter(CLIENT_IN, filter_client_data, 0);
  set_filter(SERVER_FD, filter_server_data, 0);
  (void)argv;
}
CL_FileDialog_Generic::CL_FileDialog_Generic(
	CL_FileDialog *self,
	const std::string &title,
	const std::string &file,
	const std::string &filter)
	: filedialog(self)
{
	behavior = CL_FileDialog::quit_always;
	button = CL_FileDialog::button_none;
	// TODO: Calculate proper size
	int width = 400;
	int height = 315;
	int x = (CL_Display::get_width() - width) / 2;
	int y = (CL_Display::get_height() - height) / 2;
	filedialog->set_position(CL_Rect(x, y, x + width, y + height));
	filedialog->set_title(title);

	CL_Component *client_area = filedialog->get_client_area();

	width = client_area->get_width();

	label_dir = new CL_Label(CL_Point(10, 12), "Directory:", client_area);
	input_dir = new CL_InputBox(CL_Rect(65, 10, width - 120, 30), client_area);
	input_dir->enable(false);

	button_parent = new CL_Button(CL_Rect(width - 115, 9, width - 65, 28), "Parent", client_area);
	button_createdir = new CL_Button(CL_Rect(width - 60, 9, width - 10, 28), "New", client_area);

	treeview_files = new CL_TreeView(CL_Rect(10, 32, width - 10, 197), client_area);
	treeview_files->add_column("Filename", 200);
	treeview_files->add_column("Size", 80);
	treeview_files->add_column("Type", 100);
	treeview_files->show_root_decoration(false);

	label_file = new CL_Label(CL_Point(10, 207), "Filename:", client_area);
	input_file = new CL_InputBox(CL_Rect(65, 205, width - 10, 225), client_area);

	label_filter = new CL_Label(CL_Point(10, 232), "Filter:", client_area);
	input_filter = new CL_InputBox(CL_Rect(65, 230, width - 10, 250), client_area);

	button_ok = new CL_Button(CL_Rect(10, 260, 100, 280), "OK", client_area);
	button_cancel = new CL_Button(CL_Rect(width - 110, 260, width - 10, 280), "Cancel", client_area);

	slots.connect(self->sig_set_options(), this, &CL_FileDialog_Generic::on_set_options);
	slots.connect(treeview_files->sig_selection_changed(), this, &CL_FileDialog_Generic::on_file_activated);
	slots.connect(button_ok->sig_clicked(), this, &CL_FileDialog_Generic::on_button_quit, true);
	slots.connect(button_cancel->sig_clicked(), this, &CL_FileDialog_Generic::on_button_quit, false);
	slots.connect(button_parent->sig_clicked(), this, &CL_FileDialog_Generic::on_button_parent);
	slots.connect(button_createdir->sig_clicked(), this, &CL_FileDialog_Generic::on_button_createdir);
	slots.connect(input_file->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_file);
	slots.connect(input_filter->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_filter);
	slots.connect(input_dir->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_dir);
	
	set_file(file, false);
	set_filter(filter, false);
	show_hidden = false;

	read_dir();
}
/**
 	Switch On the wind noise filter
 */
void Filter_On(void) 
{
	DEBUG_FILTER(("[FILTER] ON\n"));
	
	MessageSinkTask(theHeadset.sco_sink, &theHeadset.task);
	voice_activity = VOICE_ACTIVITY_OFF;
	set_filter();
}
Example #5
0
void set_filter_level(std::string const &level) {
  // The return type depends on whether compilation is whith threads.
  auto logger = boost::log::core::get();

  if (level == "all" || level == "trace") {
    logger->set_filter(trivial::severity >= trivial::trace);
    LOG(info) << "Log level set to TRACE";
  } else if (level == "debug") {
    logger->set_filter(trivial::severity >= trivial::debug);
    LOG(info) << "Log level set to DEBUG";
  } else if (level == "info") {
    logger->set_filter(trivial::severity >= trivial::info);
    LOG(info) << "Log level set to INFO";
  } else if (level == "warn") {
    logger->set_filter(trivial::severity >= trivial::warning);
  } else if (level == "error") {
    logger->set_filter(trivial::severity >= trivial::error);
  } else if (level == "fatal") {
    logger->set_filter(trivial::severity >= trivial::fatal);
  } else if ((level == "off") || (level == "none")) {
    logger->set_logging_enabled(false);
  } else {
    logger->set_filter(trivial::severity >= trivial::fatal);
  }
}
Example #6
0
void BaseSniffer::init(pcap_t *phandle, const std::string &filter, 
  bpf_u_int32 if_mask) 
{
    handle = phandle;
    mask = if_mask;
    
    if(!filter.empty() && !set_filter(filter))
        throw runtime_error("Invalid filter");
}
Example #7
0
void init_filters(void)
{

    for(int i=0; i<8; i++)
    {   //set sensible default values
        //lowpass filter where everything passes with no resonance
        set_filter(i,FLT_LOWPASS,i2fp(1),i2fp(0),i2fp(0),false);
    }
    fp_inv_255=fl2fp(1.0f/255) ;
    filters_inited=true;
}
Example #8
0
int ingest_pcap(char *file) {
  int rc = -1;
  strncpy(&cfg.path[cfg.path_file_idx], file, PATH_MAX-cfg.path_file_idx);
  if (cfg.verbose) fprintf(stderr,"reading file %s\n", cfg.path);
  cfg.pcap = pcap_open_offline(cfg.path, cfg.err);
  if (cfg.pcap==NULL)  {fprintf(stderr,"can't open %s: %s\n", cfg.path, cfg.err); goto done;}
  if (set_filter()) goto done;
  rc = pcap_loop(cfg.pcap, 0, cb, NULL);  

 done:
  return rc;
}
Example #9
0
static void determine_mode_from_name (const char *argv0)
{
	/* This is filterdiff, unless it is named 'lsdiff' or 'grepdiff'. */
	const char *p = strrchr (argv0, '/');
	if (!p++)
		p = argv0;
	if (strstr (p, "lsdiff"))
		set_list ();
	else if (strstr (p, "grepdiff"))
		set_grep ();
	else
		set_filter ();
}
/**
 	Energy changed handler
 */
void Filter_EnergyChanged(Message message) {
	MessageEnergyChanged* m;
	m = (MessageEnergyChanged*) message;
	
	if (m->over_threshold) {
		DEBUG_FILTER(("[FILTER] VOICE_ACTIVITY_ON\n"));
		voice_activity = VOICE_ACTIVITY_ON;
	} else {
 		DEBUG_FILTER(("[FILTER] VOICE_ACTIVITY_OFF\n"));
		voice_activity = VOICE_ACTIVITY_OFF;
	}
	set_filter();
}
void CL_FileDialog_Generic::on_set_options(const CL_DomElement &options)
{
	if (options.has_attribute("file"))
		set_file(options.get_attribute("file"), false);

	if (options.has_attribute("filter"))
		set_filter(options.get_attribute("filter"), false);

	if (options.has_attribute("show_hidden"))
		show_hidden = CL_String::to_bool(options.get_attribute("show_hidden"));

	read_dir();
}
int YARPMEIDeviceDriver::setIntLimit(void *cmd)
{
	int16 rc = 0;
	SingleAxisParameters *tmp = (SingleAxisParameters *) cmd;
	int axis = tmp->axis;

	double val = *((double *) tmp->parameters);

	_filter_coeffs[axis][DF_I_LIMIT] = (int16) round(val);
	rc = set_filter(axis, _filter_coeffs[axis]);
	
	return rc;
}
int YARPMEIDeviceDriver::setIntLimits(void *lmts)
{
	int16 rc = 0;

	double *cmd = (double *) lmts;

	for(int i = 0; i<_njoints; i++)
	{
		_filter_coeffs[i][DF_I_LIMIT] = (int16) round(cmd[i]);
		rc = set_filter(i, _filter_coeffs[i]);
	}
	
	return rc;
}
Example #14
0
int
do_lvm_clear_filter (void)
{
  if (deactivate () == -1)
    return -1;

  if (set_filter ("\"a/.*/\"") == -1)
    return -1;

  if (rescan () == -1)
    return -1;

  return reactivate ();
}
int YARPMEIDeviceDriver::setOffsets(void *offs)
{
	int16 rc = 0;

	double *cmd = (double *) offs;

	for(int i = 0; i<_njoints; i++)
	{
		_filter_coeffs[i][DF_OFFSET] = (int16) round(cmd[i]);
		rc = set_filter(i, _filter_coeffs[i]);
	}
	
	return rc;
}
Example #16
0
/* Makes a new filter */
static void on_filter_entry_changed(GtkComboBoxEntry * cbox, gpointer user_data)
{
  gchar *str;
  /* TODO should make sure that for each mode the filter is set up
   * correctly */
  str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(cbox));
  if (pref.filter)
    g_free (pref.filter);
  pref.filter = g_strdup (str);
  /* TODO We should look at the error code from set_filter and pop
   * up a window accordingly */
  set_filter (pref.filter, NULL);
  g_free (str);
  cbox_add_select(cbox, pref.filter);
}				/* on_filter_entry_changed */
Example #17
0
static int need_a_filter(pam_handle_t *pamh
			 , int flags, int argc, const char **argv
			 , const char *name, int which_run)
{
    int ctrl;
    char **evp;
    const char *filterfile;
    int retval;

    ctrl = process_args(pamh, argc, argv, name, &evp, &filterfile);
    if (ctrl == -1) {
	return PAM_AUTHINFO_UNAVAIL;
    }

    /* set the tty to the old or the new one? */

    if (!(ctrl & NON_TERM) && !(ctrl & NEW_TERM)) {
	retval = set_the_terminal(pamh);
	if (retval != PAM_SUCCESS) {
	    _pam_log(LOG_ERR, "tried and failed to set PAM_TTY");
	}
    } else {
	retval = PAM_SUCCESS;  /* nothing to do which is always a success */
    }

    if (retval == PAM_SUCCESS && (ctrl & which_run)) {
	retval = set_filter(pamh, flags, ctrl
			    , (const char **)evp, filterfile);
    }

    if (retval == PAM_SUCCESS 
	&& !(ctrl & NON_TERM) && (ctrl & NEW_TERM)) {
	retval = set_the_terminal(pamh);
	if (retval != PAM_SUCCESS) {
	    _pam_log(LOG_ERR
		     , "tried and failed to set new terminal as PAM_TTY");
	}
    }

    free_evp(evp);

    if (ctrl & FILTER_DEBUG) {
	_pam_log(LOG_DEBUG, "filter/%s, returning %d", name, retval);
	_pam_log(LOG_DEBUG, "[%s]", pam_strerror(pamh, retval));
    }

    return retval;
}
Example #18
0
int caraca_init(void)
{
	signal_length = hw.code_length * 1000000 / 1200;
	if ((hw.fd = caraca_open(PACKAGE)) < 0) {
		logprintf(LOG_ERR, "could not open lirc");
		logperror(LOG_ERR, "caraca_init()");
		return (0);
	}
	/*accept IR-Messages (16 : RC5 key code) for all nodes on the bus */
	if (set_filter(hw.fd, 0x400, 0x7c0, 0) <= 0) {
		logprintf(LOG_ERR, "could not set filter for IR-Messages");
		caraca_deinit();
		return (0);
	}
	return (1);
}
Example #19
0
void Db_table_View::set_table(QString tabla)
{
    this->tabla = tabla;
    model->setTable(tabla);
    if(!model->select())
        qDebug () << model->lastError();
 //   ui->resultado_list->hideColumn(0);

    colums = model->columnCount();
    //-----------------------
    // Formateo forzado
    //-----------------------
    if (tabla =="vistaart_tarifa"){
        QString filtro ="tarifa=";
        filtro.append(QString::number(tarifa));
        set_filter(filtro);
        ui->resultado_list->setColumnWidth(0,100);
        ui->resultado_list->setColumnWidth(1,100);
        ui->resultado_list->setColumnWidth(2,100);
        ui->resultado_list->setColumnWidth(3,300);
        ui->resultado_list->setColumnWidth(4,180);
        ui->resultado_list->setColumnWidth(5,50);
        ui->resultado_list->setColumnWidth(6,90);
        ui->resultado_list->setColumnWidth(7,90);
        ui->resultado_list->setColumnHidden(8,true);
        ui->resultado_list->setColumnHidden(9,true);
        ui->resultado_list->setColumnHidden(11,true);
        ui->resultado_list->setColumnWidth(10,50);
        ui->resultado_list->setColumnWidth(12,50);
        ui->resultado_list->setColumnHidden(13,true);

        model->setHeaderData(0,Qt::Horizontal,tr("Código"));
        model->setHeaderData(1,Qt::Horizontal,tr("C.Barras"));
        model->setHeaderData(2,Qt::Horizontal,tr("C.Proveedor"));
        model->setHeaderData(3,Qt::Horizontal,tr("Descripción"));
        model->setHeaderData(4,Qt::Horizontal,tr("Desc. Resumida"));
        model->setHeaderData(5,Qt::Horizontal,tr("IVA"));
        model->setHeaderData(6,Qt::Horizontal,tr("Coste"));
        model->setHeaderData(7,Qt::Horizontal,tr("PVP"));
        model->setHeaderData(10,Qt::Horizontal,tr("St.R"));
        model->setHeaderData(12,Qt::Horizontal,tr("St.F"));
        ui->resultado_list->setItemDelegateForColumn(6,new MonetaryDelegate);
        ui->resultado_list->setItemDelegateForColumn(7, new MonetaryDelegate);

    }
}
Example #20
0
/*
 * db_col_filter() - This function examines each element in the collection for
 *   references to objects that have been deleted. If any such elements are
 *   found, they are removed. If the collection type is DB_TYPE_SEQUENCE, then
 *   the elements containing deleted object references will be changed to have
 *   a DB_TYPE_NULL value. DB_TYPE_MULTISET or DB_TYPE_SET, elements containing
 *   deleted object references are first converted to elements containing a
 *   DB_TYPE_NULL value. After all deleted object references have been
 *   converted to null values, all but one of the null values are then removed
 *   from the collection.
 * return : error status
 * col(in): collection to filter
 */
int
db_col_filter (DB_COLLECTION * col)
{
  int error;

  CHECK_CONNECT_ERROR ();
  CHECK_1ARG_ERROR (col);

  /* Check if modifications are disabled only if the set is owned */
  if (col->owner != NULL)
    {
      CHECK_MODIFICATION_ERROR ();
    }

  error = set_filter (col);

  return error;
}
Example #21
0
/*
 * db_seq_filter() - This function causes set elements containing references
 *    to deleted objects to be completely removed from the designated set.
 *    The system does not automatically filter sets containing references to
 *    deleted objects; if you do not call this function, make sure that your
 *    application code is prepared to encounter deleted objects.
 * return : error code
 * set(in): set to filter
 */
int
db_seq_filter (DB_SET * set)
{
  int retval;

  CHECK_CONNECT_ERROR ();
  CHECK_1ARG_ERROR (set);

  /* Check if modifications are disabled only if the set is owned */
  if (set->owner != NULL)
    {
      CHECK_MODIFICATION_ERROR ();
    }

  retval = (set_filter (set));

  return (retval);
}
Example #22
0
int
do_lvm_set_filter (char *const *devices)
{
  CLEANUP_FREE char *filter = make_filter_string (devices);
  if (filter == NULL)
    return -1;

  if (deactivate () == -1)
    return -1;

  int r = set_filter (filter);
  if (r == -1)
    return -1;

  if (rescan () == -1)
    return -1;

  return reactivate ();
}
Example #23
0
logger& logger::init()
{
    typedef sinks::debug_output_backend backend_t;
    auto pDebugBackend = boost::make_shared< backend_t >();

    auto pDebugSink = boost::make_shared< sinks::synchronous_sink< backend_t > >(pDebugBackend);
    pDebugSink->set_filter(expr::attr<severity_level>("Severity") >= trace);
    pDebugSink->set_formatter(
        expr::stream
        << "[" << expr::attr<UINT>("RecordID")
        << "][" << expr::format_date_time(_timestamp, "%Y-%m-%d %H:%M:%S.%f")
        << "][" << _severity
        << "]" << expr::message
        << std::endl);
    logging::core::get()->add_sink(pDebugSink);

    sink_ = logging::add_file_log(
                keywords::open_mode = std::ios::app, // append write
                keywords::file_name = file_name_ + "%Y-%m-%d.log",
                keywords::rotation_size = rotation_size_,
                keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
                keywords::min_free_space = min_free_space_,

                keywords::format = (
                                       expr::stream
                                       << "[" << expr::attr<UINT>("RecordID")
                                       << "][" << expr::format_date_time(_timestamp, "%Y-%m-%d %H:%M:%S.%f")
                                       << "][" << _severity
                                       << "]" << expr::message)
            );

    sink_->locked_backend()->auto_flush(auto_flush_);

    logging::add_common_attributes();

    attrs::counter<UINT> RecordID(1);
    logging::core::get()->add_global_attribute("RecordID", RecordID);

    this->set_filter_trace();

    return *this;
}
int YARPMEIDeviceDriver::setPid(void *cmd)
{
	int16 rc = 0;

	SingleAxisParameters *tmp = (SingleAxisParameters *) cmd;
	LowLevelPID *pid = (LowLevelPID *) tmp->parameters;

	// these are stored to be used later in the setOffsets/setOffset functions
	_filter_coeffs[tmp->axis][DF_P] = (int16) round(pid->KP);
	_filter_coeffs[tmp->axis][DF_I] = (int16) round(pid->KI);
	_filter_coeffs[tmp->axis][DF_D] = (int16) round(pid->KD);
	_filter_coeffs[tmp->axis][DF_ACCEL_FF] = (int16) round (pid->AC_FF);
	_filter_coeffs[tmp->axis][DF_VEL_FF] = (int16) round(pid->VEL_FF);
	_filter_coeffs[tmp->axis][DF_I_LIMIT] = (int16) round(pid->I_LIMIT);
	_filter_coeffs[tmp->axis][DF_OFFSET] = (int16) round(pid->OFFSET);
	_filter_coeffs[tmp->axis][DF_DAC_LIMIT] = (int16) round(pid->T_LIMIT);
	_filter_coeffs[tmp->axis][DF_SHIFT] = (int16) round(pid->SHIFT);
	_filter_coeffs[tmp->axis][DF_FRICT_FF] = (int16) round(pid->FRICT_FF);
	
	rc = set_filter(tmp->axis, _filter_coeffs[tmp->axis]);

	return rc;
}
void kvdb_catch_table(u16 pid, u16 table_id)
{
     adv_demux_filter_t *sn_filter = NULL;
     dmx_filter_setting_t param;
     KVDB_DRV_DEBUG("%s, %d \n", __FUNCTION__, __LINE__);
     KVDB_DRV_DEBUG("pid = %d , table_id = %d \n", pid, table_id);
     memset(&param,0x0, sizeof(dmx_filter_setting_t) );
      sn_filter = alloc_filter(pid);
      if(!sn_filter)
      {
            KVDB_DRV_DEBUG("sn_filter is NULL \n");
            return;
      }
      param.continuous = FALSE;
      param.en_crc = TRUE;
      param.req_mode =  DMX_REQ_MODE_SINGLE_SECTION;

      param.value[0] = table_id;
      param.mask[0] = 0xff,      
      set_filter( sn_filter, &param, call_back_data_procee);
      KVDB_DRV_DEBUG("start_filter ----\n");
      start_filter(sn_filter);
      return;
}
Example #26
0
BOOST_LOG_GLOBAL_LOGGER_INIT(__logger, bl::sources::severity_logger_mt)
{
    bl::sources::severity_logger_mt<boost::log::trivial::severity_level> logger;
    logger.add_attribute("TimeStamp", bl::attributes::local_clock());

    using text_sink = bl::sinks::asynchronous_sink<bl::sinks::text_ostream_backend>;
    auto consoleSink = boost::make_shared<text_sink>();
    consoleSink->locked_backend()->add_stream(boost::shared_ptr<std::ostream>(&std::cout, boost::null_deleter()));
    consoleSink->set_filter(severity >= boost::log::trivial::severity_level::warning);

    using file_sink = bl::sinks::asynchronous_sink<bl::sinks::text_file_backend>;
    auto logfileSink = boost::make_shared<file_sink>();
    
    {
        auto logfileBackend = logfileSink->locked_backend();
        logfileBackend->set_time_based_rotation(bl::sinks::file::rotation_at_time_point(0, 0, 0));
        logfileBackend->set_file_name_pattern("Logs\\ashbot_%Y%m%d.log");
        logfileBackend->auto_flush();
        logfileBackend->set_file_collector(
            bl::sinks::file::make_collector(bl::keywords::target = "Logs\\Archive")
        );
    }

    namespace expr = bl::expressions;

    bl::formatter fmt = expr::stream
        << format_date_time(timestamp, "%Y-%m-%d %H:%M:%S.%f")
        << " [" << boost::log::trivial::severity << "] "
        << expr::smessage;
    logfileSink->set_formatter(fmt);

    bl::core::get()->add_sink(consoleSink);
    bl::core::get()->add_sink(logfileSink);

    return logger;
}
Example #27
0
 void on_container_start(proton::container &c) override {
     proton::source_options opts;
     set_filter(opts, "colour = 'green'");
     proton::connection conn = c.connect(url);
     conn.open_receiver(url.path(), proton::receiver_options().source(opts));
 }
Example #28
0
/**
* @brief Main entry point for R
*
* @param bamfilenameR Filename of read container
* @param aRgvals Vector containing the user arguments
* @param filterList passed from R in the form list("chr1"=c(100,200,3000,3010...start,end...))
* @return R list in the form list("chr1"=c(1,2,1,2,1,1,...),"chr1_gind"=c(1100,1200...),"chr1_lind"=c(0,112,...),"chrX"=NA,...) and a Statistics vector
* @details All chromosome of the filter or all chromosomes in the file header will be scanned and passed to an R list
* @note
* @todo high_cov not yet implemented.
*/
SEXP construct_dc(SEXP bamfilenameR, SEXP aRgvals, SEXP filterList) {

	double *statsp;//resulting statistics in the order "total reads" "coverage" "local coverage" "max score"
	uint32_t upcounter=0,i=0;
	time_t tstart,tstop;
	global_densities_t gd={0};
    user_arguments_t user_args;
    filter_t ft;
    SEXP histogram,stats;
    int *argvalsp;

    signal(SIGINT,SIG_DFL);//make this thing stop on CTRL+C
    time(&tstart);

    /* Set user defined values */

    PROTECT(aRgvals=AS_INTEGER(aRgvals));upcounter++;
    if(LENGTH(aRgvals)!=10)error("Invalid amount of arguments - arguments[%d] / should be %d!\n",LENGTH(aRgvals),9);
    argvalsp=INTEGER_POINTER(aRgvals);
    user_args.bamfilename = STRING_VALUE(bamfilenameR);
    user_args.READTHROUGH = argvalsp[0];//bool. read from start to end and 0 take whole read whithout CIGAR splice info
    user_args.PAIRED = argvalsp[1];
    user_args.STRANDED = argvalsp[2];//Set to 1 / -1 it will use only forward / reverse reads respectively. 0 means all reads are processed
    user_args.TMAPQ = argvalsp[3];//Minimum MPAQ score. Lower scored reads will be skipped
    user_args.COLLAPSE = argvalsp[4];
    user_args.EXTEND = argvalsp[5];//extend each read in its direction by this amount of BPs
    user_args.HWINDOW = argvalsp[6];
    user_args.COMPRESSION = argvalsp[7];//minimum BPs needed between data blocks to collapse the gap and index it
    user_args.VERBOSE = argvalsp[8];
    user_args.UNIQUE = argvalsp[9];


    /* Try to open the file */
    samfile_t *bam_file;
    bam_file=open_samtools(user_args.bamfilename);
	if(!bam_file){
		warning("sam/bam file not found!\n");
		UNPROTECT(upcounter);
	    return(R_NilValue);
	}

    if(user_args.HWINDOW>user_args.COMPRESSION){
    	warning("HWINDOW has to be smaller than COMPRESSION! HWINDOW updated to %d\n",user_args.COMPRESSION);
    	user_args.HWINDOW=user_args.COMPRESSION;
    }

	PROTECT(histogram = NEW_INTEGER(UINT16_MAX));upcounter++;//initialize compressed scores
	gd.histogramp = (uint32_t*) INTEGER_POINTER(histogram);
	for(i = 0; i < UINT16_MAX; i++) gd.histogramp[i] = 0;

	gd.total_elements=bam_file->header->n_targets;//one vector per chromosome needed
	/* ####  CHECK IF THERE IS AN ACTIVE FILTER IN PLACE */
    user_args.FILTER=isNewList(filterList) ? 1 : 0;
    if(user_args.FILTER){
    	upcounter+=set_filter(filterList,&ft);
    	gd.total_elements=ft.seqn;//overwrite total elements if filter is passed, since one density is returned per slice
    }

	// Creating a list with vector elements as many as sequences plus a character string vector:
    PROTECT(gd.list = allocVector(VECSXP, (gd.total_elements*3)+2));upcounter++;//3x for the two indexes and scores per chromosome
    PROTECT(gd.list_names = allocVector(STRSXP,(gd.total_elements*3)+2));upcounter++;//+1 for statistics vector +1 for the histogram

	/* PASS EVERYTHING */
	write_density(&gd,&user_args,bam_file,&ft);
	if(!gd.total_reads)goto NO_READS_FOUND;
	// 1 total_reads  2 gcoverage  3 lcoverage  4 maxscore  5 lmaxscore  6 lowqual  7 filtered  8 collapsed  9 paired  10 proper_pairs 11 pos  12 neg 13 fmapmass 14 lsize 15 gsize
	SET_STRING_ELT(gd.list_names,gd.total_elements*3,mkChar("Statistics"));
	PROTECT(stats = NEW_NUMERIC(15));upcounter++;
	statsp = NUMERIC_POINTER(stats);
	*statsp++=(double)gd.total_reads;
	*statsp++=(double)gd.mapmass/(double)gd.gsize;
	*statsp++=(double)gd.lmapmass/(double)gd.lsize;
	*statsp++=(double)gd.maxscore;
	*statsp++=(double)gd.lmaxScore;
	*statsp++=(double)gd.lowqual;
	*statsp++=(double)gd.filtered_reads;
	*statsp++=(double)gd.collapsed;
	*statsp++=(double)gd.paired;
	*statsp++=(double)gd.ppairs/2;
	*statsp++=(double)gd.pos_strand;
	*statsp++=(double)gd.neg_strand;
	*statsp=(double)gd.mapmass;
	*statsp++=(double)gd.lsize;
	*statsp++=(double)gd.gsize;


	if(gd.lmaxScore>=umaxof(usersize)-1){
		warning("\nThe maximum pile up is exceeding the maximal value of UINT16_MAX=%d. Reads have been capped to that value.\nConsider to rerun using the maxDups option!\n",UINT16_MAX);
	}

	SET_VECTOR_ELT(gd.list,gd.total_elements*3, stats);

	SET_STRING_ELT(gd.list_names,(gd.total_elements*3)+1,mkChar("Histogram"));
	SET_VECTOR_ELT(gd.list,(gd.total_elements*3)+1,histogram);

    setAttrib(gd.list, R_NamesSymbol, gd.list_names);

    NO_READS_FOUND:
    time(&tstop);
	if(user_args.VERBOSE>0)printf("About %.0f seconds passed. %llu reads processed \n", difftime(tstop, tstart),gd.total_reads);
	close_bamfile(bam_file);
	if(user_args.FILTER)destroy_filter(&ft);
    UNPROTECT(upcounter+gd.upcounter);
    if(!gd.total_reads)return(R_NilValue);
    else return(gd.list);
}
Example #29
0
char *uilib_select_file_autostart(const char *title,
                                   unsigned int filterlist, unsigned int type,
                                   int style, int *autostart,
                                   char *resource_readonly)
{
    char *name = NULL;
    char *initialdir = NULL;
    char *initialfile = NULL;
//    char *filter = NULL;
//    unsigned int filterindex;
//    OPENFILENAME ofn;
//    int result;
    char *ret = NULL;

    if (styles[style].initialdir_resource != NULL)
        resources_get_value(styles[style].initialdir_resource,
            (void *)&initialdir);

    initialfile = ui_file_selector_initialfile[style];
    if (styles[style].file_resource != NULL)
        resources_get_value(styles[style].file_resource,
            (void *)&initialfile);

#if 0
    if (fontfile == NULL) {
        fontfile = util_concat(archdep_boot_path(), 
                               "\\fonts\\cbm-directory-charset.fon", NULL);
        font_loaded = 0;
        EnumFontFamilies(GetDC(NULL), "cbm-directory-charset/ck!",
            (FONTENUMPROC)EnumFontProc, (LPARAM)&font_loaded);
        if (font_loaded == 0) {
            font_loaded = AddFontResource(fontfile);
        }
    }

    filter = set_filter(filterlist, &filterindex);

    memset(&ofn, 0, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hwnd;
    ofn.hInstance = winmain_instance;
    ofn.lpstrFilter = filter;
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter = 0;
    ofn.nFilterIndex = filterindex;
    ofn.lpstrFile = st_name;
    ofn.nMaxFile = sizeof(st_name);
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = initialdir;
    ofn.lpstrTitle = title;
    ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NOTESTFILECREATE
                | OFN_SHAREAWARE | OFN_ENABLESIZING;
    if (styles[style].TemplateID != 0) {
        ofn.Flags |= OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
        ofn.lpfnHook = styles[style].hook_proc;
        ofn.lpTemplateName = MAKEINTRESOURCE(styles[style].TemplateID);
    } else {
        ofn.lpfnHook = NULL;
        ofn.lpTemplateName = NULL;
    }
    if (type == UILIB_SELECTOR_TYPE_FILE_LOAD)
        ofn.Flags |= OFN_FILEMUSTEXIST;

    ofn.nFileOffset = 0;
    ofn.nFileExtension = 0;
    ofn.lpstrDefExt = NULL;

    read_content_func = styles[style].content_read_function;
    autostart_result = autostart;
    res_readonly = resource_readonly;
    vsync_suspend_speed_eval();

    if (type == UILIB_SELECTOR_TYPE_FILE_SAVE)
        result = GetSaveFileName(&ofn);
    else
        result = GetOpenFileName(&ofn);

    update_filter_history(ofn.nFilterIndex);
#endif

    name = ui_filereq(title, styles[style].TemplateID, initialdir, initialfile, styles[style].content_read_function, autostart, resource_readonly);

    if (name != NULL) {
        char newdir[1024], *ptr = PathPart(name);
        memcpy(newdir, name, (int)(ptr - name));
        newdir[(int)(ptr - name)] = '\0';

        if (ui_file_selector_initialfile[style] != NULL)
            lib_free(ui_file_selector_initialfile[style]);
        if (styles[style].file_resource != NULL)
            resources_set_value(styles[style].file_resource, FilePart(name));
        ui_file_selector_initialfile[style] = lib_stralloc(FilePart(name));

        resources_set_value(styles[style].initialdir_resource, newdir);
        ret = lib_stralloc(name);
    }

//    lib_free(filter);

    return ret;
}
Example #30
0
File: menu.c Project: pepone42/gngb
int action_set_filter(MENU_ITEM *self)
{
  int p=(int)self->user_data;
  set_filter(p);
  return 2;
}