void TraceStoreCol::Init(Mask &mask, size_t frames, const char *flowOrder, int numFlowsBuff, int maxFlow, int rowStep, int colStep) { pthread_mutex_init (&mLock, NULL); mUseMeshNeighbors = 1; mRowRefStep = rowStep; mColRefStep = colStep; mMinRefProbes = floor (mRowRefStep * mColRefStep * .1); mRows = mask.H(); mCols = mask.W(); mFrames = frames; mFrameStride = mRows * mCols; mFlows = mFlowsBuf = maxFlow; mFlowFrameStride = mFrameStride * maxFlow; mMaxDist = 2 * sqrt(rowStep*rowStep + colStep+colStep); mFlowOrder = flowOrder; mWells = mRows * mCols; mUseAsReference.resize (mWells, false); int keep = 0; int empties = 0; mRefGridsValid.resize (mFlowsBuf, 0); mRefGrids.resize (mFlowsBuf); mData.resize (mWells * mFrames * mFlowsBuf); std::fill (mData.begin(), mData.end(), 0); }
int LoadMask(Mask &mask, char *fileName, int version, MaskType withThese) { int beadsFound = 0; int n = 0; int w, h; w = mask.W(); h = mask.H(); FILE *fp = NULL; fopen_s(&fp, fileName, "r"); if (fp) { int x, y; // read the XY offset and the size of the input mask x = 0; y = 0; if (version == 1) { // version 1 masks are from TorrentExplorer, so they are not full-chip sized double _x, _y; n = fscanf_s(fp, "%lf,%lf\n", &_x, &_y); assert(n == 2); x = (int)_x; y = (int)_y; n = fscanf_s(fp, "%d,%d\n", &w, &h); assert(n==2); } int i,j; int val; for(j=0;j<h;j++) { for(i=0;i<w;i++) { if (i < (w-1)) { n = fscanf_s(fp, "%d,", &val); // comma scanned in, but seems to also work with just a space in a mask input file assert(n==1); } else { n = fscanf_s(fp, "%d\n", &val); // last entry per row has no comma assert(n==1); } if (val > 0) { // if (val == 64) // mask[(i+x)+(j+y)*mask.W()] |= MaskBead; // else mask[(i+x)+(j+y)*mask.W()] |= withThese; beadsFound++; } } } fclose(fp); } else { fprintf (stderr, "%s: %s\n", fileName, strerror(errno)); } return beadsFound; }
int main (int argc, const char *argv[]) { BaseCallerSalute(); time_t analysis_start_time; time(&analysis_start_time); Json::Value basecaller_json(Json::objectValue); DumpStartingStateOfProgram (argc,argv,analysis_start_time, basecaller_json["BaseCaller"]); // // Step 1. Process Command Line Options & Initialize Modules // BaseCallerParameters bc_params; OptArgs opts, null_opts; opts.ParseCmdLine(argc, argv); if (opts.GetFirstBoolean('h', "help", false) or argc == 1) bc_params.PrintHelp(); if (opts.GetFirstBoolean('v', "version", false)) { fprintf (stdout, "%s", IonVersion::GetFullVersion ("BaseCaller").c_str()); exit (EXIT_SUCCESS); } // Command line processing *** Main directories and file locations first bc_params.InitializeFilesFromOptArgs(opts); bc_params.InitContextVarsFromOptArgs(opts); // Command line processing *** Options that have default values retrieved from wells or mask files RawWells wells ("", bc_params.GetFiles().filename_wells.c_str()); if (!wells.OpenMetaData()) { fprintf (stderr, "Failed to retrieve metadata from %s\n", bc_params.GetFiles().filename_wells.c_str()); exit (EXIT_FAILURE); } Mask mask (1, 1); if (mask.SetMask (bc_params.GetFiles().filename_mask.c_str())) exit (EXIT_FAILURE); string chip_type = "unknown"; if (wells.KeyExists("ChipType")) wells.GetValue("ChipType", chip_type); // Command line processing *** Various general option and opts to classify and sample wells BaseCallerContext bc; bc.mask = &mask; bc.SetKeyAndFlowOrder(opts, wells.FlowOrder(), wells.NumFlows()); bc.chip_subset.InitializeChipSubsetFromOptArgs(opts, mask.W(), mask.H()); // Sampling options may reset command line arguments & change context bc_params.InitializeSamplingFromOptArgs(opts, bc.chip_subset.NumWells()); bc_params.SetBaseCallerContextVars(bc); ClassifyAndSampleWells(bc, bc_params.GetSamplingOpts()); // *** Setup for different datasets BarcodeDatasets datasets_calibration(bc.run_id, bc_params.GetFiles().calibration_panel_file); datasets_calibration.SetIonControl(bc.run_id); datasets_calibration.GenerateFilenames("IonControl","basecaller_bam",".basecaller.bam",bc_params.GetFiles().output_directory); BarcodeDatasets datasets(bc.run_id, bc_params.GetFiles().lib_datasets_file); // Check if any of the template barcodes is equal to a control barcode if (datasets_calibration.DatasetInUse()) datasets.RemoveControlBarcodes(datasets_calibration.json()); datasets.GenerateFilenames("Library","basecaller_bam",".basecaller.bam",bc_params.GetFiles().output_directory); BarcodeDatasets datasets_tf(bc.run_id); datasets_tf.SetTF(bc.process_tfs); datasets_tf.GenerateFilenames("TF","basecaller_bam",".basecaller.bam",bc_params.GetFiles().output_directory); BarcodeDatasets datasets_unfiltered_untrimmed(datasets); BarcodeDatasets datasets_unfiltered_trimmed(datasets); // *** Initialize remaining modules of BaseCallerContext vector<string> bam_comments; BaseCallerFilters filters(opts, bam_comments, bc.run_id, bc.flow_order, bc.keys, mask); bc.filters = &filters; BaseCallerMetricSaver metric_saver(opts, bc.chip_subset.GetChipSizeX(), bc.chip_subset.GetChipSizeY(), bc.flow_order.num_flows(), bc.chip_subset.GetRegionSizeX(), bc.chip_subset.GetRegionSizeY(), bc_params.GetFiles().output_directory); bc.metric_saver = &metric_saver; // Calibration modules bc.recalibration.Initialize(opts, bc.flow_order); bc.recalModel.Initialize(opts, bam_comments, bc.run_id, bc.chip_subset); // initialize the per base quality score generator - dependent on calibration bc.quality_generator.Init(opts, chip_type, bc_params.GetFiles().input_directory, bc_params.GetFiles().output_directory, bc.recalibration.is_enabled()); // Phase estimator bc.estimator.InitializeFromOptArgs(opts, bc.chip_subset, bc.keynormalizer); // Barcode classification BarcodeClassifier barcodes(opts, datasets, bc.flow_order, bc.keys, bc_params.GetFiles().output_directory, bc.chip_subset.GetChipSizeX(), bc.chip_subset.GetChipSizeY()); bc.barcodes = &barcodes; // Make sure calibration barcodes are initialized with default parameters BarcodeClassifier calibration_barcodes(null_opts, datasets_calibration, bc.flow_order, bc.keys, bc_params.GetFiles().output_directory, bc.chip_subset.GetChipSizeX(), bc.chip_subset.GetChipSizeY()); bc.calibration_barcodes = &calibration_barcodes; // Command line parsing officially over. Detect unknown options. opts.CheckNoLeftovers(); // Save some run info into our handy json file bc_params.SaveParamsToJson(basecaller_json, bc, chip_type); SaveBaseCallerProgress(0, bc_params.GetFiles().output_directory); MemUsage("RawWellsBasecalling"); // // Step 2. Filter training and phase estimation // // Find distribution of clonal reads for use in read filtering: filters.TrainClonalFilter(bc_params.GetFiles().output_directory, wells, mask, bc.polyclonal_filter); MemUsage("ClonalPopulation"); ReportState(analysis_start_time,"Polyclonal Filter Training Complete"); // Library phasing parameter estimation MemUsage("BeforePhaseEstimation"); if (not bc.estimator.HaveEstimates()) { wells.OpenForIncrementalRead(); bc.estimator.DoPhaseEstimation(&wells, &mask, bc.flow_order, bc.keys, (bc_params.NumThreads() == 1)); wells.Close(); } bc.estimator.ExportResultsToJson(basecaller_json["Phasing"]); bc.estimator.ExportTrainSubsetToJson(basecaller_json["TrainSubset"]); SaveJson(basecaller_json, bc_params.GetFiles().filename_json); SaveBaseCallerProgress(10, bc_params.GetFiles().output_directory); // Phase estimation assumed to be 10% of the work // Initialize Barcode Classifier(s) - dependent on phase estimates bc.barcodes->BuildPredictedSignals(bc.estimator.GetAverageCF(), bc.estimator.GetAverageIE(), bc.estimator.GetAverageDR()); bc.calibration_barcodes->BuildPredictedSignals(bc.estimator.GetAverageCF(), bc.estimator.GetAverageIE(), bc.estimator.GetAverageDR()); MemUsage("AfterPhaseEstimation"); ReportState(analysis_start_time,"Phase Parameter Estimation Complete"); MemUsage("BeforeBasecalling"); // // Step 3. Open wells and output BAM files & initialize writers // // Library data set writer - always bc.lib_writer.Open(bc_params.GetFiles().output_directory, datasets, 0, bc.chip_subset.NumRegions(), bc.flow_order, bc.keys[0].bases(), filters.GetLibBeadAdapters(), bc_params.NumBamWriterThreads(), basecaller_json, bam_comments); // Calibration reads data set writer - if applicable if (bc.have_calibration_panel) bc.calib_writer.Open(bc_params.GetFiles().output_directory, datasets_calibration, 0, bc.chip_subset.NumRegions(), bc.flow_order, bc.keys[0].bases(), filters.GetLibBeadAdapters(), bc_params.NumBamWriterThreads(), basecaller_json, bam_comments); // Test fragments data set writer - if applicable if (bc.process_tfs) bc.tf_writer.Open(bc_params.GetFiles().output_directory, datasets_tf, 1, bc.chip_subset.NumRegions(), bc.flow_order, bc.keys[1].bases(), filters.GetTFBeadAdapters(), bc_params.NumBamWriterThreads(), basecaller_json, bam_comments); // Unfiltered / unfiltered untrimmed data set writers - if applicable if (!bc.unfiltered_set.empty()) { bc.unfiltered_writer.Open(bc_params.GetFiles().unfiltered_untrimmed_directory, datasets_unfiltered_untrimmed, -1, bc.chip_subset.NumRegions(), bc.flow_order, bc.keys[0].bases(), filters.GetLibBeadAdapters(), bc_params.NumBamWriterThreads(), basecaller_json, bam_comments); bc.unfiltered_trimmed_writer.Open(bc_params.GetFiles().unfiltered_trimmed_directory, datasets_unfiltered_trimmed, -1, bc.chip_subset.NumRegions(), bc.flow_order, bc.keys[0].bases(), filters.GetLibBeadAdapters(), bc_params.NumBamWriterThreads(), basecaller_json, bam_comments); } // // Step 4. Execute threaded basecalling // time_t basecall_start_time; time(&basecall_start_time); pthread_mutex_init(&bc.mutex, NULL); pthread_t worker_id[bc_params.NumThreads()]; for (int worker = 0; worker < bc_params.NumThreads(); worker++) if (pthread_create(&worker_id[worker], NULL, BasecallerWorker, &bc)) { printf("*Error* - problem starting thread\n"); exit (EXIT_FAILURE); } for (int worker = 0; worker < bc_params.NumThreads(); worker++) pthread_join(worker_id[worker], NULL); pthread_mutex_destroy(&bc.mutex); time_t basecall_end_time; time(&basecall_end_time); // // Step 5. Close files and print out some statistics // printf("\n\nBASECALLING: called %d of %u wells in %1.0lf seconds with %d threads\n\n", filters.NumWellsCalled(), bc.chip_subset.NumWells(), difftime(basecall_end_time,basecall_start_time), bc_params.NumThreads()); bc.lib_writer.Close(datasets, "Library"); if (bc.have_calibration_panel) bc.calib_writer.Close(datasets_calibration, "IonControl"); if (bc.process_tfs) bc.tf_writer.Close(datasets_tf, "Test Fragments"); filters.TransferFilteringResultsToMask(mask); if (!bc.unfiltered_set.empty()) { // Must happen after filters transferred to mask bc.WriteUnfilteredFilterStatus(bc_params.GetFiles()); bc.unfiltered_writer.Close(datasets_unfiltered_untrimmed); bc.unfiltered_trimmed_writer.Close(datasets_unfiltered_trimmed); datasets_unfiltered_untrimmed.SaveJson(bc_params.GetFiles().unfiltered_untrimmed_directory+"/datasets_basecaller.json"); datasets_unfiltered_trimmed.SaveJson(bc_params.GetFiles().unfiltered_trimmed_directory+"/datasets_basecaller.json"); } metric_saver.Close(); barcodes.Close(datasets); calibration_barcodes.Close(datasets_calibration); if (bc.have_calibration_panel) { datasets.json()["IonControl"]["datasets"] = datasets_calibration.json()["datasets"]; datasets.json()["IonControl"]["read_groups"] = datasets_calibration.read_groups(); } datasets.SaveJson(bc_params.GetFiles().output_directory+"/datasets_basecaller.json"); if (bc.process_tfs) datasets_tf.SaveJson(bc_params.GetFiles().output_directory+"/datasets_tf.json"); // Generate BaseCaller.json bc.lib_writer.SaveFilteringStats(basecaller_json, "lib", true); if (bc.have_calibration_panel) bc.calib_writer.SaveFilteringStats(basecaller_json, "control", false); if (bc.process_tfs) bc.tf_writer.SaveFilteringStats(basecaller_json, "tf", false); time_t analysis_end_time; time(&analysis_end_time); basecaller_json["BaseCaller"]["end_time"] = get_time_iso_string(analysis_end_time); basecaller_json["BaseCaller"]["total_duration"] = (int)difftime(analysis_end_time,analysis_start_time); basecaller_json["BaseCaller"]["basecalling_duration"] = (int)difftime(basecall_end_time,basecall_start_time); basecaller_json["Filtering"]["qv_histogram"] = Json::arrayValue; for (int qv = 0; qv < 50; ++qv) basecaller_json["Filtering"]["qv_histogram"][qv] = (Json::UInt64)bc.lib_writer.qv_histogram()[qv]; SaveJson(basecaller_json, bc_params.GetFiles().filename_json); SaveBaseCallerProgress(100, bc_params.GetFiles().output_directory); mask.WriteRaw (bc_params.GetFiles().filename_filter_mask.c_str()); mask.validateMask(); MemUsage("AfterBasecalling"); ReportState(analysis_start_time,"Basecalling Complete"); return EXIT_SUCCESS; }
int main (int argc, const char *argv[]) { if (argc == 1) { printf ("BaseCallerLite - Bare bone basecaller\n"); printf ("\n"); printf ("Usage:\n"); printf ("BaseCallerLite [options]\n"); printf ("\tOptions:\n"); printf ("\t\tComing soon\n"); printf ("\n"); return 1; } string libKey = "TCAG"; string inputDirectory = "."; string outputDirectory = "."; bool singleCoreCafie = false; BaseCallerLite basecaller; basecaller.regionXSize = 50; basecaller.regionYSize = 50; basecaller.runId = "BCLTE"; basecaller.CF = 0.0; basecaller.IE = 0.0; basecaller.numWellsCalled = 0; basecaller.nextRegionX = 0; basecaller.nextRegionY = 0; OptArgs opts; opts.ParseCmdLine(argc, argv); opts.GetOption(basecaller.CF, "0.0", '-', "cf"); opts.GetOption(basecaller.IE, "0.0", '-', "ie"); opts.GetOption(inputDirectory, ".", '-', "input-dir"); opts.GetOption(outputDirectory, ".", '-', "output-dir"); opts.GetOption(singleCoreCafie, "false", '-', "singlecorecafie"); int numWorkers = 2*numCores(); if (singleCoreCafie) numWorkers = 1; Mask mask (1, 1); if (mask.SetMask ((inputDirectory + "/bfmask.bin").c_str())) exit (EXIT_FAILURE); RawWells wells (inputDirectory.c_str(),"1.wells"); //SetWellsToLiveBeadsOnly(wells,&mask); wells.OpenForIncrementalRead(); basecaller.maskPtr = &mask; basecaller.wellsPtr = &wells; basecaller.rows = mask.H(); basecaller.cols = mask.W(); basecaller.flowOrder.SetFlowOrder(wells.FlowOrder(), wells.NumFlows()); basecaller.numFlows = wells.NumFlows(); basecaller.numRegionsX = (basecaller.cols + basecaller.regionXSize - 1) / basecaller.regionXSize; basecaller.numRegionsY = (basecaller.rows + basecaller.regionYSize - 1) / basecaller.regionYSize; basecaller.numRegions = basecaller.numRegionsX * basecaller.numRegionsY; basecaller.libKeyFlows.assign(basecaller.numFlows,0); basecaller.libNumKeyFlows = basecaller.flowOrder.BasesToFlows(libKey, &basecaller.libKeyFlows[0], basecaller.numFlows); basecaller.libSFF.Open(outputDirectory+"/rawlib.sff", basecaller.numRegions, basecaller.flowOrder, libKey); time_t startBasecall; time(&startBasecall); pthread_mutex_init(&basecaller.wellsAccessMutex, NULL); pthread_t worker_id[numWorkers]; for (int iWorker = 0; iWorker < numWorkers; iWorker++) if (pthread_create(&worker_id[iWorker], NULL, BasecallerWorkerWrapper, &basecaller)) { printf("*Error* - problem starting thread\n"); return 1; } for (int iWorker = 0; iWorker < numWorkers; iWorker++) pthread_join(worker_id[iWorker], NULL); pthread_mutex_destroy(&basecaller.wellsAccessMutex); time_t endBasecall; time(&endBasecall); basecaller.libSFF.Close(); printf("\nBASECALLING: called %d of %d wells in %1.1f seconds with %d threads\n", basecaller.numWellsCalled, basecaller.rows*basecaller.cols, difftime(endBasecall,startBasecall), numWorkers); printf("Generated library SFF with %d reads\n", basecaller.libSFF.num_reads()); return 0; }
void BFReference::CalcSignalReference(const std::string &datFile, const std::string &bgFile, Mask &mask, int traceFrame) { Image bfImg; Image bfBkgImg; bfImg.SetImgLoadImmediate (false); bfBkgImg.SetImgLoadImmediate (false); bool loaded = bfImg.LoadRaw(datFile.c_str()); bool bgLoaded = bfBkgImg.LoadRaw(bgFile.c_str()); if (!loaded) { ION_ABORT("*Error* - No beadfind file found, did beadfind run? are files transferred? (" + datFile + ")"); } if (!bgLoaded) { ION_ABORT("*Error* - No beadfind background file found, did beadfind run? are files transferred? (" + bgFile + ")"); } const RawImage *raw = bfImg.GetImage(); assert(raw->cols == GetNumCol()); assert(raw->rows == GetNumRow()); assert(raw->cols == mask.W()); assert(raw->rows == mask.H()); bfImg.FilterForPinned(&mask, MaskEmpty, false); bfBkgImg.FilterForPinned(&mask, MaskEmpty, false); // bfImg.XTChannelCorrect(&mask); bfImg.XTChannelCorrect(); // bfBkgImg.XTChannelCorrect(&mask); bfBkgImg.XTChannelCorrect(); Traces trace; trace.Init(&bfImg, &mask, FRAMEZERO, FRAMELAST, FIRSTDCFRAME,LASTDCFRAME); bfImg.Close(); Traces bgTrace; bgTrace.Init(&bfBkgImg, &mask, FRAMEZERO, FRAMELAST, FIRSTDCFRAME,LASTDCFRAME); bfBkgImg.Close(); if (mDoRegionalBgSub) { trace.SetMeshDist(0); bgTrace.SetMeshDist(0); } trace.SetT0Step(mRegionXSize); bgTrace.SetT0Step(mRegionXSize); trace.CalcT0(true); size_t numWells = trace.GetNumRow() * trace.GetNumCol(); for (size_t i = 0; i < numWells; i++) { trace.SetT0(max(trace.GetT0(i) - 3, 0.0f), i); } bgTrace.SetT0(trace.GetT0()); trace.T0DcOffset(0,4); trace.FillCriticalFrames(); trace.CalcReference(mRegionXSize,mRegionYSize,trace.mGridMedian); bgTrace.T0DcOffset(0,4); bgTrace.FillCriticalFrames(); bgTrace.CalcReference(mRegionXSize,mRegionYSize,bgTrace.mGridMedian); int length = GetNumRow() * GetNumCol(); mBfMetric.resize(length, std::numeric_limits<double>::signaling_NaN()); vector<double> rawTrace(trace.GetNumFrames()); vector<double> bgRawTrace(bgTrace.GetNumFrames()); int pinned =0, excluded = 0; for (int i = 0; i < length; i++) { if (mask[i] & MaskExclude || mask[i] & MaskPinned) { continue; if (mask[i] & MaskExclude) { excluded++; } else if (mask[i] & MaskPinned) { pinned++; } } trace.GetTraces(i, rawTrace.begin()); bgTrace.GetTraces(i, bgRawTrace.begin()); mBfMetric[i] = 0; for (int s = 3; s < 15; s++) { mBfMetric[i] += rawTrace[s] - bgRawTrace[s]; } } cout << "Pinned: " << pinned << " excluded: " << excluded << endl; for (int i = 0; i < length; i++) { if (mask[i] & MaskExclude || mask[i] & MaskPinned || mask[i] & MaskIgnore) { mWells[i] = Exclude; } else { mask[i] = MaskIgnore; } } cout << "Filling reference. " << endl; FillInReference(mWells, mBfMetric, mGrid, mMinQuantile, mMaxQuantile, mNumEmptiesPerRegion); for (int i = 0; i < length; i++) { if (mWells[i] == Reference) { mask[i] = MaskEmpty; } } bfImg.Close(); }
void BFReference::CalcSignalReference2(const std::string &datFile, const std::string &bgFile, Mask &mask, int traceFrame) { Image bfImg; Image bfBkgImg; bfImg.SetImgLoadImmediate (false); bfBkgImg.SetImgLoadImmediate (false); bool loaded = bfImg.LoadRaw(datFile.c_str()); bool bgLoaded = bfBkgImg.LoadRaw(bgFile.c_str()); if (!loaded) { ION_ABORT("*Error* - No beadfind file found, did beadfind run? are files transferred? (" + datFile + ")"); } if (!bgLoaded) { ION_ABORT("*Error* - No beadfind background file found, did beadfind run? are files transferred? (" + bgFile + ")"); } const RawImage *raw = bfImg.GetImage(); assert(raw->cols == GetNumCol()); assert(raw->rows == GetNumRow()); assert(raw->cols == mask.W()); assert(raw->rows == mask.H()); int StartFrame = bfImg.GetFrame(-663); //5 int EndFrame = bfImg.GetFrame(350); //20 int NNinnerx = 1, NNinnery = 1, NNouterx = 12, NNoutery = 8; cout << "DC start frame: " << StartFrame << " end frame: " << EndFrame << endl; bfImg.FilterForPinned(&mask, MaskEmpty, false); bfImg.XTChannelCorrect(); // bfImg.XTChannelCorrect(&mask); Traces trace; trace.Init(&bfImg, &mask, FRAMEZERO, FRAMELAST, FIRSTDCFRAME,LASTDCFRAME); bfImg.Normalize(StartFrame, EndFrame); if (mDoRegionalBgSub) { trace.SetMeshDist(0); } trace.CalcT0(true); if (mDoRegionalBgSub) { GridMesh<float> grid; grid.Init(raw->rows, raw->cols, mRegionYSize, mRegionXSize); int numBin = grid.GetNumBin(); int rowStart = -1, rowEnd = -1, colStart = -1, colEnd = -1; for (int binIx = 0; binIx < numBin; binIx++) { cout << "BG Subtract Region: " << binIx << endl; grid.GetBinCoords(binIx, rowStart, rowEnd, colStart, colEnd); Region reg; reg.row = rowStart; reg.h = rowEnd - rowStart; reg.col = colStart; reg.w = colEnd - colStart; bfImg.BackgroundCorrectRegion(&mask, reg, MaskAll, MaskEmpty, NNinnerx, NNinnery, NNouterx, NNoutery, NULL); } } else { bfImg.BackgroundCorrect(&mask, MaskEmpty, MaskEmpty, NNinnerx, NNinnery, NNouterx, NNoutery, NULL); } int length = GetNumRow() * GetNumCol(); mBfMetric.resize(length, std::numeric_limits<double>::signaling_NaN()); for (int wIx = 0; wIx < length; wIx++) { if (mask[wIx] & MaskExclude || mask[wIx] & MaskPinned) continue; int t0 = (int)trace.GetT0(wIx); mBfMetric[wIx] = 0; float zSum = 0; int count = 0; for (int fIx = min(t0-20, 0); fIx < t0-10; fIx++) { zSum += bfImg.At(wIx,fIx); count ++; } for (int fIx = t0+3; fIx < t0+15; fIx++) { mBfMetric[wIx] += (bfImg.At(wIx,fIx) - (zSum / count)); } } bfImg.Close(); for (int i = 0; i < length; i++) { if (mask[i] & MaskExclude || mWells[i] == Exclude) { mWells[i] = Exclude; } else { mask[i] = MaskIgnore; } } cout << "Filling reference. " << endl; FillInReference(mWells, mBfMetric, mGrid, mMinQuantile, mMaxQuantile, mNumEmptiesPerRegion); for (int i = 0; i < length; i++) { if (mWells[i] == Reference) { mask[i] = MaskEmpty; } } }
void BFReference::CalcReference(const std::string &datFile, Mask &mask, std::vector<float> &metric) { Image bfImg; bfImg.SetImgLoadImmediate (false); bool loaded = bfImg.LoadRaw(datFile.c_str()); if (!loaded) { ION_ABORT("*Error* - No beadfind file found, did beadfind run? are files transferred? (" + datFile + ")"); } const RawImage *raw = bfImg.GetImage(); assert(raw->cols == GetNumCol()); assert(raw->rows == GetNumRow()); assert(raw->cols == mask.W()); assert(raw->rows == mask.H()); if (!mDebugFile.empty()) { DebugTraces(mDebugFile, mask, bfImg); } bfImg.FilterForPinned(&mask, MaskEmpty, false); // int StartFrame= bfImg.GetFrame((GetDcStart()*1000/15)-1000); // int EndFrame = bfImg.GetFrame((GetDcEnd()*1000/15)-1000); int StartFrame = bfImg.GetFrame(-663); //5 int EndFrame = bfImg.GetFrame(350); //20 cout << "DC start frame: " << StartFrame << " end frame: " << EndFrame << endl; bfImg.XTChannelCorrect(); FilterForOutliers(bfImg, mask, mIqrOutlierMult, mRegionYSize, mRegionXSize); bfImg.Normalize(StartFrame, EndFrame); // bfImg.XTChannelCorrect(&mask); int NNinnerx = 1, NNinnery = 1, NNouterx = 12, NNoutery = 8; if (mDoRegionalBgSub) { GridMesh<float> grid; grid.Init(raw->rows, raw->cols, mRegionYSize, mRegionXSize); int numBin = grid.GetNumBin(); int rowStart = -1, rowEnd = -1, colStart = -1, colEnd = -1; for (int binIx = 0; binIx < numBin; binIx++) { grid.GetBinCoords(binIx, rowStart, rowEnd, colStart, colEnd); Region reg; reg.row = rowStart; reg.h = rowEnd - rowStart; reg.col = colStart; reg.w = colEnd - colStart; bfImg.BackgroundCorrectRegion(&mask, reg, MaskAll, MaskEmpty, NNinnerx, NNinnery, NNouterx, NNoutery, NULL); } } else { bfImg.BackgroundCorrect(&mask, MaskEmpty, MaskEmpty, NNinnerx, NNinnery, NNouterx, NNoutery, NULL); } Region region; region.col = 0; region.row = 0; region.w = GetNumCol(); //mGrid.GetColStep(); region.h = GetNumRow(); // mGrid.GetRowStep(); int startFrame = bfImg.GetFrame(12); // frame 15 on uncompressed 314 // int endFrame = bfImg.GetFrame(raw->timestamps[bfImg.Ge]5300); // frame 77 or so int endFrame = bfImg.GetFrame(5000); // frame 77 or so bfImg.CalcBeadfindMetric_1(&mask, region, "pre", startFrame, endFrame); const double *results = bfImg.GetResults(); int length = GetNumRow() * GetNumCol(); metric.resize(length); copy(&results[0], &results[0] + (length), metric.begin()); bfImg.Close(); }