Skip to content

Commit

Permalink
Merge pull request #525 from Bioinformatics/ipa-6036-fix-collapsed-q
Browse files Browse the repository at this point in the history
IPA-6036: Fix collapsed q-metrics for BaseSpace
  • Loading branch information
ezralanglois authored and GitHub Enterprise committed Jan 24, 2017
2 parents a6ec230 + 79c7297 commit bc8610b
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 18 deletions.
28 changes: 15 additions & 13 deletions src/interop/model/metrics/q_collapsed_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ namespace illumina{ namespace interop{ namespace io {
}
else
{
if(count != TOTAL_RECORD_SIZE )
INTEROP_THROW( incomplete_file_exception, "Insufficient data read from the file, got: "<<
count << " != expected: " << TOTAL_RECORD_SIZE );
return ALT_RECORD_SIZE;
if(count != RECORD_SIZE )
INTEROP_THROW( incomplete_file_exception, "Insufficient data read from the file, got: "
<< count << " != expected: " << RECORD_SIZE );
return RECORD_SIZE;
}
return count;
}
Expand All @@ -116,11 +116,12 @@ namespace illumina{ namespace interop{ namespace io {
*
* @note The size of the record is not fixed for this format, the median q-score may more may not be there
*
* @return 1
* @param header collapsed q metric header
* @return record size
*/
static record_size_t compute_size(const q_collapsed_metric::header_type&)
static record_size_t compute_size(const q_collapsed_metric::header_type& header)
{
return static_cast<record_size_t>(ALT_RECORD_SIZE);
return static_cast<record_size_t>(header.m_record_size == 0 ? ALT_RECORD_SIZE : header.m_record_size);
}

/** Compute header size
Expand Down Expand Up @@ -309,7 +310,7 @@ namespace illumina{ namespace interop{ namespace io {
* 2. Version: 5
*/
template<>
struct generic_layout<q_collapsed_metric, 5> : public default_layout<5, 1 /*Tmp hack */>
struct generic_layout<q_collapsed_metric, 5> : public default_layout<5>
{
/** @page q_collapsed_v5 Collapsed Q-Metrics Version 5
*
Expand Down Expand Up @@ -399,21 +400,22 @@ namespace illumina{ namespace interop{ namespace io {
}
else
{
if (count != TOTAL_RECORD_SIZE)
if (count != RECORD_SIZE)
INTEROP_THROW(incomplete_file_exception, "Insufficient data read from the file, got: " <<
count << " != expected: " << TOTAL_RECORD_SIZE);
return ALT_RECORD_SIZE;
count << " != expected: " << RECORD_SIZE);
return RECORD_SIZE;
}
return count;
}

/** Compute the layout size
*
* @param header collapsed q metric header
* @return size of the record
*/
static record_size_t compute_size(const q_collapsed_metric::header_type &)
static record_size_t compute_size(const q_collapsed_metric::header_type & header)
{
return static_cast<record_size_t>(ALT_RECORD_SIZE);
return static_cast<record_size_t>(header.m_record_size == 0 ? ALT_RECORD_SIZE : header.m_record_size);
}
/** Map reading/writing a header to a stream
*
Expand Down
2 changes: 2 additions & 0 deletions src/tests/interop/metrics/inc/metric_format_fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace illumina{ namespace interop { namespace unittest
q_collapsed_metric_v4,
q_collapsed_metric_v5,
q_collapsed_metric_v6,
q_collapsed_metric_no_median_v2,
q_collapsed_metric_no_median_v5,
q_metric_v4,
q_metric_v5,
q_metric_v6,
Expand Down
145 changes: 143 additions & 2 deletions src/tests/interop/metrics/inc/q_collapsed_metrics_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ namespace illumina{ namespace interop { namespace unittest
typedef typename parent_t::metric_t metric_t;
enum{
/** Do not check the expected binary data */
disable_binary_data=true,
disable_binary_data=true, // work around for dropping header
/** Do not check the expected binary data size */
disable_binary_data_size=true
disable_binary_data_size=true // work around for dropping header
};
/** Create the expected metric set
*
Expand Down Expand Up @@ -151,6 +151,147 @@ namespace illumina{ namespace interop { namespace unittest
*/
struct q_collapsed_metric_v6 : q_collapsed_metric_v5_6<6>{};

/** This generator creates an expected metric set and the corresponding binary data
*
* @see model::metrics::q_collapsed_metric
*/
template<int Version>
struct q_collapsed_metric_no_median_v_2_4 : metric_test<model::metrics::q_collapsed_metric, Version>
{
enum{
/** Do not check the expected binary data */
disable_binary_data=true,
/** Do not check the expected binary data size */
disable_binary_data_size=true
};
/** Define a parent type */
typedef metric_test<model::metrics::q_collapsed_metric, Version> parent_t;
/** Define a metric set type */
typedef typename parent_t::metric_set_t metric_set_t;
/** Define a metric type */
typedef typename parent_t::metric_t metric_t;
/** Create the expected metric set
*
* @param metrics destination metric set
*/
static void create_expected(metric_set_t& metrics, const model::run::info& =model::run::info())
{
metrics = metric_set_t(parent_t::VERSION);
metrics.insert(metric_t(1,1105,1,2447414,2334829,2566750,0));
metrics.insert(metric_t(1,1103,1,2436317,2327796,2543605,0));
metrics.insert(metric_t(1,1106,1,2474217,2366046,2583629,0));
}
/** Get the expected binary data
*
* @param buffer binary data string
*/
template<class Collection>
static void create_binary_data(Collection& buffer)
{
const int tmp[] =
{
Version,18
,1,0,81,4,1,0,54,88,37,0,109,-96,35,0,94,42,39,0
,1,0,79,4,1,0,-35,44,37,0,-12,-124,35,0,-11,-49,38,0
,1,0,82,4,1,0,-23,-64,37,0,94,26,36,0,77,108,39,0
};
buffer.assign(tmp, tmp+util::length_of(tmp));
}
};
/** This generator creates an expected metric set and the corresponding binary data
*
* @see model::metrics::q_collapsed_metric
* @note Version 2
*/
struct q_collapsed_metric_no_median_v2 : q_collapsed_metric_no_median_v_2_4<2>{};
/** This generator creates an expected metric set and the corresponding binary data
*
* @see model::metrics::q_collapsed_metric
* @note Version 3
*/
struct q_collapsed_metric_no_median_v3 : q_collapsed_metric_no_median_v_2_4<3>{};
/** This generator creates an expected metric set and the corresponding binary data
*
* @see model::metrics::q_collapsed_metric
* @note Version 4
*/
struct q_collapsed_metric_no_median_v4 : q_collapsed_metric_no_median_v_2_4<4>{};


/** This generator creates an expected metric set and the corresponding binary data
*
* @see model::metrics::q_collapsed_metric
* @note Version 6
*/
template<int Version>
struct q_collapsed_metric_no_median_v5_6 : metric_test<model::metrics::q_collapsed_metric, Version>
{
/** Define a parent type */
typedef metric_test<model::metrics::q_collapsed_metric, Version> parent_t;
/** Define a metric set type */
typedef typename parent_t::metric_set_t metric_set_t;
/** Define a metric type */
typedef typename parent_t::metric_t metric_t;
enum{
/** Do not check the expected binary data */
disable_binary_data=true,
/** Do not check the expected binary data size */
disable_binary_data_size=true
};
/** Create the expected metric set
*
* @param metrics destination metric set
*/
static void create_expected(metric_set_t& metrics, const model::run::info& =model::run::info())
{
typedef typename metric_set_t::header_type header_t;
typedef typename header_t::qscore_bin_vector_type qscore_bin_vector_type;
typedef typename header_t::bin_t bin_t;
typedef typename bin_t::bin_type ushort_t;
typedef typename metric_t::uint_t uint_t;
const uint_t bin_count = 7;

const ushort_t lower[] = {2, 10, 20, 25, 30, 35, 40};
const ushort_t upper[] = {9, 19, 24, 29, 34, 39, 40};
const ushort_t value[] = {2, 14, 21, 27, 32, 36, 40};
qscore_bin_vector_type headervec;
for(uint_t i=0;i<bin_count;i++)
headervec.push_back(bin_t(lower[i], upper[i], value[i]));

metrics = metric_set_t(header_t(headervec), parent_t::VERSION);
metrics.insert(metric_t(1,1105,1,2447414,2334829,2566750,0));
metrics.insert(metric_t(1,1103,1,2436317,2327796,2543605,0));
metrics.insert(metric_t(1,1106,1,2474217,2366046,2583629,0));
}
/** Get the expected binary data
*
* @param buffer binary data string
*/
template<class Collection>
static void create_binary_data(Collection& buffer)
{
const int tmp[] =
{
Version,18,1,7,2,10,20,25,30,35,40,9,19,24,29,34,39,40,2,14,21,27,32,36,40
,1,0,81,4,1,0,54,88,37,0,109,-96,35,0,94,42,39,0
,1,0,79,4,1,0,-35,44,37,0,-12,-124,35,0,-11,-49,38,0
,1,0,82,4,1,0,-23,-64,37,0,94,26,36,0,77,108,39,0
};
buffer.assign(tmp, tmp+util::length_of(tmp));
}
};
/** This generator creates an expected metric set and the corresponding binary data
*
* @see model::metrics::q_collapsed_metric
* @note Version 5
*/
struct q_collapsed_metric_no_median_v5 : q_collapsed_metric_no_median_v5_6<5>{};
/** This generator creates an expected metric set and the corresponding binary data
*
* @see model::metrics::q_collapsed_metric
* @note Version 6
*/
struct q_collapsed_metric_no_median_v6 : q_collapsed_metric_no_median_v5_6<6>{};

}}}

52 changes: 49 additions & 3 deletions src/tests/interop/metrics/q_collapsed_metrics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ q_collapsed_metrics_tests::generator_type q_collapsed_unit_test_generators[] = {
wrap(new hardcoded_metric_generator< q_collapsed_metric_v5 >),
wrap(new write_read_metric_generator< q_collapsed_metric_v5 >),
wrap(new hardcoded_metric_generator< q_collapsed_metric_v6 >),
wrap(new write_read_metric_generator< q_collapsed_metric_v6 >)
,wrap(new by_cycle_metric_generator< q_collapsed_metric_v5 >),
wrap(new write_read_metric_generator< q_collapsed_metric_v6 >),
wrap(new by_cycle_metric_generator< q_collapsed_metric_v5 >),
wrap(new by_cycle_metric_generator< q_collapsed_metric_v4 >),
wrap(new by_cycle_metric_generator< q_collapsed_metric_v3 >),
wrap(new by_cycle_metric_generator< q_collapsed_metric_v2 >),
wrap(new by_cycle_metric_generator< q_collapsed_metric_v6 >)
wrap(new by_cycle_metric_generator< q_collapsed_metric_v6 >),
wrap(new hardcoded_metric_generator< q_collapsed_metric_no_median_v2 >),
wrap(new hardcoded_metric_generator< q_collapsed_metric_no_median_v5 >),
wrap(new write_read_metric_generator< q_collapsed_metric_no_median_v2 >),
wrap(new write_read_metric_generator< q_collapsed_metric_no_median_v5 >)

};

// Setup unit tests for q_collapsed_metrics_tests
Expand Down Expand Up @@ -116,6 +121,47 @@ TEST(q_collapsed_metrics_test, test_convert_write_read)
}
}

TEST(q_collapsed_metrics_test, compute_buffer_size)
{
typedef model::run::flowcell_layout::uint_t uint_t;
run_metrics metrics;


const uint_t swath_count = 4;
const uint_t tile_count = 99;
const uint_t sections_per_lane = 1;
const uint_t lanes_per_section = 1;
const uint_t lane_count = 8;//expected.max_lane();
const uint_t surface_count = 2;
const model::run::read_info read_array[]={
model::run::read_info(1, 1, 4, false)
};
std::vector<std::string> channels;
model::run::info run_info("XX",
"",
1,
model::run::flowcell_layout(lane_count,
surface_count,
swath_count,
tile_count,
sections_per_lane,
lanes_per_section),
channels,
model::run::image_dimensions(),
util::to_vector(read_array));

q_metric_v6::create_expected(metrics.get<q_metric>());
metrics.run_info(run_info);
metrics.legacy_channel_update(constants::HiSeq);
metrics.finalize_after_load();

EXPECT_GT(metrics.get<q_collapsed_metric>().size(), 0u);

const size_t buffer_size = io::compute_buffer_size(metrics.get<q_collapsed_metric>());
EXPECT_GT(buffer_size, 0u);

}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit bc8610b

Please sign in to comment.