Skip to content

Commit

Permalink
feat: creates new element from a JCAMP
Browse files Browse the repository at this point in the history
  • Loading branch information
maasencioh committed Nov 4, 2016
1 parent 2b691e7 commit 1c6089a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
"eslint": "^3.4.0",
"eslint-config-cheminfo": "^1.2.0",
"eslint-plugin-no-only-tests": "^1.1.0",
"jcampconverter": "^2.3.0",
"nyc": "^8.3.0"
},
"dependencies": {
"binary-search": "^1.3.2",
"jcampconverter": "^2.3.0",
"ml-gsd": "mljs/global-spectral-deconvolution#peak-high",
"ml-regression": "^4.1.1"
}
Expand Down
16 changes: 16 additions & 0 deletions src/fromJcamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const Chromatogram = require('./Chromatogram');
const converter = require('jcampconverter').convert;

/**
* Creates a new Chromatogram element based in a JCAMP string
* @param {string} jcamp - String containing the JCAMP data
* @return {Chromatogram} - New class element with the given data
*/
function fromJcamp(jcamp) {
const data = converter(jcamp, {newGCMS: true}).gcms;
return new Chromatogram(data);
}

module.exports = fromJcamp;
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ exports.kovats = require('./kovats');
exports.getKovatsTable = require('./getKovatsTable');
exports.kovatsConversionFunction = require('./kovatsConversionFunction');
exports.rescaleTime = require('./rescaleTime');
exports.fromJcamp = require('./fromJcamp');
5 changes: 2 additions & 3 deletions test/loadJcamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import {convert} from 'jcampconverter';
import fs from 'fs';
import Promise from 'bluebird';
import {join} from 'path';
import {Chromatogram} from '..';
import {Chromatogram, fromJcamp} from '..';

const readFileAsync = Promise.promisify(fs.readFile);

test('load JCAMP', async t => {
const path = join(__dirname, 'data/jcamp/MixC8-C40_140630.JDX');
const jcamp = await readFileAsync(path, 'utf8');
const data = convert(jcamp, {newGCMS: true}).gcms;
const chrom = new Chromatogram(data);
const chrom = fromJcamp(jcamp);
t.is(chrom.length, 6993);
});
72 changes: 35 additions & 37 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ align-text@^0.1.1, align-text@^0.1.3:
repeat-string "^1.5.2"

amdefine@>=0.0.4:
version "1.0.0"
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.0.tgz#fd17474700cb5cc9c2b709f0be9d23ce3c198c33"
version "1.0.1"
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"

ansi-align@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -332,8 +332,8 @@ babel-code-frame@^6.16.0, babel-code-frame@^6.7.5:
js-tokens "^2.0.0"

babel-core@^6.0.14, babel-core@^6.13.0, babel-core@^6.14.0, babel-core@^6.18.0, babel-core@^6.3.21, babel-core@^6.8.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.18.0.tgz#bb5ce9bc0a956e6e94e2f12d597abb3b0b330deb"
version "6.18.2"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.18.2.tgz#d8bb14dd6986fa4f3566a26ceda3964fa0e04e5b"
dependencies:
babel-code-frame "^6.16.0"
babel-generator "^6.18.0"
Expand Down Expand Up @@ -1212,7 +1212,7 @@ binary-extensions@^1.0.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.7.0.tgz#6c1610db163abfb34edfe42fa423343a1e01185d"

binary-search:
binary-search@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/binary-search/-/binary-search-1.3.2.tgz#88c9b7bd2b7221d352da78ec887f5af2549e4de2"

Expand Down Expand Up @@ -1634,10 +1634,8 @@ co@3.1.0:
resolved "https://registry.yarnpkg.com/co/-/co-3.1.0.tgz#4ea54ea5a08938153185e15210c68d9092bc1b78"

code-point-at@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.0.1.tgz#1104cd34f9b5b45d3eba88f1babc1924e1ce35fb"
dependencies:
number-is-nan "^1.0.0"
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"

collapse-white-space@^1.0.0:
version "1.0.2"
Expand Down Expand Up @@ -2305,8 +2303,8 @@ ecc-jsbn@~0.1.1:
jsbn "~0.1.0"

editions@^1.1.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/editions/-/editions-1.3.1.tgz#008425f64dc1401db45ec110e06aa602562419c0"
version "1.3.3"
resolved "https://registry.yarnpkg.com/editions/-/editions-1.3.3.tgz#0907101bdda20fac3cbe334c27cbd0688dc99a5b"

ee-first@1.1.1:
version "1.1.1"
Expand Down Expand Up @@ -2758,8 +2756,8 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"

fsevents@^1.0.0:
version "1.0.14"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.0.14.tgz#558e8cc38643d8ef40fe45158486d0d25758eee4"
version "1.0.15"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.0.15.tgz#fa63f590f3c2ad91275e4972a6cea545fb0aae44"
dependencies:
nan "^2.3.0"
node-pre-gyp "^0.6.29"
Expand Down Expand Up @@ -2861,8 +2859,8 @@ getpass@^0.1.1:
assert-plus "^1.0.0"

ggit@^1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/ggit/-/ggit-1.11.0.tgz#2a6e32608270f31f9f1fcb57f0c3b1221ed2943c"
version "1.11.1"
resolved "https://registry.yarnpkg.com/ggit/-/ggit-1.11.1.tgz#97c0c97945a7733131093ab887f94eff870e0e96"
dependencies:
bluebird "3.4.1"
chdir-promise "0.2.1"
Expand All @@ -2875,7 +2873,7 @@ ggit@^1.11.0:
glob "6.0.1"
lazy-ass "1.1.0"
lodash "3.10.1"
moment "2.12.0"
moment "2.15.2"
optimist "0.6.1"
q "2.0.3"
quote "0.4.0"
Expand Down Expand Up @@ -2928,8 +2926,8 @@ git-up@^2.0.0:
parse-url "^1.3.0"

