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>
#include "interop/model/metric_base/metric_set.h"
#include "interop/model/metrics/tile_metric.h"
#include "interop/io/metric_file_stream.h"
using namespace illumina::interop::model::metric_base;
using namespace illumina::interop::model::metrics;
using namespace illumina::interop::io;
{
int ret;
try {
read_interop(argv[1], tile_metric_set);
}
{
std::cerr << "InterOp did not have the expected format: " << ex.what() << std::endl;
return 1;
}
{
std::cerr << "Count not find InterOp file: " << ex.what() << std::endl;
return 1;
}
return 0;
}
C
using System;
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;
}
}