-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'smalton/DOR-750-per-barcode-polya-config' into 'master'
[DOR-750] Per-barcode polyA config overrides Closes DOR-750 See merge request machine-learning/dorado!1165
- Loading branch information
Showing
12 changed files
with
296 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "poly_tail_calculator_selector.h" | ||
|
||
#include "poly_tail_calculator.h" | ||
#include "poly_tail_config.h" | ||
|
||
#include <fstream> | ||
#include <sstream> | ||
|
||
namespace dorado::poly_tail { | ||
|
||
PolyTailCalculatorSelector::PolyTailCalculatorSelector(const std::filesystem::path& config, | ||
bool is_rna, | ||
bool is_rna_adapter) { | ||
if (config.empty()) { | ||
std::stringstream buffer(""); | ||
init(buffer, is_rna, is_rna_adapter); | ||
return; | ||
} | ||
|
||
if (!std::filesystem::exists(config) || !std::filesystem::is_regular_file(config)) { | ||
throw std::runtime_error("PolyA config file doesn't exist at " + config.string()); | ||
} | ||
|
||
std::ifstream file(config); | ||
if (!file.is_open()) { | ||
throw std::runtime_error("Failed to open file " + config.string()); | ||
} | ||
|
||
std::stringstream buffer; | ||
buffer << file.rdbuf(); | ||
init(buffer, is_rna, is_rna_adapter); | ||
} | ||
|
||
PolyTailCalculatorSelector::PolyTailCalculatorSelector(std::istream& config_stream, | ||
bool is_rna, | ||
bool is_rna_adapter) { | ||
init(config_stream, is_rna, is_rna_adapter); | ||
} | ||
|
||
void PolyTailCalculatorSelector::init(std::istream& config_stream, | ||
bool is_rna, | ||
bool is_rna_adapter) { | ||
auto configs = prepare_configs(config_stream); | ||
m_default = PolyTailCalculatorFactory::create(configs.back(), is_rna, is_rna_adapter); | ||
configs.pop_back(); | ||
|
||
std::lock_guard<std::mutex> lock(m_lut_mutex); | ||
for (const auto& config : configs) { | ||
m_lut[config.barcode_id] = | ||
PolyTailCalculatorFactory::create(config, is_rna, is_rna_adapter); | ||
} | ||
} | ||
|
||
// Return the barcode-specific configuration if one has been provided, otherwise the default. | ||
// If any barcode-specific configurations are present, do not attempt to estimate | ||
// for unclassified reads - better to give no result than a wrong result in this case. | ||
std::shared_ptr<const PolyTailCalculator> PolyTailCalculatorSelector::get_calculator( | ||
const std::string& name) const { | ||
std::lock_guard<std::mutex> lock(m_lut_mutex); | ||
auto it = m_lut.find(name); | ||
return (it == std::end(m_lut)) | ||
? (name == "unclassified" && !m_lut.empty() ? nullptr : m_default) | ||
: it->second; | ||
} | ||
|
||
} // namespace dorado::poly_tail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <iosfwd> | ||
#include <memory> | ||
#include <mutex> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace dorado::poly_tail { | ||
|
||
class PolyTailCalculator; | ||
|
||
class PolyTailCalculatorSelector { | ||
public: | ||
PolyTailCalculatorSelector(const std::filesystem::path& config, | ||
bool is_rna, | ||
bool is_rna_adapter); | ||
PolyTailCalculatorSelector(std::istream& config_stream, bool is_rna, bool is_rna_adapter); | ||
|
||
std::shared_ptr<const PolyTailCalculator> get_calculator(const std::string& name) const; | ||
|
||
private: | ||
void init(std::istream& config_stream, bool is_rna, bool is_rna_adapter); | ||
|
||
mutable std::mutex m_lut_mutex; | ||
std::unordered_map<std::string, std::shared_ptr<const PolyTailCalculator>> m_lut; | ||
std::shared_ptr<const PolyTailCalculator> m_default; | ||
}; | ||
|
||
} // namespace dorado::poly_tail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.