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 dataimaging_column_vector
: Vector of columns for the imaging tablemap_id_offset
: map row ID to the offset in the float arrayvalid_to_load
: byte array (std::vector<unsigned char>
oruchar_vector
) indicating which InterOp files to load
The primary functions used below are:
run_metrics::read
: read the InterOp files from diskcreate_imaging_table_columns
: Generate the available column groups from the metric setcount_table_rows
: Count the number of necessary rows from the metric setcount_table_columns
: Count the number of subcolumns for the tablepopulate_imaging_table_data
: Populate the array of data for the tablelist_imaging_table_metrics_to_load
: list which imaging metrics will be loaded
C#
using System;
class ImagingTableExample
{
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;
logic::table::list_imaging_table_metrics_to_load(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)
{
std::cout << "Expected: $ imaging_table <run-folder1> <run-folder2> ... <run-folderN>" << std::endl;
return ret;
}
#ifdef INTEROP_TEST_CSHARP_BINDING
std::vector<model::table::imaging_column> columns;
logic::table::row_offset_map_t row_offsets;
logic::table::create_imaging_table_columns(run, 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
{
logic::table::create_imaging_table(run, table);
}
catch(const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return UNEXPECTED_EXCEPTION;
}
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;
return MISSING_RUNINFO_XML;
}
{
std::cerr << ex.what() << std::endl;
return MALFORMED_XML;
}
{
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;
return UNEXPECTED_EXCEPTION;
}
if(check_empty && metrics.empty())
{
std::cerr << "No InterOp files found" << std::endl;
return EMPTY_INTEROP;
}