@rnacanvas/search 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -0
- package/dist/SequenceCharacter.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
With `npm`:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @rnacanvas/search
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
# Usage
|
|
10
|
+
|
|
11
|
+
All exports of this package can be accessed as named imports.
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
// an example import
|
|
15
|
+
import { SequenceCharacter } from '@rnacanvas/search';
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## `class SequenceCharacter`
|
|
19
|
+
|
|
20
|
+
Represents a character in a sequence.
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
var A = new SequenceCharacter('A');
|
|
24
|
+
|
|
25
|
+
A.toString(); // "A"
|
|
26
|
+
|
|
27
|
+
A.matches('A'); // true
|
|
28
|
+
A.matches('G'); // false
|
|
29
|
+
|
|
30
|
+
A.complements('U'); // true
|
|
31
|
+
A.complements('T'); // true
|
|
32
|
+
A.complements('G'); // false
|
|
33
|
+
|
|
34
|
+
// case doesn't matter
|
|
35
|
+
A.matches('a'); // true
|
|
36
|
+
A.complements('u'); // true
|
|
37
|
+
|
|
38
|
+
// IUPAC codes are recognized
|
|
39
|
+
A.matches('R'); // true
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This constructor will throw for strings that are not composed of a single character.
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
// empty string
|
|
46
|
+
new SequenceCharacter(''); // throws
|
|
47
|
+
|
|
48
|
+
// more than one character
|
|
49
|
+
new SequenceCharacter('AG'); // throws
|
|
50
|
+
new SequenceCharacter('asdf'); // throws
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Any character may be input to the constructor, though.
|
|
54
|
+
|
|
55
|
+
### `toString()`
|
|
56
|
+
|
|
57
|
+
Simply returns the character as a string.
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
var A = new SequenceCharacter('A');
|
|
61
|
+
A.toString(); // "A"
|
|
62
|
+
|
|
63
|
+
var R = new SequenceCharacter('R');
|
|
64
|
+
R.toString(); // "R"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### `matches()`
|
|
68
|
+
|
|
69
|
+
Returns `true` if the character matches the input character.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
var A = new SequenceCharacter('A');
|
|
73
|
+
|
|
74
|
+
A.matches('A'); // true
|
|
75
|
+
A.matches('C'); // false
|
|
76
|
+
|
|
77
|
+
// case doesn't matter
|
|
78
|
+
A.matches('a'); // true
|
|
79
|
+
|
|
80
|
+
// works for sequence character instances too
|
|
81
|
+
A.matches(new SequenceCharacter('A')); // true
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
[IUPAC nucleic acid codes](https://www.bioinformatics.org/sms/iupac.html) are recognized.
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
var A = new SequenceCharacter('A');
|
|
88
|
+
|
|
89
|
+
A.matches('R'); // true
|
|
90
|
+
A.matches('Y'); // false
|
|
91
|
+
|
|
92
|
+
var N = new SequenceCharacter('N');
|
|
93
|
+
|
|
94
|
+
// the any character matches any non-gap character
|
|
95
|
+
N.matches('A'); // true
|
|
96
|
+
N.matches('p'); // true
|
|
97
|
+
|
|
98
|
+
var period = new SequenceCharacter('.');
|
|
99
|
+
var dash = new SequenceCharacter('-');
|
|
100
|
+
|
|
101
|
+
// gap characters only match other gap characters
|
|
102
|
+
period.matches('.'); // true
|
|
103
|
+
dash.matches('-'); // true
|
|
104
|
+
period.matches('N'); // false
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Will throw for empty strings and strings containing more than one character.
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
var A = new SequenceCharacter('A');
|
|
111
|
+
|
|
112
|
+
// empty string
|
|
113
|
+
A.matches(''); // throws
|
|
114
|
+
|
|
115
|
+
// strings containing more than one character
|
|
116
|
+
A.matches('AG'); // throws
|
|
117
|
+
A.matches('asdf'); // throws
|
|
118
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SequenceCharacter.d.ts","sourceRoot":"","sources":["../src/SequenceCharacter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,iBAAiB;;gBAGhB,SAAS,EAAE,MAAM;IAU7B,QAAQ,IAAI,MAAM;IAIlB,OAAO,CAAC,cAAc,EAAE,iBAAiB,GAAG,MAAM,GAAG,OAAO;
|
|
1
|
+
{"version":3,"file":"SequenceCharacter.d.ts","sourceRoot":"","sources":["../src/SequenceCharacter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,iBAAiB;;gBAGhB,SAAS,EAAE,MAAM;IAU7B,QAAQ,IAAI,MAAM;IAIlB,OAAO,CAAC,cAAc,EAAE,iBAAiB,GAAG,MAAM,GAAG,OAAO;IAkC5D,WAAW,CAAC,cAAc,EAAE,iBAAiB,GAAG,MAAM,GAAG,OAAO;CAiCjE"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.search=t():e.search=t()}(this,()=>(()=>{"use strict";var e={d:(t,r)=>{for(var
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.search=t():e.search=t()}(this,()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{SequenceCharacter:()=>o});var r,n=function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};class o{constructor(e){if(r.set(this,void 0),0==e.length)throw new Error("Character cannot be an empty string.");if(e.length>1)throw new Error("Character must be a single character.");!function(e,t,r,n,o){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?o.call(e,r):o?o.value=r:t.set(e,r)}(this,r,e,"f")}toString(){return n(this,r,"f")}matches(e){var t,o;if("string"!=typeof e&&(e=e.toString()),0==e.length)throw new Error("Other character cannot be an empty string.");if(e.length>1)throw new Error("Other character cannot be multiple characters.");let c=n(this,r,"f").toUpperCase();return e=e.toUpperCase(),!(!i.includes(c)||!i.includes(e))||!i.includes(c)&&!i.includes(e)&&("N"===c&&!i.includes(e)||"N"===e&&!i.includes(c)||(c in a?null!==(o=null===(t=a[c])||void 0===t?void 0:t.includes(e))&&void 0!==o&&o:c===e))}complements(e){var t,o;if("string"!=typeof e&&(e=e.toString()),0==e.length)throw new Error("Other character cannot be an empty string.");if(e.length>1)throw new Error("Other character cannot be multiple characters.");let a=n(this,r,"f").toUpperCase();return e=e.toUpperCase(),!(!i.includes(a)||!i.includes(e))||!i.includes(a)&&!i.includes(e)&&("N"===a&&!i.includes(e)||"N"===e&&!i.includes(a)||a in c&&null!==(o=null===(t=c[a])||void 0===t?void 0:t.includes(e))&&void 0!==o&&o)}}r=new WeakMap;const i=[...".-"],a={A:[..."A"],C:[..."C"],G:[..."G"],U:[..."UT"],T:[..."TU"],R:[..."AG"],Y:[..."CUT"],S:[..."GC"],W:[..."AUT"],K:[..."GUT"],M:[..."AC"],B:[..."CGUTYSK"],D:[..."AGUTRWK"],H:[..."ACUTYWM"],V:[..."ACGRSM"]},c={A:[..."UT"],C:[..."G"],G:[..."CUT"],U:[..."AG"],T:[..."AG"]};return t})());
|