Skip to content

Commit

Permalink
Adding ability to pick up sample to barcoding map from a csv file in …
Browse files Browse the repository at this point in the history
…the runtime directory
  • Loading branch information
rambaut committed Jan 12, 2020
1 parent ba8630b commit 738fab1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "artic-rampart",
"version": "1.0.2-0",
"version": "1.0.3-0",
"main": "src/electron.js",
"author": "James Hadfield, Ainé O'Toole, ARTIC network, Nick Loman, Andrew Rambaut",
"bin": {
Expand Down
6 changes: 3 additions & 3 deletions recipes/conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% set version = "1.0.1" %}
{% set version = "1.0.3" %}

package:
name: rampart
version: {{ version }}

source:
url: https://github.com/artic-network/rampart/archive/v1.0.1-1.tar.gz
url: https://github.com/artic-network/rampart/archive/v1.0.3.tar.gz
folder: rampart
sha256: 424a9e60cc663234fcabe49b24c8e44a6900e86aa64b9e5d031e95644f3ef4a7
sha256: 3235c4296320bbfc06a80142d30ae9f36848bee7f563bc1677270883a77a9155

requirements:
build:
Expand Down
29 changes: 28 additions & 1 deletion server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @type {module:fs}
*/
const fs = require('fs');
const dsv = require('d3-dsv');
// const path = require('path')
const { normalizePath, getAbsolutePath, verbose, log, warn, fatal } = require("./utils");
const { getNthReferenceColour } = require("./colours");
Expand All @@ -28,6 +29,7 @@ const GENOME_CONFIG_FILENAME= "genome.json";
const PRIMERS_CONFIG_FILENAME = "primers.json";
const PIPELINES_CONFIG_FILENAME = "pipelines.json";
const RUN_CONFIG_FILENAME = "run_configuration.json";
const BARCODES_TO_SAMPLE_FILENAME = "barcodes.csv";

const UNMAPPED_LABEL = "unmapped";
const UNASSIGNED_LABEL = "unassigned";
Expand Down Expand Up @@ -171,7 +173,7 @@ function checkPipeline(config, pipeline, index = 0, giveWarning = false) {

}

const getInitialConfig = (args) => {
function getInitialConfig(args) {
const serverDir = __dirname;
const rampartSourceDir = serverDir.substring(0, serverDir.length - 7); // no trailing slash

Expand Down Expand Up @@ -211,11 +213,35 @@ const getInitialConfig = (args) => {
config.run.title = args.title;
}

// attempt to open a csv file containing a mapping of barcodes to samples (this will override anything
// in the config files).
const barcodeFile = findConfigFile(pathCascade, BARCODES_TO_SAMPLE_FILENAME);
if (barcodeFile) {
try {
verbose("config", `Reading sample to barcode mapping from ${barcodeFile}`);
const samples = dsv.csvParse(fs.readFileSync(barcodeFile).toString());

const sampleMap = samples.reduce( (sampleMap, d) => {
sampleMap[d.sample] = (d.sample in sampleMap ? [...sampleMap[d.sample], d.barcode] : [d.barcode]);
return sampleMap;
}, {});
config.run.samples = Object.keys(sampleMap).map((d) => {
return {
'name': d,
'barcodes': sampleMap[d]
};
});
} catch (err) {
warn("Unable to read barcode to sample map file: " + barcodeFile)
}
}

config.run.barcodeNames = {};
if (config.run.samples) {

// if barcode names have been specified then limit demuxing to only those barcodes...
config.run.samples.forEach((sample, index) => {
verbose("config", `Sample: ${sample.name} -> ${sample.barcodes.join(",")}`);
sample.barcodes.forEach((barcode) => {
// // find an integer in the barcode name
// const matches = barcode.match(/(\d\d?)/);
Expand Down Expand Up @@ -334,6 +360,7 @@ const getInitialConfig = (args) => {
config.pipelines.annotation.configOptions = { ...config.pipelines.annotation.configOptions, ...config.run.annotationOptions };
}


if (Object.keys(config.run.barcodeNames).length > 0) {
config.pipelines.annotation.configOptions["limit_barcodes_to"] = Object.keys(config.run.barcodeNames).join(',');
}
Expand Down

0 comments on commit 738fab1

Please sign in to comment.