Imaging

This section introduces the way SAV calculates the Imaging tab. This introduces a limited set of functions. The key classes used below are:

  • run_metrics: model holding the binary InterOp data
  • imaging_column_vector: Vector of columns for the imaging table
  • map_id_offset: map row ID to the offset in the float array
  • valid_to_load: byte array (std::vector<unsigned char> or uchar_vector) indicating which InterOp files to load

The primary functions used below are:

  • run_metrics::read: read the InterOp files from disk
  • create_imaging_table_columns: Generate the available column groups from the metric set
  • count_table_rows: Count the number of necessary rows from the metric set
  • count_table_columns: Count the number of subcolumns for the table
  • populate_imaging_table_data: Populate the array of data for the table
  • list_imaging_table_metrics_to_load: list which imaging metrics will be loaded

C#

using System;
using Illumina.InterOp.Run;
using Illumina.InterOp.Metrics;
using Illumina.InterOp.RunMetrics;
using Illumina.InterOp.Comm;
using Illumina.InterOp.Table;
{
static int Main(string[] args)
{
if (args.Length != 1)
{
if (args.Length < 1)
Console.WriteLine ("No run folder");
else
Console.WriteLine ("Too many arguments");
return 1;
}
// @ [Reading only metrics required by the Imaging Tab]
run_metrics metrics = new run_metrics();
uchar_vector interopsToLoad = new uchar_vector();
// Load only the metrics required by imaging table
c_csharp_table.list_imaging_table_metrics_to_load(interopsToLoad);
metrics.read(args[0], interopsToLoad);
// @ [Reading only metrics required by the Imaging Tab]
imaging_column_vector columnVector = new imaging_column_vector();
map_id_offset rowOffsets = new map_id_offset();
c_csharp_table.create_imaging_table_columns(metrics, columnVector);
c_csharp_table.count_table_rows(metrics, rowOffsets);
int rowCount = rowOffsets.Count;
int columnCount = (int)c_csharp_table.count_table_columns(columnVector);
float[] data = new float[rowCount * columnCount];
c_csharp_table.populate_imaging_table_data(metrics, columnVector, rowOffsets, data, (uint)data.Length);
for(int rowIndex=0;rowIndex<rowCount;++rowIndex)
{
for(int groupIndex=0;groupIndex<columnVector.Count;++groupIndex)
{
if(columnVector[groupIndex].has_children())
{
for(int subColumnIndex=0;subColumnIndex<columnVector[groupIndex].subcolumns().Count;++subColumnIndex)
{
int columnIndex = (int)(columnVector[groupIndex].offset()+subColumnIndex);
Console.Write("{0},", data[rowIndex*columnCount + columnIndex]);
}
}
else
{
int columnIndex = (int)(columnVector[groupIndex].offset());
Console.Write("{0},", data[rowIndex*columnCount + columnIndex]);
}
}
Console.WriteLine();
}
return 0;
}
}

C++

The following shows how to calculate the Imaging metrics:

std::vector<unsigned char> valid_to_load;
for (int i = 1; i < argc; i++)
{
run_metrics run;
std::cout << "# Run Folder: " << io::basename(argv[i]) << std::endl;
int ret = read_run_metrics(argv[i], run, valid_to_load, thread_count);
if (ret != SUCCESS) return ret;
#ifdef INTEROP_TEST_CSHARP_BINDING
std::vector<model::table::imaging_column> columns;
const size_t column_count = logic::table::count_table_columns(columns);
logic::table::count_table_rows(run, row_offsets);
std::vector<float> data(row_offsets.size()*column_count);
logic::table::populate_imaging_table_data(run, columns, row_offsets, &data[0], data.size());
#endif
model::table::imaging_table table;
try
{
}
catch(const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
}
std::cout << table << std::endl;
}

The following shows the implementation of read_run_metrics above and how to read the InterOp data from disk:

using namespace illumina::interop;
using namespace illumina::interop::model;
try
{
metrics.clear();
metrics.read(filename, valid_to_load, thread_count);
}
{
std::cerr << ex.what() << std::endl;
}
catch(const xml::xml_parse_exception& ex)
{
std::cerr << ex.what() << std::endl;
return MALFORMED_XML;
}
catch(const io::bad_format_exception& ex)
{
std::cerr << ex.what() << std::endl;
return BAD_FORMAT;
}
{
std::cerr << ex.what() << std::endl;
}
catch(const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
}
if(check_empty && metrics.empty())
{
std::cerr << "No InterOp files found" << std::endl;
return EMPTY_INTEROP;
}