Esempio n. 1
0
// output from this are a functioning wells file and a beadfind mask
// images are only known internally to this.
void RealImagesToWells (
  OptArgs &opts,
  CommandLineOpts& inception_state,
  SeqListClass&    my_keys,
  TrackProgress&   my_progress,
  ImageSpecClass&  my_image_spec,
  SlicedPrequel&   my_prequel_setup )
{
  Region            wholeChip(0, 0, my_image_spec.cols, my_image_spec.rows);
  ComplexMask*      complex_mask       = 0;
  BkgFitterTracker* bkg_fitter_tracker = 0;
   
  if(inception_state.bkg_control.signal_chunks.restart_from.empty())
  {
    // do separator if necessary: generate mask
    IsolatedBeadFind ( my_prequel_setup, my_image_spec, wholeChip, inception_state,
		       inception_state.sys_context.GetResultsFolder(), inception_state.sys_context.analysisLocation,  my_keys, my_progress );
  }

  else
  {
    // restarting execution from known state, restore my_prequel_setup
    // no matter what I do seems like all restoration has to happen in this scope

    string filePath = inception_state.sys_context.analysisLocation + inception_state.bkg_control.signal_chunks.restart_from;

    time_t begin_load_time;
    time ( &begin_load_time );

    ifstream ifs(filePath.c_str(), ifstream::in);
    assert(ifs.good());

   // boost::archive::text_iarchive in_archive(ifs);
    boost::archive::binary_iarchive in_archive(ifs);
    string saved_git_hash;
    in_archive >> saved_git_hash
	       >> my_prequel_setup
	       >> complex_mask
	       >> bkg_fitter_tracker;

    ifs.close();

    time_t finish_load_time;
    time ( &finish_load_time );
    fprintf ( stdout, "Loading restart state from archive %s took %0.1f sec\n",
	      filePath.c_str(), difftime ( finish_load_time, begin_load_time ));

    if ( inception_state.bkg_control.signal_chunks.restart_check ){
      string git_hash = IonVersion::GetGitHash();
      ION_ASSERT( (saved_git_hash.compare(git_hash) == 0),
		  "This GIT hash " + git_hash + " of Analysis does not match the GIT hash " + saved_git_hash + " where " + filePath + " was saved; disable this check by using --no-restart-check");
    }

    // set file locations
    my_prequel_setup.FileLocations ( inception_state.sys_context.analysisLocation );
  }

  // Check if we have enoguh flows to perform signal processing.
  // If we are starting from flow 0 we should have at least number of flows 
  // equalling flow block size (currently 20) to perform regional paramter 
  // fitting in background model and derive any actional information for the 
  // next set of flows. If we dont have thes minimum number of flows then give
  // an appropriate message and error out
  if (!CheckForMinimumNumberOfFlows(inception_state)) {
    std::cout << "ERROR: Insufficient number of flows to start signal processing. "
              << "Minimum number of flows required is 20." << std::endl;
    exit(EXIT_FAILURE);
  }
 
  // do signal processing generate wells conditional on a separator
  IsolatedSignalProcessing ( my_prequel_setup, my_image_spec, wholeChip, opts, inception_state,
                             inception_state.sys_context.analysisLocation,  my_keys, my_progress, complex_mask, bkg_fitter_tracker );

  // @TODO cleanup causes crash when restarted, why?
  // if (complex_mask != NULL) delete complex_mask;
  // if (bkg_fitter_tracker != NULL) delete bkg_fitter_tracker;
}
Esempio n. 2
0
void SetUpOrLoadInitialState(CommandLineOpts &inception_state, SeqListClass &my_keys, TrackProgress &my_progress, ImageSpecClass &my_image_spec, SlicedPrequel& my_prequel_setup)
{

  if ( !inception_state.bkg_control.signal_chunks.restart_from.empty() )
  {
    // restarting from saved computational state
    // beadfind, bfmask.bin and beadfind.h5 will be ignored

    // note that if we are here we will never load the separator data
    inception_state.sys_context.GenerateContext (); // find our directories
    inception_state.sys_context.SetUpAnalysisLocation();

    LoadBeadFindState(inception_state, my_keys, my_image_spec);
  }
  else if (inception_state.mod_control.reusePriorBeadfind && inception_state.bkg_control.signal_chunks.restart_from.empty())
  {
    // starting execution fresh, justBeadFind already run
    
    // get any state from beadFind
    LoadBeadFindState(inception_state, my_keys, my_image_spec);

	// save current command line options to state file
	std::string stateFile = inception_state.sys_context.analysisLocation + "/analysisState.json";
    if (rename(stateFile.c_str(),(inception_state.sys_context.analysisLocation+"/analysisState_beadfind.json").c_str()) )
    {
      fprintf(stdout, "Unable to copy beadfind analysisState.json");
    }

    SetUpKeys(my_keys, inception_state.key_context, inception_state.flow_context);
    ProgramState state ( stateFile );
    state.Save ( inception_state,my_keys,my_image_spec );
    state.WriteState();

    // region layout saved in inception_state.loc_context
    // region definitions in background model via my_prequel_setup
    my_prequel_setup.SetRegions ( inception_state.loc_context.numRegions,
				  my_image_spec.rows,my_image_spec.cols,
				  inception_state.loc_context.regionXSize,
				  inception_state.loc_context.regionYSize );
    my_prequel_setup.FileLocations ( inception_state.sys_context.analysisLocation );

  }
 else
 {  
   // starting execution fresh, justBeadFind not run
   inception_state.SetUpProcessing();

   CreateResultsFolder (inception_state.sys_context.GetResultsFolder());
   inception_state.sys_context.SetUpAnalysisLocation();
    
   // convert from old key representatino to more useful modern style  
   SetUpKeys(my_keys, inception_state.key_context, inception_state.flow_context);
  
   //@TODO: side effects here on the entire image class
   // after this point, Images will behave differently when read in
   SetUpToProcessImages ( my_image_spec, inception_state );

   // region layout saved into inception_state.loc_context
   SetUpRegionsForAnalysis ( my_image_spec.rows, my_image_spec.cols, inception_state.loc_context );

   // region layout shared in background model and beadfind via my_prequel_setup
   my_prequel_setup.SetRegions ( inception_state.loc_context.numRegions,
				 my_image_spec.rows,my_image_spec.cols,
				 inception_state.loc_context.regionXSize,
				 inception_state.loc_context.regionYSize );
   my_prequel_setup.FileLocations ( inception_state.sys_context.analysisLocation );
 }
  strncpy(ImageTransformer::PCATest,inception_state.img_control.PCATest,sizeof(ImageTransformer::PCATest)-1);

  fprintf(stdout, "Analysis region size is width %d, height %d\n", inception_state.loc_context.regionXSize, inception_state.loc_context.regionYSize);
}
Esempio n. 3
0
void IsolatedSignalProcessing (
  SlicedPrequel    &my_prequel_setup,
  ImageSpecClass   &my_image_spec,
  Region           &wholeChip,
  OptArgs		   &opts,
  CommandLineOpts  &inception_state,
  string           &analysisLocation,
  SeqListClass     &my_keys,
  TrackProgress    &my_progress,
  ComplexMask      *complex_mask,
  BkgFitterTracker *bkg_fitter_tracker)
{
//@TODO: split function here as we immediately pick up the files

  ComplexMask from_beadfind_mask; //Todo: check if we can move this one level up so it is at the same level as the read in from the archive.
  if(!(inception_state.bkg_control.signal_chunks.restart_from.empty()))
  {
    from_beadfind_mask = *complex_mask;
  }
  else
    {
    // starting execution fresh
    from_beadfind_mask.InitMask();

    my_prequel_setup.LoadBeadFindForSignalProcessing ( true );

	Json::Value json1;
    vector<int> region_list;
	RetrieveParameterVectorInt(opts, json1, '-', "region-list", "", region_list);
	if(!region_list.empty())
	{
		my_prequel_setup.RestrictRegions(region_list);
	}

    if ( inception_state.bfd_control.beadMaskFile != NULL )
    {
      fprintf ( stdout, "overriding beadfind mask with %s\n", inception_state.bfd_control.beadMaskFile );
      from_beadfind_mask.my_mask->LoadMaskAndAbortOnFailure ( inception_state.bfd_control.beadMaskFile );
    }
    else
    {
      from_beadfind_mask.my_mask->LoadMaskAndAbortOnFailure ( my_prequel_setup.bfMaskFile.c_str() );
    }

    from_beadfind_mask.InitPinnedInFlow ( inception_state.flow_context.GetNumFlows() );
  }
  /********************************************************************
   *
   *  Background Modelling Process
   *
   *******************************************************************/
  // set up the directory for a new temporary wells file
  // clear out previous ones (can be bad with re-entrant processing!)
  ClearStaleWellsFile();
  inception_state.sys_context.MakeNewTmpWellsFile ( inception_state.sys_context.GetResultsFolder() );

  // feenableexcept(FE_DIVBYZERO | FE_INVALID); // | FE_OVERFLOW);

  // we might use some other model here
  if ( true )
  {
    DoThreadedSignalProcessing ( opts, inception_state, from_beadfind_mask, ChipIdDecoder::GetChipType(), my_image_spec,
                                 my_prequel_setup,my_keys, inception_state.mod_control.passTau, bkg_fitter_tracker);

  } // end BKG_MODL

  // whatever model we run, copy the signals to permanent location
  inception_state.sys_context.CopyTmpWellFileToPermanent (  inception_state.sys_context.GetResultsFolder() );

  inception_state.sys_context.CleanupTmpWellsFile (); // remove local file(!) how will this work with re-entrant processing????

  // mask file may be updated by model processing
  // analysis.bfmask.bin is what BaseCaller expects
  string analysisMaskFile  = analysisLocation + "analysis.bfmask.bin";
  string analysisStatFile  = analysisLocation + "analysis.bfmask.stats";
  from_beadfind_mask.my_mask->UpdateBeadFindOutcomes ( wholeChip, analysisMaskFile.c_str(), !inception_state.bfd_control.SINGLEBF, 0, analysisStatFile.c_str() );

  my_progress.ReportState ( "Raw flowgrams complete" );
}
Esempio n. 4
0
// output from this are a functioning wells file and a beadfind mask
// images are only known internally to this.
void RealImagesToWells (
  CommandLineOpts& inception_state,
  SeqListClass&    my_keys,
  TrackProgress&   my_progress,
  ImageSpecClass&  my_image_spec,
  SlicedPrequel&   my_prequel_setup )
{
  Region            wholeChip(0, 0, my_image_spec.cols, my_image_spec.rows);
  ComplexMask*      complex_mask       = 0;
  BkgFitterTracker* bkg_fitter_tracker = 0;
   
  if(inception_state.bkg_control.restart_from.empty())
  {
    // do separator if necessary: generate mask
    IsolatedBeadFind ( my_prequel_setup, my_image_spec, wholeChip, inception_state,
		       inception_state.sys_context.GetResultsFolder(), inception_state.sys_context.analysisLocation,  my_keys, my_progress );
  }

  else
  {
    // restarting execution from known state, restore my_prequel_setup
    // no matter what I do seems like all restoration has to happen in this scope

    string filePath = inception_state.sys_context.analysisLocation + inception_state.bkg_control.restart_from;

    time_t begin_load_time;
    time ( &begin_load_time );

    ifstream ifs(filePath.c_str(), ifstream::in);
    assert(ifs.good());

    //boost::archive::text_iarchive in_archive(ifs);
    boost::archive::binary_iarchive in_archive(ifs);
    string saved_svn_rev;
    in_archive >> saved_svn_rev
	       >> my_prequel_setup
	       >> complex_mask
	       >> bkg_fitter_tracker;

    ifs.close();

    time_t finish_load_time;
    time ( &finish_load_time );
    fprintf ( stdout, "Loading restart state from archive %s took %0.1f sec\n",
	      filePath.c_str(), difftime ( finish_load_time, begin_load_time ));

    if ( inception_state.bkg_control.restart_check ){
      string svn_rev = IonVersion::GetSvnRev();
      ION_ASSERT( (saved_svn_rev.compare(svn_rev) == 0),
		  "This SVN rev " + svn_rev + " of Analysis does not match the SV rev " + saved_svn_rev + " where " + filePath + " was saved; disable this check by using --no-restart-check");
    }

    // set file locations
    my_prequel_setup.FileLocations ( inception_state.sys_context.analysisLocation );
  }

  // do signal processing generate wells conditional on a separator
  IsolatedSignalProcessing ( my_prequel_setup, my_image_spec, wholeChip, inception_state,
                             inception_state.sys_context.analysisLocation,  my_keys, my_progress, complex_mask, bkg_fitter_tracker );

  // @TODO cleanup causes crash when restarted, why?
  // if (complex_mask != NULL) delete complex_mask;
  // if (bkg_fitter_tracker != NULL) delete bkg_fitter_tracker;
}