Reading a binary InterOp file

Reading a binary Interop file is really just two lines of code, but all sorts of unexpected situations may arise. This example shows you how to write bullet proof code to read an Illumina InterOp file.

Simple method

C++

Shows how to read a single metric set using run_metrics

std::vector<unsigned char> valid_to_load(constants::MetricCount, 0);
valid_to_load[constants::Q]=1;
run_metrics metrics;
try
{
metrics.read(filename, valid_to_load);
}
catch(const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
metric_set<q_metric>& q_metric_set = metrics.get<model::metrics::q_metric>();

C#

Shows how to read all metrics required by the imaging tab in SAV

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);

Advanced method

Not recommneded for most users.

C++

#include <iostream>
using namespace illumina::interop::io;
int check_args(int argc);
int main(int argc, char** argv)
{
int ret;
if((ret = check_args(argc)) != 0) return ret;
try {
read_interop(argv[1], tile_metric_set);
}
catch(const incomplete_file_exception&){}// Ignore incomplete files
catch(const bad_format_exception& ex) // Something catastrophic happened to the file
{
std::cerr << "InterOp did not have the expected format: " << ex.what() << std::endl;
return 1;
}
catch(const file_not_found_exception& ex)
{
std::cerr << "Count not find InterOp file: " << ex.what() << std::endl;
return 1;
}
std::cout << "Tile metric set contains " << tile_metric_set.size() << " metrics" << std::endl;
return 0;
}

C

using System;
using Illumina.InterOp.Run;
using Illumina.InterOp.Metrics;
using Illumina.InterOp.Comm;
class Example1
{
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;
}
base_tile_metrics tile_metric_set = new base_tile_metrics ();
try
{
c_csharp_comm.read_interop (args [0], tile_metric_set);
}
catch(incomplete_file_exception){}
catch(file_not_found_exception ex)
{
Console.WriteLine("File not found: "+args [0]);
Console.WriteLine (ex);
return 1;
}
catch(bad_format_exception ex)
{
Console.WriteLine (ex);
return 1;
}
Console.Write ("Tile metric set contains {0} metrics", tile_metric_set.size());
return 0;
}
}