You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shell state does not persist between calls, but within a single call you can chain commands with `&&` and pipes. Here we count lines in the BED files and peek at the first few records.
Shell state does not persist between `bash()` calls (cwd, variables, etc.), so multi-step work must be done in a single call using `&&` or pipes. Here we compute the fragment-length distribution from the BED file entirely in shell.
71
72
72
73
```bash
73
-
cat > /tmp/bash_pipeline.py << 'EOF'
74
+
cat > /tmp/bash-demo/bash_pipeline.py << 'EOF'
74
75
# Compute fragment lengths (col3 - col2) and sort/count them in one pipeline
The FASTA file is also in the allowed directory. We can count sequences, check contig names, and compute per-base composition without loading the whole file into Python.
`bash()` can only write inside the `ai_chat_temp_files/` subdirectory of the allowed directory. Redirects to any other path fail with a read-only filesystem error. Files written there persist to disk and can be read back with `read_file()` or another `bash()` call.
127
128
128
129
```bash
129
-
cat > /tmp/bash_write.py << 'EOF'
130
+
cat > /tmp/bash-demo/bash_write.py << 'EOF'
130
131
# Sort the BED file by start position and save it
131
132
r = bash("sort -k2,2n swipe.bed > ai_chat_temp_files/swipe_sorted.bed")
@@ -178,7 +179,7 @@ message: EROFS: read-only file system
178
179
A command that exits with a non-zero code does not raise an exception — the exit code is returned inside the dict. This lets scripts distinguish between an empty result and an actual error.
179
180
180
181
```bash
181
-
cat > /tmp/bash_exitcodes.py << 'EOF'
182
+
cat > /tmp/bash-demo/bash_exitcodes.py << 'EOF'
182
183
# grep returns 1 when no match is found — not an exception
@@ -205,13 +206,13 @@ stderr: cat: nonexistent_file.txt: No such file or directory
205
206
Bioinformatics tools and language runtimes are not available. Attempting to call them returns a non-zero exit code with `command not found` in stderr. The available set is: grep, sed, awk, sort, uniq, wc, cut, head, tail, cat, find, tr, paste, jq, and standard bash builtins.
206
207
207
208
```bash
208
-
cat > /tmp/bash_unavailable.py << 'EOF'
209
+
cat > /tmp/bash-demo/bash_unavailable.py << 'EOF'
209
210
for cmd in ["samtools view demo.bam", "python3 --version", "bedtools --version"]:
`bash()` is most useful when paired with the BAM query functions. Here we fetch all read lengths from the BAM with `read_info()`, write them to `ai_chat_temp_files/` as a TSV, then use `bash()` to compute summary statistics and find the top-5 longest reads.
227
228
228
229
```bash
229
-
cat > /tmp/bash_combined.py << 'EOF'
230
+
cat > /tmp/bash-demo/bash_combined.py << 'EOF'
230
231
# Fetch all read lengths from the BAM and write as TSV for bash processing
@@ -265,11 +266,12 @@ top-5 by length (len read_id):
265
266
`bash()` is well-suited for summarising data already written to `ai_chat_temp_files/`. Here we compute a read-length histogram from the TSV written in the previous section and render it as a text bar chart entirely in shell using awk and sort.
266
267
267
268
```bash
268
-
cat > /tmp/bash_histogram.py << 'EOF'
269
+
cat > /tmp/bash-demo/bash_histogram.py << 'EOF'
269
270
r = bash("tail -n +2 ai_chat_temp_files/reads.tsv | awk '{bin=int($2/200)*200; count[bin]++; total++} END{for(k in count){pct=count[k]*100/total; bar=\"\"; for(j=0;j<int(pct/2+0.5);j++) bar=bar \"#\"; printf \"%d-%d bp %3d %s\\n\", k, k+199, count[k], bar}}' | sort -n")
0 commit comments