Skip to content

Commit

Permalink
Apply Prettier code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ariutta committed Jul 24, 2019
1 parent 6321eff commit 7b2d90e
Show file tree
Hide file tree
Showing 68 changed files with 863,850 additions and 4,959 deletions.
41 changes: 22 additions & 19 deletions bin/bridgedb
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ program

program
.command("datasource <input> [as]")
.description(
`If "as" not specified: identify the format used to specify a given xref data source.
.description(
`If "as" not specified: identify the format used to specify a given xref data source.
If "as" specified: format an xref data source as specified.
For example, Entrez Gene -> ncbigene
The data comes from BridgeDb.
`
)
)
.action(function(input, as, options) {
var serialize = ndjson.serialize();
if (process.env.NODE_ENV === "development") {
if (!process.env.MOCK_SERVER_WARNING_GIVEN) {
console.warn("Using development mock server.");
process.env.MOCK_SERVER_WARNING_GIVEN = 'yes';
process.env.MOCK_SERVER_WARNING_GIVEN = "yes";
}
//*TODO: use this instance for testing:
var bridgeDb = new BridgeDb({
Expand All @@ -58,25 +58,28 @@ program
}
})
.on("--help", function() {
console.log(fs
.readFileSync(path.join(__dirname, "datasource.help.sh"), "utf8")
// We drop the shebang when displaying here as help
.replace(/^.*\n/, "")
// We also drop bash comment characters
.replace(/^#(\ )?/gm, "")
// and replace path to bridgedb with just bridgedb
.replace(/(\.\/)?bin\/(bridgedb)/gm, "\$2"));
console.log(
fs
.readFileSync(path.join(__dirname, "datasource.help.sh"), "utf8")
// We drop the shebang when displaying here as help
.replace(/^.*\n/, "")
// We also drop bash comment characters
.replace(/^#(\ )?/gm, "")
// and replace path to bridgedb with just bridgedb
.replace(/(\.\/)?bin\/(bridgedb)/gm, "$2")
);
});

createXrefsCLI(program);

program
.command('*')
.action(function(cmd){
console.error("");
console.error('\ \ Unrecognized command "%s". Valid commands shown below:', cmd);
program.outputHelp();
});
program.command("*").action(function(cmd) {
console.error("");
console.error(
' Unrecognized command "%s". Valid commands shown below:',
cmd
);
program.outputHelp();
});

program.parse(process.argv);

Expand Down
52 changes: 30 additions & 22 deletions bin/dsvXrefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ module.exports = function(
var headersOption = options.hasOwnProperty("headers")
? Boolean(options.headers)
: false;
var delimiterOption = options.format in delimiterFor
? delimiterFor[options.format]
: "\t";
var delimiterOption =
options.format in delimiterFor ? delimiterFor[options.format] : "\t";
var newlineOption = options.newline || "\n";
var quoteOption = options.quote || '"';
var commentOption = options.comment || "#";
Expand All @@ -54,19 +53,28 @@ module.exports = function(
const xrefDataSourceArgType = argType(xrefDataSourceArg);
const xrefIdentifierArgType = argType(xrefIdentifierArg);

var organismColumn = organismArgType === "auto"
? 0
: organismArgType === "columnIndex" ? parseInt(organismArg) : organismArg;
var organismColumn =
organismArgType === "auto"
? 0
: organismArgType === "columnIndex"
? parseInt(organismArg)
: organismArg;

var xrefDataSourceColumn = xrefDataSourceArgType === "auto"
? _.isFinite(parseInt(organismColumn)) ? organismColumn + 1 : 0
: xrefDataSourceArgType === "columnIndex"
var xrefDataSourceColumn =
xrefDataSourceArgType === "auto"
? _.isFinite(parseInt(organismColumn))
? organismColumn + 1
: 0
: xrefDataSourceArgType === "columnIndex"
? parseInt(xrefDataSourceArg)
: xrefDataSourceArg;

var xrefIdentifierColumn = xrefIdentifierArgType === "auto"
? _.isFinite(parseInt(xrefDataSourceColumn)) ? xrefDataSourceColumn + 1 : 0
: xrefIdentifierArgType === "columnIndex"
var xrefIdentifierColumn =
xrefIdentifierArgType === "auto"
? _.isFinite(parseInt(xrefDataSourceColumn))
? xrefDataSourceColumn + 1
: 0
: xrefIdentifierArgType === "columnIndex"
? parseInt(xrefIdentifierArg)
: xrefIdentifierArg;

Expand All @@ -93,13 +101,12 @@ module.exports = function(
`^${commentOption}.*$[${newlineOption}]?`,
"gm"
);
Rx.Observable
.fromNodeReadableStream(
hl(process.stdin)
// Ignore comments
.through(replaceStream(commentLineRe, ""))
.through(parser)
)
Rx.Observable.fromNodeReadableStream(
hl(process.stdin)
// Ignore comments
.through(replaceStream(commentLineRe, ""))
.through(parser)
)
.mergeMap(function(row) {
const organism = organismField(row);
const xrefDataSource = xrefDataSourceField(row);
Expand Down Expand Up @@ -149,9 +156,10 @@ module.exports = function(
} else {
// long format
return mappedXrefs$.mergeMap(function(xrefs) {
const firstColumn = typeof xrefDataSourceOption !== "undefined"
? xrefIdentifier
: [xrefDataSource, xrefIdentifier].join(delimiterOption);
const firstColumn =
typeof xrefDataSourceOption !== "undefined"
? xrefIdentifier
: [xrefDataSource, xrefIdentifier].join(delimiterOption);

return Rx.Observable.from(xrefs).map(xref => {
return [
Expand Down
53 changes: 29 additions & 24 deletions bin/jsonXrefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ ensembl ncbigene uniprot wikidata
// ...

function parseJQPath(path) {
return path.replace(/^\./, "")
return path
.replace(/^\./, "")
.split(".")
.reduce((acc, s) => {
(s.match(/(\w+)?(\[\w*\])?/) || [])
.slice(1)
.filter(_.negate(_.isUndefined))
.map(s => s === "[]" ? true : s.replace(/\[(\w+)\]/, "\1"))
.map(s => (s === "[]" ? true : s.replace(/\[(\w+)\]/, "\1")))
//.map(s => s.replace(/\[(\w+)\]/, "\1").replace(/\[\]/, true))
.forEach(function(s) {
acc.push(s);
Expand All @@ -59,20 +60,20 @@ function resolveJQPath(base, relativePath) {
*/
function getByParsedPath(value, path) {
if (path.length > 0) {
return _.get(
value,
path
);
return _.get(value, path);
} else {
return value;
}
}

module.exports = function(
bridgeDb, organism,
pathToXrefDataSource, pathToXrefIdentifier,
desiredXrefDataSources,
{ base, format, insertionPoint }) {
bridgeDb,
organism,
pathToXrefDataSource,
pathToXrefIdentifier,
desiredXrefDataSources,
{ base, format, insertionPoint }
) {
var pathToInsertionPoint = insertionPoint;

var { common, relPaths } = _.zip
Expand Down Expand Up @@ -210,9 +211,8 @@ module.exports = function(
}
var valuesByKey = acc.valuesByKey;

var entityKey = lastCommonKey !== true
? lastCommonKey
: path.slice(-1)[0];
var entityKey =
lastCommonKey !== true ? lastCommonKey : path.slice(-1)[0];

var entityPathRelToValue = common
.slice(JSONStreamPath.length)
Expand Down Expand Up @@ -428,9 +428,10 @@ it's not a string or array. Skipping addition of ${xrefIdentifier}.`);
return {
event: "data",
path: JSONStreamParentPath,
value: NEST0_OBJECT_KEY in valuesByKey
? valuesByKey[NEST0_OBJECT_KEY]
: valuesByKey
value:
NEST0_OBJECT_KEY in valuesByKey
? valuesByKey[NEST0_OBJECT_KEY]
: valuesByKey
};
});
});
Expand All @@ -453,11 +454,13 @@ it's not a string or array. Skipping addition of ${xrefIdentifier}.`);
var i = 0;

if (pathToInsertionPoint === "none") {
return parsedDataStream
.flatMap(x => hl(x[0].xrefs))
//.through(JSONStream.stringify(false))
.through(ndjson.serialize())
.pipe(process.stdout);
return (
parsedDataStream
.flatMap(x => hl(x[0].xrefs))
//.through(JSONStream.stringify(false))
.through(ndjson.serialize())
.pipe(process.stdout)
);
}

return hl([headerStream, parsedDataStream, footerStream])
Expand All @@ -483,8 +486,8 @@ it's not a string or array. Skipping addition of ${xrefIdentifier}.`);
typeof nsValue === "undefined"
? value
: _.isArray(nsValue)
? nsValue.concat(value)
: _.assign(nsValue, value),
? nsValue.concat(value)
: _.assign(nsValue, value),
(nsValue, key, nsObject) =>
nsValue || _.isFinite(parseInt(key)) ? Array : Object
);
Expand Down Expand Up @@ -512,7 +515,9 @@ it's not a string or array. Skipping addition of ${xrefIdentifier}.`);
return acc;
})
.flatMap(function(s) {
return hl(_.isArray(s) ? s : [s]).through(stringifier).concat(hl(["\n"]));
return hl(_.isArray(s) ? s : [s])
.through(stringifier)
.concat(hl(["\n"]));
})
.pipe(process.stdout);
};
7 changes: 3 additions & 4 deletions bin/noneXrefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ module.exports = function(
.xrefs(organism, xrefDataSource, xrefIdentifier, desiredXrefDataSources)
//.throughNodeStream(serialize)
.mergeMap(function(xrefs) {
return Rx.Observable
.from(xrefs)
.map(({ xrefDataSource, xrefIdentifier }) =>
return Rx.Observable.from(xrefs).map(
({ xrefDataSource, xrefIdentifier }) =>
[xrefDataSource, xrefIdentifier].join("\t")
);
);
})
.map(line => line + "\n")
.pipeToStdout();
Expand Down
35 changes: 15 additions & 20 deletions karma-ui-combo.conf.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
var bridgeDbDefaultConfig = require('./lib/config.js');
var bridgeDbDefaultConfig = require("./lib/config.js");
//require('./test/mockserver.js');

module.exports = function(config) {
var options = {
basePath: '',
frameworks: ['mocha', 'chai', 'browserify'],
browsers: [
'Chrome',
'Firefox'
],
files: ['test/unit/ui-components/ui-combo.test.js'],
basePath: "",
frameworks: ["mocha", "chai", "browserify"],
browsers: ["Chrome", "Firefox"],
files: ["test/unit/ui-components/ui-combo.test.js"],
preprocessors: {
'test/unit/ui-components/ui-combo.test.js': 'browserify'
"test/unit/ui-components/ui-combo.test.js": "browserify"
},
browserify: {
debug: true,
transform: ['brfs']
transform: ["brfs"]
},
colors: true,
reporters: [
'coverage',
'mocha',
],
reporters: ["coverage", "mocha"],
browserDisconnectTimeout: 60000,
browserNoActivityTimeout: 60000,
client: {
mocha: {
timeout: 59000,
},
},
timeout: 59000
}
}
};

process.env.MOCKSERVER_PORT = 4522;
var proxies = {};
proxies[bridgeDbDefaultConfig.baseIri] = {
target: 'http://localhost:' + process.env.MOCKSERVER_PORT + '/',
target: "http://localhost:" + process.env.MOCKSERVER_PORT + "/",
changeOrigin: true
};
proxies[bridgeDbDefaultConfig.datasetsMetadataIri] = {
target: 'http://localhost:' + process.env.MOCKSERVER_PORT + '/datasources.txt',
target:
"http://localhost:" + process.env.MOCKSERVER_PORT + "/datasources.txt",
changeOrigin: true
};
options.proxies = proxies;
Expand All @@ -48,7 +43,7 @@ module.exports = function(config) {
}

if (process.env.GROWL) {
options.reporters.push('growl');
options.reporters.push("growl");
}

config.set(options);
Expand Down
Loading

0 comments on commit 7b2d90e

Please sign in to comment.