Пример #1
0
HRESULT GetRibbonText(BSTR * RibbonXml)
{
	LPBYTE content = NULL;
	DWORD content_length = 0;

	ASSERT_RETURN_VALUE(LoadResourceFromModule(
		AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_RESOURCE_H), L"TEXT", &content, &content_length), S_FALSE);

	CMemFile mf(content, content_length);
	CTextFileRead rdr(&mf);

	CMapStringToString replacements;

	CString line;
	while (rdr.ReadLine(line))
	{
		CSimpleArray<CString> tokens;

		CString token;
		token.Preallocate(30);

		for (LPCWSTR pos = line; *pos; ++pos)
		{
			if (*pos == ' ' || *pos == '\t')
			{
				if (!token.IsEmpty())
				{
					tokens.Add(token);
					token = CString();
				}
			}
			else
			{
				token += *pos;
			}
		}

		if (!token.IsEmpty())
			tokens.Add(token);

		if (tokens.GetSize() != 3)
			continue;

		if (tokens[0] != "#define")
			continue;

		replacements[tokens[1]] = tokens[2];
	}

	CString ribbon = LoadTextFromModule(AfxGetInstanceHandle(), IDR_RIBBON);

	for (int pos = 0; pos < ribbon.GetLength(); ++pos)
	{
		if (ribbon[pos] != '{')
			continue;

		int endpos = ribbon.Find('}', pos);
		ASSERT_CONTINUE(endpos != -1);

		CString token = ribbon.Mid(pos+1, endpos-pos-1);
		CString token_found;

		ASSERT_CONTINUE(replacements.Lookup(token, token_found));	

		ribbon.Delete(pos, endpos-pos+1);
		ribbon.Insert(pos, token_found);

		pos += (token_found.GetLength()-1);
	}

	*RibbonXml = ribbon.AllocSysString();
	return S_OK;
}
void
position_nonref_2allele_test(const snp_pos_info& pi,
                             const blt_options& opt,
                             const bool /*is_always_test*/,
                             nonref_test_call& nrc) {

    static const bool is_mle_freq(false);

    if(pi.ref_base=='N') return;

    // add early escape test here?

    // 1. Determine the two 'primary' alleles -- Simple test just adds
    // up qscores to determine which alleles are primary.
    //
    nrc.nonref_id=(BASE_ID::ANY);
    //unsigned nonref2_id(BASE_ID::ANY); // just ignore this value for now....
    {
        double qtot[N_BASE];
        for(unsigned i(0); i<N_BASE; ++i) qtot[i] = 0;

        const unsigned n_calls(pi.calls.size());
        for(unsigned i(0); i<n_calls; ++i) {
            if(pi.calls[i].base_id==BASE_ID::ANY) continue;
            qtot[pi.calls[i].base_id] += pi.calls[i].get_qscore();
        }

        // get max and max2:
        unsigned max_id=0;
        unsigned max2_id=1;
        for(unsigned b(1); b<N_BASE; ++b) {
            if(qtot[b] > qtot[max_id]) {
                max2_id = max_id;
                max_id = b;
            } else if(qtot[b] > qtot[max2_id]) {
                max2_id = b;
            }
        }

        const unsigned ref_id=base_to_id(pi.ref_base);
        if       (ref_id==max_id) {
            nrc.nonref_id=max2_id;

#if 0
        } else if(ref_id==max2_id) {
            nrc.nonref_id=max_id;
#endif
        } else {
            nrc.nonref_id=max_id;
            //nonref2_id=max2_id;
        }
    }

    blt_float_t lhood[NR2TEST::SIZE];

    lhood[NR2TEST::REF] = calc_pos_nonref_freq_loghood(pi,0.);

    sparse_function sf;
    nonref_allele_freq_loghood_sparse_func nlf(pi,nrc.nonref_id,sf);
    sample_uniform_range(0.,1.,nlf);
    //sample_uniform_range(min_nonref_freq,1.,nlf);

    lhood[NR2TEST::NONREF_MF] = integrate_ln_sparsefunc(sf, opt.min_nonref_freq, 1,1,1);
    lhood[NR2TEST::NONREF_MF_NOISE] = integrate_ln_sparsefunc(sf, 0, opt.nonref_site_error_decay_freq,1,0);

    static const blt_float_t neginf(-std::numeric_limits<blt_float_t>::infinity());
    lhood[NR2TEST::NONREF_OTHER] = neginf;

    //std::cerr << "WAGART: logh ref/nonef: " << lhood[0] << " " << lhood[1] << "\n";

    // TODO: ctor compute this:

    // this goes in here just in case someone cranks both parameters up near 1:
    //
    const double nonref_variant_rate_used = opt.nonref_variant_rate*(1-opt.nonref_site_error_rate);

    blt_float_t prior[NR2TEST::SIZE];
    prior[NR2TEST::REF] = log1p_switch(-(nonref_variant_rate_used+opt.nonref_site_error_rate));
    prior[NR2TEST::NONREF_MF] = std::log(nonref_variant_rate_used/3);
    prior[NR2TEST::NONREF_MF_NOISE] = std::log(opt.nonref_site_error_rate);
    prior[NR2TEST::NONREF_OTHER] = std::log(2*nonref_variant_rate_used/3);

    double pprob[NR2TEST::SIZE];
    for(unsigned i(0); i<NR2TEST::SIZE; ++i) {
        pprob[i] = lhood[i] + prior[i];
    }
    normalize_ln_distro(pprob,pprob+NR2TEST::SIZE,nrc.max_gt);

    nrc.snp_qphred=error_prob_to_qphred(pprob[NR2TEST::REF]+pprob[NR2TEST::NONREF_MF_NOISE]);
    nrc.max_gt_qphred=error_prob_to_qphred(prob_comp(pprob,pprob+NR2TEST::SIZE,nrc.max_gt));

    nrc.is_snp=(nrc.snp_qphred != 0);

    if(! (is_mle_freq && nrc.is_snp)) return;

#if 0
    const double null_loghood(calc_pos_nonref_freq_loghood(pi,0.));

    // heuristic to escape early:
    static const double p_delta(0.001);
    const double delta_loghood(calc_pos_nonref_freq_loghood(pi,p_delta));
    if(null_loghood > delta_loghood) return;

    double x_nonref_freq;
    double x_loghood;

    position_nonref_freq_loghood_minfunc mf(epi);

    static const double x1(0.5);
    static const double x2(0.4);
    codemin::minimize_1d(x1,x2,mf.val(x1),mf,x_nonref_freq,x_loghood);

    x_nonref_freq = mf.arg_to_prob(x_nonref_freq);

    const double log_lrt(-2.*(x_loghood+null_loghood));

    // becuase null has the parameter fixed to a boundary value, the
    // asymmtotic distribution is a 50:50 mixture of csq(0) and chq(1)
    // -- the same effect as multiplying alpha of csq(1) by 2, dividing
    // the null prob by 2. (as we do below):
    boost::math::chi_squared dist(1);
    const double null_prob((1.-boost::math::cdf(dist,log_lrt))/2.);

    sc.is_snp=(null_prob<alpha);
    sc.null_loghood=null_loghood;
    sc.min_test_loghood=-x_loghood;
    sc.snp_prob=1.-null_prob;

    // if it's a snp then get additional information on non-reference
    // allele frequencies.
    //
    if(not sc.is_snp) return;

    static const double line_tol(1e-7);
    static const double start_ratio(0.05);
    static const double min_start_dist(1e-6);
    static const double end_tol(1e-7);
    static const unsigned max_iter(200);

    const unsigned ref_base_id(base_to_id(pi.ref_base));

    const double ref_freq(1.-x_nonref_freq);
    const double nonref_freq((x_nonref_freq)/3.);
    for(unsigned i(0); i<N_BASE; ++i) {
        if(i==ref_base_id) sc.allele_freq[i] = ref_freq;
        else               sc.allele_freq[i] = nonref_freq;
    }

    static const unsigned N_BASE2(N_BASE*N_BASE);
    double conj_dir[N_BASE2];
    std::fill(conj_dir,conj_dir+N_BASE2,0.);
    for(unsigned i(0); i<N_BASE; ++i) {
        const double start_dist( std::max(std::fabs(sc.allele_freq[i]*start_ratio),min_start_dist) );
        conj_dir[i*(N_BASE+1)] = start_dist;
    }

    double start_tol(end_tol);
    unsigned iter;
    double x_all_loghood;
    double final_dlh;
    position_allele_distro_loghood_minfunc alm(epi);
    codemin::minimize_conj_direction(sc.allele_freq,conj_dir,alm,start_tol,end_tol,line_tol,
                                     x_all_loghood,iter,final_dlh,max_iter);
    alm.arg_to_prob(sc.allele_freq,sc.allele_freq);

    sc.min_loghood=-x_all_loghood;
#endif
}
Пример #3
0
bool LoadADT(char* filename)
{
	size_t size;
	MPQFile mf(filename);

	if(mf.isEof ())
	{
		//printf("No such file.\n");	
		return false;
	}
	mcells=new mcell;

	wmoc.x =65*TILESIZE;
	wmoc.z =65*TILESIZE;

	size_t mcnk_offsets[256], mcnk_sizes[256];

	wmo_count=0;
	bool found=false;
	//uint32 fs=mf.getSize ()-3;
	//while (mf.getPos ()<fs)
	while (!mf.isEof  ())
	{
		uint32 fourcc;		
		mf.read(&fourcc,4);
		mf.read(&size, 4);

		size_t nextpos = mf.getPos () + size;
		if(fourcc==0x4d43494e)
		{
		//	printf("Found chunks info\n");
			// mapchunk offsets/sizes
			for (int i=0; i<256; i++)
			{
				mf.read(&mcnk_offsets[i],4);
				mf.read(&mcnk_sizes[i],4);
				mf.seekRelative(8);
			}
		//break;
		}
		else 
			if(fourcc==0x4d4f4446)
			{
			
			/*	if(size)
				{	
					//printf("\nwmo count %d\n",size/64);
					wmo_count =size/64;
					for (int i=0; i<wmo_count; i++)
					{
						int id;
						mf.read(&id, 4);
						WMO *wmo = (WMO*)wmomanager.items[wmomanager.get(wmos[id])];
						WMOInstance inst(wmo, mf);
						wmois.push_back(inst);
					}

				}*/
			
			}else 
			if(fourcc==0x4d574d4f)//mwmo
			{
				/*if (size)
				{
					char *buf = new char[size];
					mf.read(buf, size);
					char *p=buf;
					while (p<buf+size)
					{
					std::string path(p);
						p+=strlen(p)+1;
						fixname(path);
						
						wmomanager.add(path);
						wmos.push_back(path);
					}
					delete[] buf;
			    }*/
			}
		//	else mf.seekRelative(-3);

		mf.seek(nextpos);
	}
		//printf("Loading chunks info\n");
		// read individual map chunks
		for (int j=0; j<16; j++) 
			for (int i=0; i<16; i++) 
			{

				mf.seek((int)mcnk_offsets[j*16+i]);
				LoadMapChunk (mf,&(mcells->ch [i][j]));

			}

		/*	for(uint32 t=0;t<wmo_count ;t++)
			{
				wmois[t].draw ();

			}*/
	mf.close ();
	return true;
}
Пример #4
0
static inline void mfbuffer(MSBuffer *bp)
{
  mf((I *)bp->minofbuffer());
  bp->minofbuffer(0);
}
Пример #5
0
//For communication with outside routines: sets all data by one vector y=1..11.
void QedQcd::set(const DoubleVector & y) {
  a(ALPHA) = y.display(1);
  a(ALPHAS) = y.display(2);
  int i; for (i=3; i<=11; i++)
    mf(i-2) = y.display(i);
}
Пример #6
0
      bool App::parseCommandLineArguments(int argc, char** argv)
      {
        options::options_description od("Usage: DPTApp");
        od.add_options()
          ( "tests", options::value< std::vector<std::string> >()->composing()->multitoken(), "tests to run" )
          ( "mf", options::value<std::string>(), "MeasurementFunctor to use while testing" )
          ( "help", "show help" )
          ;
        
        options::basic_parsed_options<char> parsedOpts = options::basic_command_line_parser<char>(argc, argv).options( od ).allow_unregistered().run();

        options::variables_map optsMap;
        options::store( parsedOpts, optsMap );

        if( !optsMap["help"].empty() )
        {
          printHelp();
          printHelpTestRender();
          printHelpTestGoldImage();
          printHelpTestBasicBenchmark();
          printHelpMeasurementFunctorNVPM();

          return false;
        }

        if( optsMap["tests"].empty() )
        {
          std::cerr << "Error: tests need to be specified. Use --help flag for more information.\n";
          return false;
        }
        else if( !optsMap.count("tests") )
        {
          std::cerr << "Error: one or more test or test modules need to follow the --tests option\n";
          return false;
        }
        else
        {
          m_testFilters = optsMap["tests"].as< std::vector<std::string> >();
        }


        if( !optsMap["mf"].empty() )
        {
          std::string mf( optsMap["mf"].as<std::string>() );
          transform(mf.begin(), mf.end(), mf.begin(), ::tolower);

          if( mf.compare("goldimage") == 0 )
          {
            m_mf = new core::MeasurementFunctorGoldImage();
          }
#if defined(HAVE_NVPMAPI)
          else if( mf.compare("perfmon") == 0 )
          {
            m_mf = new core::MeasurementFunctorNVPM();
          }
#endif
          else if( mf.compare("timer") == 0 )
          {
            m_mf = new core::MeasurementFunctorTimer();
          }
          else if( mf.compare("default") == 0 )
          {
            m_mf = new core::MeasurementFunctor();
          }
          else
          {
            cerr << "Warning: invalid argument for --mf flag. Use --help flag for more information.\n";
            cerr << "Using default measurement functor.";
            m_mf = new core::MeasurementFunctor();
          }
        }
        else
        {
          cerr << "Warning: A measurement functor should be specified\n";
          cerr << "Using default measurement functor.";
          m_mf = new core::MeasurementFunctor();
        }

        m_userOptions = options::collect_unrecognized( parsedOpts.options, options::include_positional );

        if(argc == 1)
        {
          cout << "Use --help flag for instructions\n";
          return false;
        }

        return true;
      }
