tg-seq-gen 1.0.6 → 1.0.8
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/helperFns.js +65 -2
- package/index.js +6 -1
- package/package.json +3 -2
- package/shell-test.sh +96 -0
package/helperFns.js
CHANGED
@@ -4,6 +4,57 @@ const defaultCount = 10;
|
|
4
4
|
const defaultMaxLength = 10000;
|
5
5
|
const defaultMinLength = 1000;
|
6
6
|
|
7
|
+
// Feature types that can appear in GenBank files
|
8
|
+
const featureTypes = [
|
9
|
+
"CDS",
|
10
|
+
"gene",
|
11
|
+
"misc_feature",
|
12
|
+
"promoter",
|
13
|
+
"terminator",
|
14
|
+
"rep_origin",
|
15
|
+
"enhancer",
|
16
|
+
"attenuator",
|
17
|
+
"misc_binding",
|
18
|
+
"protein_bind",
|
19
|
+
"misc_signal",
|
20
|
+
"regulatory",
|
21
|
+
];
|
22
|
+
|
23
|
+
// Function to generate a random feature for GenBank format
|
24
|
+
function generateRandomFeature(seqLength) {
|
25
|
+
// Select a random feature type
|
26
|
+
const featureType =
|
27
|
+
featureTypes[Math.floor(Math.random() * featureTypes.length)];
|
28
|
+
|
29
|
+
// Generate a random start position (at least 10bp from the end)
|
30
|
+
const maxStart = Math.max(1, seqLength - 10);
|
31
|
+
const start = Math.floor(Math.random() * maxStart) + 1;
|
32
|
+
|
33
|
+
// Generate a random end position (between start and end of sequence)
|
34
|
+
const end = Math.floor(Math.random() * (seqLength - start)) + start;
|
35
|
+
|
36
|
+
// Generate a random name for the feature
|
37
|
+
const featureName = `feature_${Math.floor(Math.random() * 10000)}`;
|
38
|
+
|
39
|
+
// Format the feature in GenBank style
|
40
|
+
return ` ${featureType} ${start}..${end}
|
41
|
+
/label="${featureName}"
|
42
|
+
/note="randomly generated feature"
|
43
|
+
`;
|
44
|
+
}
|
45
|
+
|
46
|
+
// Function to generate multiple random features for a sequence
|
47
|
+
function generateFeatures(seqLength, numFeatures) {
|
48
|
+
let features = "";
|
49
|
+
if (numFeatures > 0) {
|
50
|
+
features = "FEATURES Location/Qualifiers\n";
|
51
|
+
for (let i = 0; i < numFeatures; i++) {
|
52
|
+
features += generateRandomFeature(seqLength);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
return features;
|
56
|
+
}
|
57
|
+
|
7
58
|
function genHelper(
|
8
59
|
{
|
9
60
|
count = defaultCount,
|
@@ -83,12 +134,24 @@ function getBps({ length, maxLength, minLength, isCDS }) {
|
|
83
134
|
function getSequenceFileForType(opts) {
|
84
135
|
if (opts.type === "gb") {
|
85
136
|
return genHelper(opts, ({ name, bps }) => {
|
137
|
+
// Get the current date in the format used in GenBank files
|
138
|
+
const today = new Date();
|
139
|
+
const dateString = today.toLocaleDateString('en-US', {
|
140
|
+
day: '2-digit',
|
141
|
+
month: 'short',
|
142
|
+
year: 'numeric'
|
143
|
+
}).replace(/(\w+)-(\d+)-(\d+)/, '$1-$3').toUpperCase();
|
144
|
+
|
145
|
+
// Generate features if numFeatures is specified
|
146
|
+
const features = opts.numFeatures ? generateFeatures(bps.length, opts.numFeatures) : '';
|
147
|
+
|
86
148
|
return (
|
87
149
|
"LOCUS " +
|
88
150
|
name +
|
89
151
|
" " +
|
90
152
|
bps.length +
|
91
|
-
" bp DNA linear
|
153
|
+
" bp DNA linear " + dateString + "\n" +
|
154
|
+
features +
|
92
155
|
"ORIGIN \n" +
|
93
156
|
" 1 " +
|
94
157
|
bps +
|
@@ -113,7 +176,7 @@ function getSequenceFileForType(opts) {
|
|
113
176
|
}
|
114
177
|
);
|
115
178
|
} else if (opts.type === "fasta") {
|
116
|
-
genHelper(opts, ({ name, bps }) => {
|
179
|
+
return genHelper(opts, ({ name, bps }) => {
|
117
180
|
return ">" + name + "||" + bps.length + "|linear\n" + bps;
|
118
181
|
});
|
119
182
|
}
|
package/index.js
CHANGED
@@ -13,7 +13,7 @@ const {
|
|
13
13
|
} = require("./helperFns");
|
14
14
|
|
15
15
|
program
|
16
|
-
.version("1.0.
|
16
|
+
.version("1.0.7")
|
17
17
|
.description(
|
18
18
|
"Generate sequences of varying formats (gb|csv|fasta). By default it will generate 100 sequences with random lengths between 1k and 10k bps"
|
19
19
|
)
|
@@ -37,6 +37,11 @@ program
|
|
37
37
|
defaultCount
|
38
38
|
)
|
39
39
|
.option("-t, --type [type]", "choose one of [gb|csv|fasta]", "gb")
|
40
|
+
.option(
|
41
|
+
"-f, --numFeatures [numFeatures]",
|
42
|
+
"number of random features to add to genbank files",
|
43
|
+
0
|
44
|
+
)
|
40
45
|
.parse(process.argv);
|
41
46
|
|
42
47
|
console.info("file type: ", program.type);
|
package/package.json
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "tg-seq-gen",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.8",
|
4
4
|
"description": "dna sequence generator",
|
5
5
|
"main": "index.js",
|
6
6
|
"repository": "https://github.com/TeselaGen/tg-seq-gen",
|
7
7
|
"scripts": {
|
8
|
-
"test": "node test.js"
|
8
|
+
"test": "node index.test.js",
|
9
|
+
"test:shell": "bash shell-test.sh"
|
9
10
|
},
|
10
11
|
"author": "Teselagen",
|
11
12
|
"license": "MIT",
|
package/shell-test.sh
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# Simple shell test script for tg-seq-gen
|
3
|
+
|
4
|
+
# Define test status
|
5
|
+
TEST_SUCCESS=0
|
6
|
+
TEST_FAILURE=0
|
7
|
+
|
8
|
+
# Helper function for checking test results
|
9
|
+
check_test() {
|
10
|
+
if [ $? -eq 0 ]; then
|
11
|
+
echo -e "\033[32m✓ $1\033[0m"
|
12
|
+
((TEST_SUCCESS++))
|
13
|
+
else
|
14
|
+
echo -e "\033[31m✗ $1\033[0m"
|
15
|
+
((TEST_FAILURE++))
|
16
|
+
fi
|
17
|
+
}
|
18
|
+
|
19
|
+
# Helper function to run a command with proper error handling
|
20
|
+
run_test() {
|
21
|
+
local cmd="$1"
|
22
|
+
local description="$2"
|
23
|
+
|
24
|
+
echo "Running: $cmd"
|
25
|
+
if eval "$cmd" > /dev/null 2>&1; then
|
26
|
+
check_test "$description"
|
27
|
+
return 0
|
28
|
+
else
|
29
|
+
check_test "$description"
|
30
|
+
return 1
|
31
|
+
fi
|
32
|
+
}
|
33
|
+
|
34
|
+
# Make sure we're in the correct directory
|
35
|
+
cd "$(dirname "$0")" || exit 1
|
36
|
+
|
37
|
+
# Define the command - use local index.js directly for testing
|
38
|
+
CMD="node ./index.js"
|
39
|
+
|
40
|
+
echo "Running shell tests for tg-seq-gen..."
|
41
|
+
echo "======================================"
|
42
|
+
|
43
|
+
# Test 1: Check if node is available
|
44
|
+
command -v node >/dev/null 2>&1
|
45
|
+
check_test "Node.js is available"
|
46
|
+
|
47
|
+
# Test 2: Check if the script exists
|
48
|
+
[ -f "./index.js" ]
|
49
|
+
check_test "index.js exists"
|
50
|
+
|
51
|
+
# Test 3: Generate default GenBank file
|
52
|
+
$CMD -t gb -c 1
|
53
|
+
check_test "Generate default GenBank file"
|
54
|
+
[ -f "pTG_001.gb" ] && rm "pTG_001.gb"
|
55
|
+
|
56
|
+
# Test 4: Generate default FASTA file
|
57
|
+
$CMD -t fasta -c 1
|
58
|
+
check_test "Generate default FASTA file"
|
59
|
+
[ -f "pTG_001.fasta" ] && rm "pTG_001.fasta"
|
60
|
+
|
61
|
+
# Test 5: Generate CSV file
|
62
|
+
$CMD -t csv -c 1
|
63
|
+
check_test "Generate default CSV file"
|
64
|
+
[ -f "pTG_001.csv" ] && rm "pTG_001.csv"
|
65
|
+
|
66
|
+
# Test 6: Generate with custom lengths
|
67
|
+
$CMD -t gb -c 1 -l 500,600
|
68
|
+
check_test "Generate GenBank with custom lengths"
|
69
|
+
[ -f "pTG_001.gb" ] && rm "pTG_001.gb"
|
70
|
+
|
71
|
+
# Test 7: Generate with min/max length parameters
|
72
|
+
$CMD -t fasta -c 1 -i 200 -m 500
|
73
|
+
check_test "Generate FASTA with min/max length"
|
74
|
+
[ -f "pTG_001.fasta" ] && rm "pTG_001.fasta"
|
75
|
+
|
76
|
+
# Test 8: Generate GenBank with features
|
77
|
+
$CMD -t gb -c 1 -f 5
|
78
|
+
check_test "Generate GenBank with features"
|
79
|
+
[ -f "pTG_001.gb" ] && rm "pTG_001.gb"
|
80
|
+
|
81
|
+
# Test 9: Check help output
|
82
|
+
$CMD --help | grep -q "Generate sequences"
|
83
|
+
check_test "Help command works properly"
|
84
|
+
|
85
|
+
# Test 10: Check version output
|
86
|
+
$CMD --version | grep -q "1.0.7"
|
87
|
+
check_test "Version command works properly"
|
88
|
+
|
89
|
+
# Print test summary
|
90
|
+
echo "======================================"
|
91
|
+
echo "Tests completed: $((TEST_SUCCESS + TEST_FAILURE))"
|
92
|
+
echo "Tests passed: $TEST_SUCCESS"
|
93
|
+
echo "Tests failed: $TEST_FAILURE"
|
94
|
+
|
95
|
+
# Return exit code based on test results
|
96
|
+
[ "$TEST_FAILURE" -eq 0 ] && exit 0 || exit 1
|