-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
const extractor = require("./src/extractor"); | ||
|
||
// The source extractor | ||
const options = { | ||
// *** The source extractor | ||
const sourceOptions = { | ||
ENAChecklist: "./input/Source/ENA.xml", | ||
ISAConfiguration: "./input/Source/ISA.xml", | ||
outputPath: "./output/result.txt", | ||
outputPath: "./output/sourceMerged.txt", | ||
}; | ||
extractor.sourceExtractor.getData(options); | ||
extractor.sourceExtractor.getData(sourceOptions); | ||
|
||
// // The assay extractor | ||
// extractor.assayExtractor.getData(); | ||
// *** The assay extractor | ||
const assayOptions = { | ||
ISAConfiguration: "./input/Assay/genome_seq.xml", | ||
outputPath: "./output/assayMerged.txt", | ||
}; | ||
extractor.assayExtractor.getData(assayOptions); |
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,58 @@ | ||
const xml2js = require("xml2js"); //.parseString; | ||
const parser = new xml2js.Parser({ explicitChildren: true, preserveChildrenOrder: true }).parseString; | ||
const fs = require("fs"); | ||
const fsPromises = fs.promises; | ||
|
||
const getData = async (options) => { | ||
const { ISAConfiguration, outputPath } = options; | ||
const ISA_XML = await fsPromises.readFile(ISAConfiguration); | ||
const ISAParsed = await dataParse(ISA_XML); | ||
const ISAData = ISAExtract(ISAParsed); | ||
writeOutput(ISAData, outputPath); | ||
}; | ||
|
||
const dataParse = async (data) => { | ||
return new Promise((r) => { | ||
parser(data, (e, result) => { | ||
r(result); | ||
}); | ||
}); | ||
}; | ||
|
||
const ISAExtract = (data) => { | ||
const temp = data["isatab-config-file"]["isatab-configuration"][0]["$$"]; | ||
let result = { meta: {}, data: {} }; | ||
let lastProtocol = ""; | ||
temp.forEach((x) => { | ||
if (x["#name"] == "protocol-field") { | ||
result.data[x["$"]["protocol-type"]] = []; | ||
lastProtocol = x["$"]["protocol-type"]; | ||
} else if (x["#name"] == "field") { | ||
if (lastProtocol != "") { | ||
result.data[lastProtocol].push({ | ||
name: x["$"]["header"], | ||
description: x["description"][0].trim(), | ||
dataType: x["$"]["data-type"], | ||
required: x["$"]["is-required"], | ||
}); | ||
} | ||
} else if (x["#name"] == "measurement") { | ||
result.meta["measurement"] = x["$"]["term-label"]; | ||
} else if (x["#name"] == "technology") { | ||
result.meta["technology"] = x["$"]["term-label"]; | ||
} | ||
}); | ||
// console.log(result); | ||
return result; | ||
}; | ||
|
||
const writeOutput = async (data, outputPath) => { | ||
try { | ||
await fsPromises.writeFile(outputPath, JSON.stringify(data)); | ||
console.log("Data was extracted successfully!"); | ||
} catch (e) { | ||
console.log(`Error writing to file: ${e}`); | ||
} | ||
}; | ||
|
||
module.exports = { getData }; |