Пример #7
0
// Process buttons:
void procButton(KeypadEvent b) {
    b -= 48;
    switch (keypad.getState()) {
    case RELEASED: // drop right away
        return;
    case PRESSED: // momentary
        if(mode==2) { // Signal Switching 4
            ss4Signal(b);
            break;
        } else if(mode==3) {
            pulse(b); // pulse it
            return;
        }
        if(mode==4&&(b<10&&b>=0||b==-13||b==-6||(b>=49&&b<=52))) { // MF tone
            mf(b);
        }
        if(b<10&&b>=0||b==-13||b==-6) { // MF tone
            mf(b);
        } else if(b==52) { // D
            if (stored) playStored(); // don't copy function onto stack if not needed
            return;
        } else if(mode==1) { // international kp2/st2
            if(b>=49&&b<=51) {
                mf(b);
                return;
            }
        }
        else if(mode==0&&(b<=51&&b>=49)) { // A,B,C redbox
            redBox(b); // pass it to RedBox()
            return;
        }
        break;
    case HOLD: // HELD (special functions)
        if(b==50&&mode==3) { // HOLD B for MF2 in PD Mode
            (mf2)? mf2 = 0 : mf2 = 1; // turn off if on, or on if off
            freq[0].play(440,70);
            delay(140);
            freq[0].play(440,70);
            delay(140);
        }
        if(b<10&&b>=0||b==-13||b==-6) {
            dial(b);
        } else if(b==51) { // C takes care of recording now
            if(rec) { // we are done recording:
                digitalWrite(13, LOW); // turn off LED
                rec = 0;
                stored=1; // we have digits stored
                recNotify();
            } else { // we start recording
                digitalWrite(13, HIGH); // light up LED
                rec = 1;
                for(int i=0; i<=23; i++) { // reset array
                    store[i] = -1;
                }
                recNotify();
            } // END recording code
        } else if(b==49) { // ('A' HELD) switching any mode "on" changes to mode, all "off" is domestic
            if(mode==0) { // mf to international
                mode=1;
            } else if(mode==1) { // international to ss4 mode
                mode=2;
            } else if(mode==2) { // ss4 mode to pulse mode
                mode=3;
            } else if(mode==3) { // pulse mode to DTMF
                mode=4;
            } else if(mode==4) { // DTMF to domestic
                mode=0;
            }
            notifyMode();
            return;
        }
        break;
    }
    return;
}
Пример #8
0
int
main (int argc, char** argv)
{
  BoxLib::Initialize(argc, argv);

  BL_PROFILE_VAR("main()", pmain);

  Array<DistributionMapping::Strategy> dmStrategies(nStrategies);
  dmStrategies[0] = DistributionMapping::ROUNDROBIN;
  dmStrategies[1] = DistributionMapping::KNAPSACK;
  dmStrategies[2] = DistributionMapping::SFC;
  dmStrategies[3] = DistributionMapping::PFC;

  Array<std::string> dmSNames(nStrategies);
  dmSNames[0] = "ROUNDROBIN";
  dmSNames[1] = "KNAPSACK";
  dmSNames[2] = "SFC";
  dmSNames[3] = "PFC";

  Array<double> dmSTimes(nStrategies, 0.0);

  for(int iS(0); iS < nStrategies * nTimes; ++iS) {

    int whichStrategy(iS % nStrategies);

    DistributionMapping::strategy(dmStrategies[whichStrategy]);

//    Box bx(IntVect(0,0,0),IntVect(511,511,255));
//    Box bx(IntVect(0,0,0),IntVect(1023,1023,255));
    Box bx(IntVect(0,0,0),IntVect(1023,1023,1023));
//    Box bx(IntVect(0,0,0),IntVect(2047,2047,1023));
//    Box bx(IntVect(0,0,0),IntVect(127,127,127));
//    Box bx(IntVect(0,0,0),IntVect(255,255,255));

    BoxArray ba(bx);
    ba.maxSize(64);

    const int N = 2000;  // This should be divisible by 4 !!!

    if (ParallelDescriptor::IOProcessor() && iS == 0) {
        std::cout << "Domain: " << bx << "  # boxes in BoxArray:  " << ba.size() << '\n';
    }
    if (ParallelDescriptor::IOProcessor())
        std::cout << "Strategy: " << dmSNames[DistributionMapping::strategy()] << '\n';


    ParallelDescriptor::Barrier();

    {
        //
        // A test of FillBoundary() on 1 grow cell with cross stencil.
        //
        MultiFab mf(ba,1,1); mf.setVal(1.23);

        ParallelDescriptor::Barrier();
        double beg = ParallelDescriptor::second();
        for (int i = 0; i < N; i++)
            mf.FillBoundary(true);
        double end = (ParallelDescriptor::second() - beg);

        ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber());
        if (ParallelDescriptor::IOProcessor()) {
          std::cout << N << " cross x 1: " << end << std::endl;
	  dmSTimes[whichStrategy] += end;
	}
    }


    {
        //
        // A test of FillBoundary() on 1 grow cell with dense stencil.
        //
        MultiFab mf(ba,1,1); mf.setVal(1.23);

        ParallelDescriptor::Barrier();
        double beg = ParallelDescriptor::second();
        for (int i = 0; i < N; i++)
            mf.FillBoundary(false);
        double end = (ParallelDescriptor::second() - beg);

        ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber());
        if (ParallelDescriptor::IOProcessor()) {
          std::cout << N << " dense x 1: " << end << std::endl;
	  dmSTimes[whichStrategy] += end;
	}
    }

    {
        //
        // First a test of FillBoundary() on 2 grow cells with dense stencil.
        //
        MultiFab mf(ba,1,2); mf.setVal(1.23);

        ParallelDescriptor::Barrier();
        double beg = ParallelDescriptor::second();
        for (int i = 0; i < N/2; i++)
            mf.FillBoundary(false);
        double end = (ParallelDescriptor::second() - beg);

        ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber());
        if (ParallelDescriptor::IOProcessor()) {
          std::cout << (N/2) << " dense x 2: " << end << std::endl;
	  dmSTimes[whichStrategy] += end;
	}
    }

    {
        //
        // First a test of FillBoundary() on 4 grow cells with dense stencil.
        //
        MultiFab mf(ba,1,4); mf.setVal(1.23);

        ParallelDescriptor::Barrier();
        double beg = ParallelDescriptor::second();
        for (int i = 0; i < N/4; i++)
            mf.FillBoundary(false);
        double end = (ParallelDescriptor::second() - beg);

        ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber());
        if (ParallelDescriptor::IOProcessor()) {
          std::cout << (N/4) << " dense x 4: " << end << std::endl;
	  dmSTimes[whichStrategy] += end;
	}
    }
    if (ParallelDescriptor::IOProcessor())
        std::cout << std::endl;

  }  // end for iS


    if(ParallelDescriptor::IOProcessor()) {
      for(int i(0); i < nStrategies; ++i) {
        std::cout << std::endl << "Total times:" << std::endl;
	std::cout << dmSNames[i] << " time = " << dmSTimes[i] << std::endl;
      }
      std::cout << std::endl << std::endl;
    }

    BL_PROFILE_VAR_STOP(pmain);

    BoxLib::Finalize();

    return 0;
}