git-url-parse@^6.0.1:
version "6.0.7"
resolved "https://registry.yarnpkg.com/git-url-parse/-/git-url-parse-6.0.7.tgz#e61dbb05ccd78921494814f5e5f0cea17275d3de"
version "6.1.0"
resolved "https://registry.yarnpkg.com/git-url-parse/-/git-url-parse-6.1.0.tgz#01a99f11ca4def4d88d9886da7f84d75d114495b"
dependencies:
git-up "^2.0.0"

Expand Down Expand Up @@ -3067,8 +3065,8 @@ glogg@^1.0.0:
sparkles "^1.0.0"

got@^5.0.0, got@^5.2.0:
version "5.7.0"
resolved "https://registry.yarnpkg.com/got/-/got-5.7.0.tgz#718879e60f824cc0f69721127b835379b056a3af"
version "5.7.1"
resolved "https://registry.yarnpkg.com/got/-/got-5.7.1.tgz#5f81635a61e4a6589f180569ea4e381680a51f35"
dependencies:
create-error-class "^3.0.1"
duplexer2 "^0.1.4"
Expand All @@ -3087,8 +3085,8 @@ got@^5.0.0, got@^5.2.0:
url-parse-lax "^1.0.0"

graceful-fs@^4.0.0, graceful-fs@^4.1.2:
version "4.1.9"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.9.tgz#baacba37d19d11f9d146d3578bc99958c3787e29"
version "4.1.10"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.10.tgz#f2d720c22092f743228775c75e3612632501f131"

"graceful-readlink@>= 1.0.0":
version "1.0.1"
Expand Down Expand Up @@ -3222,8 +3220,8 @@ hawk@~3.1.3:
sntp "1.x.x"

highlight.js@^9.1.0:
version "9.7.0"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.7.0.tgz#e7a926bf3079c65b2ae50314878e456a009b4aac"
version "9.8.0"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.8.0.tgz#38eeef40cd45eaddbec8c9e5238fb7a783a3b685"

hoek@2.x.x:
version "2.16.3"
Expand Down Expand Up @@ -3700,7 +3698,7 @@ istanbul-lib-hook@^1.0.0-alpha.4:
dependencies:
append-transform "^0.3.0"

istanbul-lib-instrument@^1.1.3:
istanbul-lib-instrument@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.2.0.tgz#73d5d108ab7568c373fdcb7d01c1d42d565bc8c4"
dependencies:
Expand Down Expand Up @@ -3732,7 +3730,7 @@ istanbul-lib-source-maps@^1.0.2:
rimraf "^2.4.4"
source-map "^0.5.3"

istanbul-reports@^1.0.0-alpha.8:
istanbul-reports@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.0.0.tgz#24b4eb2b1d29d50f103b369bd422f6e640aa0777"
dependencies:
Expand Down Expand Up @@ -4358,9 +4356,9 @@ module-deps-sortable@4.0.6:
through2 "^2.0.0"
xtend "^4.0.0"

moment@2.12.0:
version "2.12.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.12.0.tgz#dc2560d19838d6c0731b1a6afa04675264d360d6"
moment@2.15.2:
version "2.15.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.15.2.tgz#1bfdedf6a6e345f322fe956d5df5bd08a8ce84dc"

ms@^0.7.1:
version "0.7.2"
Expand Down Expand Up @@ -4516,8 +4514,8 @@ number-is-nan@^1.0.0:
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"

nyc@^8.3.0:
version "8.3.2"
resolved "https://registry.yarnpkg.com/nyc/-/nyc-8.3.2.tgz#a3b7a590fe1c6c4b2d0e3f24afe28b62bfafd745"
version "8.4.0"
resolved "https://registry.yarnpkg.com/nyc/-/nyc-8.4.0.tgz#660371c807caef0427fb9b0948f74180624ea6e4"
dependencies:
archy "^1.0.0"
arrify "^1.0.1"
Expand All @@ -4530,10 +4528,10 @@ nyc@^8.3.0:
glob "^7.0.6"
istanbul-lib-coverage "^1.0.0"
istanbul-lib-hook "^1.0.0-alpha.4"
istanbul-lib-instrument "^1.1.3"
istanbul-lib-instrument "^1.2.0"
istanbul-lib-report "^1.0.0-alpha.3"
istanbul-lib-source-maps "^1.0.2"
istanbul-reports "^1.0.0-alpha.8"
istanbul-reports "^1.0.0"
md5-hex "^1.2.0"
micromatch "^2.3.11"
mkdirp "^0.5.0"
Expand Down Expand Up @@ -5289,8 +5287,8 @@ request-promise@^4.0.1:
stealthy-require "^1.0.0"

request@^2.74.0, request@^2.75.0:
version "2.76.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.76.0.tgz#be44505afef70360a0436955106be3945d95560e"
version "2.78.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.78.0.tgz#e1c8dec346e1c81923b24acdb337f11decabe9cc"
dependencies:
aws-sign2 "~0.6.0"
aws4 "^1.2.1"
Expand Down Expand Up @@ -5326,8 +5324,8 @@ require-precompiled@^0.1.0:
resolved "https://registry.yarnpkg.com/require-precompiled/-/require-precompiled-0.1.0.tgz#5a1b52eb70ebed43eb982e974c85ab59571e56fa"

require-uncached@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.2.tgz#67dad3b733089e77030124678a459589faf6a7ec"
version "1.0.3"
resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3"
dependencies:
caller-path "^0.1.0"
resolve-from "^1.0.0"
Expand Down

0 comments on commit 1c6089a

Please sign in to comment.