@@ -15,53 +15,43 @@ import {
15
15
*/
16
16
export function getCoordinates ( input : string , assembly : string ) : Result [ ] {
17
17
const results : Result [ ] = [ ] ;
18
- input = input . replace ( / , / g, '' ) ;
18
+ input = input . replace ( / , / g, "" ) ;
19
19
20
- if ( input . startsWith ( "chr" ) && input . length <= 5 && input . length > 3 ) {
21
- results . push ( {
22
- title : input . split ( ":" ) [ 0 ] + `:1-100000` ,
23
- domain : {
24
- chromosome : input . split ( ":" ) [ 0 ] ,
25
- start : 1 ,
26
- end : 100000 ,
27
- } ,
28
- description : input . split ( ":" ) [ 0 ] + `:1-100000` ,
29
- type : "Coordinate" ,
30
- } ) ;
31
- }
32
20
if ( input . includes ( ":" ) && input . includes ( "-" ) ) {
33
21
const chromosome = input . split ( ":" ) [ 0 ] ;
34
22
const start = parseInt ( input . split ( ":" ) [ 1 ] . split ( "-" ) [ 0 ] ) || 0 ;
35
23
const end = parseInt ( input . split ( ":" ) [ 1 ] . split ( "-" ) [ 1 ] ) || start + 1000 ;
36
-
37
24
const chrLength = chromosomeLengths [ assembly ] [ chromosome ] ;
38
25
39
26
// Only set coordinates if end is greater than start and within chromosome length
40
27
if ( end > start && chrLength && end <= chrLength ) {
41
28
results . push ( {
42
- title : `${ chromosome } :${ start } -${ end } ` ,
29
+ title : `${ chromosome } :${ start . toLocaleString ( ) } -${ end . toLocaleString ( ) } ` ,
43
30
domain : {
44
31
chromosome : chromosome ,
45
32
start : start ,
46
33
end : end ,
47
34
} ,
48
- description : `${ chromosome } :${ start } -${ end } ` ,
35
+ description : `${ chromosome } :${ start . toLocaleString ( ) } -${ end . toLocaleString ( ) } ` ,
49
36
type : "Coordinate" ,
50
37
} ) ;
51
38
}
52
- }
53
- if ( input . includes ( "\t" ) ) {
39
+ } else if ( input . includes ( "\t" ) ) {
54
40
const [ chromosome , start , end ] = input . split ( "\t" ) ;
55
41
const chrLength = chromosomeLengths [ assembly ] [ chromosome ] ;
56
- if ( parseInt ( end ) > parseInt ( start ) && chrLength && parseInt ( end ) <= chrLength ) {
42
+ if (
43
+ parseInt ( end ) > parseInt ( start ) &&
44
+ chrLength &&
45
+ parseInt ( end ) <= chrLength
46
+ ) {
57
47
results . push ( {
58
- title : `${ chromosome } :${ start } -${ end } ` ,
48
+ title : `${ chromosome } :${ start . toLocaleString ( ) } -${ end . toLocaleString ( ) } ` ,
59
49
domain : {
60
50
chromosome : chromosome ,
61
51
start : parseInt ( start ) ,
62
52
end : parseInt ( end ) ,
63
53
} ,
64
- description : `${ chromosome } :${ start } -${ end } ` ,
54
+ description : `${ chromosome } :${ start . toLocaleString ( ) } -${ end . toLocaleString ( ) } ` ,
65
55
type : "Coordinate" ,
66
56
} ) ;
67
57
}
@@ -202,3 +192,16 @@ const chromosomeLengths: { [key: string]: { [key: string]: number } } = {
202
192
chry : 91744698 ,
203
193
} ,
204
194
} ;
195
+
196
+ export function isDomain ( input : string ) {
197
+ const hasTabs = input . includes ( "\t" ) ;
198
+ const hasHyphens = input . includes ( "-" ) ;
199
+ const hasChromosomeNumber = input . length >= 4 && / ^ \d $ / . test ( input [ 3 ] ) ;
200
+ console . log (
201
+ input ,
202
+ hasTabs || hasHyphens || ( input . startsWith ( "chr" ) && hasChromosomeNumber )
203
+ ) ;
204
+ return (
205
+ ( hasTabs || hasHyphens ) && input . startsWith ( "chr" ) && hasChromosomeNumber
206
+ ) ;
207
+ }
0 commit comments