New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nucleotide

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nucleotide - npm Package Compare versions

Comparing version 0.5.11 to 0.6.2

40

package.json
{
"name": "nucleotide",
"version": "0.5.11",
"description": "Deal with nucleotides and molecular formula",
"module": "src/index.js",
"files": [
"src"
],
"repository": {
"type": "git",
"url": "git+https://github.com/cheminfo/molecular-formula.git"
},
"keywords": [],
"author": "Luc Patiny",
"license": "MIT",
"bugs": {
"url": "https://github.com/cheminfo/molecular-formula/issues"
},
"homepage": "https://github.com/cheminfo/molecular-formula/tree/master/packages/nucleotide#readme"
"author": {
"name": "Luc Patiny"
},
"bugs": {
"url": "https://github.com/cheminfo/molecular-formula/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Deal with nucleotides and molecular formula",
"main": "src/index.js",
"files": [
"src"
],
"homepage": "https://github.com/cheminfo/molecular-formula/tree/master/packages/nucleotide#readme",
"keywords": [],
"license": "MIT",
"name": "nucleotide",
"repository": {
"type": "git",
"url": "git+https://github.com/cheminfo/molecular-formula.git"
},
"version": "0.6.2"
}

@@ -6,5 +6,23 @@ 'use strict';

describe('test nucleotide', () => {
test('sequenceToMF of AAA return ', () => {
expect(Nucleotide.sequenceToMF('AAA')).toEqual('HODampDampDampH');
test('sequenceToMF of ATC ', () => {
expect(Nucleotide.sequenceToMF('ATC')).toEqual(
'HOAmpTmpCmpH.HOGmpAmpTmpH'
);
});
test('sequenceToMF of AAU ', () => {
expect(Nucleotide.sequenceToMF('AAU')).toEqual('HOAmpAmpUmpH');
});
test('sequenceToMF of circular AAA ', () => {
expect(Nucleotide.sequenceToMF('AAA', { circular: true })).toEqual(
'AmpAmpAmp.TmpTmpTmp'
);
});
test('sequenceToMF of DNA AAA ', () => {
expect(Nucleotide.sequenceToMF('AAA', { kind: 'DNA' })).toEqual(
'HODampDampDampH'
);
});
});
'use strict';
/**
* Convert a nucleic sequence to a MF
* @param {String} sequence
* @param {object} [options={}]
* @param {string} [options.kind] - rna, ds-dna or dna. Default if contains U: rna, otherwise ds-dna
* @param {string} [options.circular=false]
*/
function sequenceToMF(sequence, options = {}) {
let { dna, rna, circular } = options;
let { kind, circular } = options;
sequence = sequence.toUpperCase().replace(/[^ATCGU]/g, '');
if (!dna && !rna) {
if (!kind) {
if (sequence.includes('U')) {
rna = true;
kind = 'rna';
} else {
dna = true;
kind = 'ds-dna';
}
}
var nucleotides;
if (dna) {
nucleotides = desoxyNucleotides;
} else {
nucleotides = oxyNucleotides;
kind = kind.replace(/[^A-Za-z]/g, '').toLowerCase();
let results = [[]];
if (kind === 'dsdna') results.push([]);
switch (kind) {
case 'dna':
for (let nucleotide of sequence) {
results[0].push(desoxyNucleotides[nucleotide]);
}
break;
case 'rna':
for (let nucleotide of sequence) {
results[0].push(oxyNucleotides[nucleotide]);
}
break;
case 'dsdna':
for (let nucleotide of sequence) {
results[0].push(oxyNucleotides[nucleotide]);
results[1].unshift(oxyNucleotides[complementary[nucleotide]]);
}
break;
default:
throw new Error(`Nucleotide sequenceToMF: unknown kind: ${kind}`);
}
let result = [];
if (!circular) result.push('HO');
for (let nucleotide of sequence) {
result.push(nucleotides[nucleotide]);
if (!circular) {
results.forEach((result) => result.unshift('HO'));
results.forEach((result) => result.push('H'));
}
if (!circular) result.push('H');
return result.join('');
return results.map((result) => result.join('')).join('.');
}

@@ -33,2 +60,9 @@

const complementary = {
A: 'T',
T: 'A',
C: 'G',
G: 'C'
};
const desoxyNucleotides = {

@@ -35,0 +69,0 @@ A: 'Damp',

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc