Skip to content

Commit 76923cd

Browse files
authored
Merge pull request #51 from Juke34/38
fix #38 #49 #50 update readitools3
2 parents ced6a58 + a1fd531 commit 76923cd

9 files changed

Lines changed: 261 additions & 647 deletions

File tree

.github/workflows/install_nextflow_v24.10.5.sh

Lines changed: 0 additions & 511 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414

1515
test_rain:
1616

17-
# Avoid running twice for a push + PR
18-
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
17+
# Avoid running twice: skip push events if there's an open PR for this branch
18+
if: github.event_name != 'push' || github.event.pull_request == null
1919

2020
runs-on: ubuntu-24.04
2121

@@ -40,48 +40,44 @@ jobs:
4040
key: ${{ runner.os }}-openjdk-11
4141
restore-keys: |
4242
${{ runner.os }}-openjdk-11
43+
4344
- name: Install OpenJDK
44-
if: ${{ steps.cache-openjdk.outputs.cache-hit != 'true' }}
45-
run: sudo apt-get install openjdk-11-jdk
45+
if: steps.cache-openjdk.outputs.cache-hit != 'true'
46+
run: sudo apt-get update && sudo apt-get install -y openjdk-11-jdk
4647

4748
# Install/cache Nextflow
4849
- name: Cache Nextflow
4950
id: cache-nextflow
5051
uses: actions/cache@v4
5152
with:
5253
path: /usr/local/bin/nextflow
53-
key: ${{ runner.os }}-nextflow
54+
key: ${{ runner.os }}-nextflow-24.10.6
5455
restore-keys: |
55-
${{ runner.os }}-nextflow
56+
${{ runner.os }}-nextflow-24.10.6
57+
5658
- name: Install Nextflow
57-
if: ${{ steps.cache-nextflow.outputs.cache-hit != 'true' }}
58-
run: cat .github/workflows/install_nextflow_v24.10.5.sh | bash && mv nextflow /usr/local/bin && chmod +x /usr/local/bin/nextflow
59-
60-
# Check-out the repo under $GITHUB_WORKSPACE so that the job can access it
61-
- uses: actions/checkout@v4
59+
if: steps.cache-nextflow.outputs.cache-hit != 'true'
60+
run: export NXF_VER=24.10.6 && curl -s https://get.nextflow.io | bash && sudo mv nextflow /usr/local/bin && sudo chmod +x /usr/local/bin/nextflow
6261

63-
- name: Cache Dockerfiles and TAR
62+
# Cache Docker images
63+
- name: Cache Docker images
6464
id: cache-dockerfiles
6565
uses: actions/cache@v4
6666
with:
6767
path: docker-images.tar
6868
key: ${{ runner.os }}-dockerfiles-${{ hashFiles('docker/**/*') }}
69+
restore-keys: |
70+
${{ runner.os }}-dockerfiles-
6971
7072
- name: Load cached Docker images
71-
id: load-cache
73+
if: steps.cache-dockerfiles.outputs.cache-hit == 'true'
7274
run: |
73-
if [ -f docker-images.tar ]; then
74-
echo "Loading cached Docker images..."
75-
docker load -i docker-images.tar || true
76-
echo "build=false" >> $GITHUB_ENV
77-
else
78-
echo "No Docker cache found"
79-
echo "build=true" >> $GITHUB_ENV
80-
fi
75+
echo "Loading cached Docker images..."
76+
docker load -i docker-images.tar
8177
82-
- name: Build images
83-
if: env.build == 'true' || steps.cache-dockerfiles.outputs.cache-hit != 'true'
84-
run: bash build_images.sh github_action
78+
- name: Build Docker images
79+
if: steps.cache-dockerfiles.outputs.cache-hit != 'true'
80+
run: bash build_containers.sh --docker --github_action
8581

8682
# Run test(s)
8783
- name: test short single

bin/rna_site_variant_readers.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,8 @@ def close(self) -> None:
107107
class ReditoolsXReader(RNASiteVariantReader):
108108
"""Abstract base class defining common methods for the readers for the Reditools2 and Reditools3 formats"""
109109

110-
header_strings = (
111-
"Region",
112-
"Position",
113-
"Reference",
114-
"Strand",
115-
"Coverage-q30",
116-
"MeanQ",
117-
"BaseCount[A,C,G,T]",
118-
"AllSubs",
119-
"Frequency",
120-
"gCoverage-q30",
121-
"gMeanQ",
122-
"gBaseCount[A,C,G,T]",
123-
"gAllSubs",
124-
"gFrequency",
125-
)
110+
# header_strings should be defined in subclasses
111+
header_strings = ()
126112

127113
def __init__(self, file_handle: TextIO) -> None:
128114
self.file_handle: TextIO = file_handle
@@ -227,6 +213,23 @@ def close(self) -> None:
227213
self.file_handle.close()
228214

229215
class Reditools2Reader(ReditoolsXReader):
216+
header_strings = (
217+
"Region",
218+
"Position",
219+
"Reference",
220+
"Strand",
221+
"Coverage-q30",
222+
"MeanQ",
223+
"BaseCount[A,C,G,T]",
224+
"AllSubs",
225+
"Frequency",
226+
"gCoverage-q30",
227+
"gMeanQ",
228+
"gBaseCount[A,C,G,T]",
229+
"gAllSubs",
230+
"gFrequency",
231+
)
232+
230233
def parse_strand(self) -> int:
231234
strand = int(self.parts[REDITOOLS_FIELD_INDEX["Strand"]])
232235
match strand:
@@ -240,6 +243,23 @@ def parse_strand(self) -> int:
240243
raise Exception(f"Invalid strand value: {strand}")
241244

242245
class Reditools3Reader(ReditoolsXReader):
246+
header_strings = (
247+
"Region",
248+
"Position",
249+
"Reference",
250+
"Strand",
251+
"Coverage",
252+
"MeanQ",
253+
"BaseCount[A,C,G,T]",
254+
"AllSubs",
255+
"Frequency",
256+
"gCoverage",
257+
"gMeanQ",
258+
"gBaseCount[A,C,G,T]",
259+
"gAllSubs",
260+
"gFrequency",
261+
)
262+
243263
def parse_strand(self) -> int:
244264
strand_str = self.parts[REDITOOLS_FIELD_INDEX["Strand"]]
245265
match strand_str:

build_containers.sh

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#!/usr/bin/env bash
2+
3+
# Unified container build script
4+
# Usage:
5+
# ./build_containers.sh # Build both Docker and Singularity (default)
6+
# ./build_containers.sh --docker # Build only Docker images
7+
# ./build_containers.sh --singularity # Build only Singularity images
8+
# ./build_containers.sh --all # Build both (explicit)
9+
# ./build_containers.sh --github_action # Build both for GitHub Actions
10+
# ./build_containers.sh --docker github_action # Build Docker for GitHub Actions
11+
# ./build_containers.sh --singularity github_action # Build Singularity for GitHub Actions
12+
13+
set -e
14+
15+
# Parse arguments
16+
build_docker=false
17+
build_singularity=false
18+
github_action_mode=""
19+
auto_detect=false
20+
21+
# If no arguments provided, auto-detect available tools
22+
if [ $# -eq 0 ]; then
23+
auto_detect=true
24+
fi
25+
26+
# Parse all arguments
27+
while [ $# -gt 0 ]; do
28+
case "$1" in
29+
--docker)
30+
build_docker=true
31+
;;
32+
--singularity|--apptainer)
33+
build_singularity=true
34+
;;
35+
--all)
36+
build_docker=true
37+
build_singularity=true
38+
;;
39+
--github_action)
40+
github_action_mode="github_action"
41+
# If --github_action is used without --docker or --singularity, enable auto-detect
42+
if [ "$build_docker" = false ] && [ "$build_singularity" = false ]; then
43+
auto_detect=true
44+
fi
45+
;;
46+
-h|--help)
47+
echo "Usage: $0 [OPTIONS] [github_action]"
48+
echo ""
49+
echo "Options:"
50+
echo " --docker Build Docker images only"
51+
echo " --singularity Build Singularity/Apptainer images only"
52+
echo " --apptainer Alias for --singularity"
53+
echo " --all Build both Docker and Singularity images"
54+
echo " (no options) Build both by default"
55+
echo ""
56+
echo "Additional arguments:"
57+
echo " github_action Enable GitHub Actions mode (saves to archive)"
58+
echo ""
59+
echo "Examples:"
60+
echo " $0 # Build both (default)"
61+
echo " $0 --docker # Build only Docker"
62+
echo " $0 --singularity github_action # Build Singularity for CI"
63+
exit 0
64+
;;
65+
*)
66+
echo "Unknown option: $1"
67+
echo "Use --help for usage information"
68+
exit 1
69+
;;
70+
esac
71+
shift
72+
done
73+
74+
# Auto-detect available tools if no specific option was provided
75+
if [ "$auto_detect" = true ]; then
76+
echo "Auto-detecting available container tools..."
77+
78+
if command -v docker &> /dev/null; then
79+
echo " ✓ Docker found"
80+
build_docker=true
81+
else
82+
echo " ✗ Docker not found"
83+
fi
84+
85+
if command -v singularity &> /dev/null; then
86+
echo " ✓ Singularity/Apptainer found"
87+
build_singularity=true
88+
else
89+
echo " ✗ Singularity/Apptainer not found"
90+
fi
91+
92+
# Check if at least one tool is available
93+
if [ "$build_docker" = false ] && [ "$build_singularity" = false ]; then
94+
echo ""
95+
echo "❌ Error: Neither Docker nor Singularity/Apptainer found on this system."
96+
echo "Please install at least one container tool to proceed."
97+
exit 1
98+
fi
99+
100+
echo ""
101+
fi
102+
103+
# Save original working directory
104+
wd=$(pwd)
105+
106+
# Get architecture for Docker builds
107+
arch=$(uname -m)
108+
109+
# Build Docker images if requested
110+
if [ "$build_docker" = true ]; then
111+
echo "════════════════════════════════════════════════════════════════"
112+
echo " Building Docker images..."
113+
echo "════════════════════════════════════════════════════════════════"
114+
115+
# List of image names
116+
image_list=( )
117+
118+
for dir in docker/*; do
119+
cd "${dir}"
120+
imgname=$(echo $dir | rev | cut -d/ -f1 | rev)
121+
image_list+=(${imgname})
122+
123+
echo ██████████████████▓▒░ Building ${imgname} ░▒▓██████████████████
124+
125+
# Set architecture to docker buildx
126+
docker_arch_option=""
127+
128+
# Reditools2 and Pluviometer do not compile on arm64, force using amd64 compilation
129+
if [[ "$arch" == arm* || "$arch" == "aarch64" ]]; then
130+
if [[ $dir =~ "reditools2" ]] || [[ $dir =~ "pluviometer" ]]; then
131+
echo "$imgname does not compile on arm64, force using amd64 compilation"
132+
docker_arch_option=" --platform linux/amd64"
133+
fi
134+
fi
135+
136+
docker build ${docker_arch_option} -t ${imgname} .
137+
138+
# Back to the original working directory
139+
cd "$wd"
140+
done
141+
142+
if [[ ${github_action_mode} == 'github_action' ]]; then
143+
echo "Saving docker images to cache..."
144+
docker save ${image_list[@]} -o docker-images.tar
145+
echo Archive size: $(stat --printf="%s" docker-images.tar)
146+
fi
147+
148+
echo ""
149+
fi
150+
151+
# Build Singularity images if requested
152+
if [ "$build_singularity" = true ]; then
153+
echo "════════════════════════════════════════════════════════════════"
154+
echo " Building Singularity/Apptainer images..."
155+
echo "════════════════════════════════════════════════════════════════"
156+
157+
# Create output directory for .sif images
158+
mkdir -p sif_images
159+
160+
# List to store built images
161+
sif_list=( )
162+
163+
# Loop through all .def files in singularity/ subdirectories
164+
for def_file in singularity/*/*.def; do
165+
# Extract image name from directory
166+
imgname=$(basename "$(dirname "$def_file")")
167+
sif_output="sif_images/${imgname}.sif"
168+
sif_list+=("$sif_output")
169+
170+
echo ██████████████████▓▒░ Building ${imgname} ░▒▓██████████████████
171+
172+
# Build with fakeroot if available
173+
if command -v singularity &> /dev/null; then
174+
singularity build --fakeroot "$sif_output" "$def_file"
175+
else
176+
echo "❌ Singularity not found! Aborting."
177+
exit 1
178+
fi
179+
done
180+
181+
# If used in GitHub Actions, create an archive
182+
if [[ ${github_action_mode} == 'github_action' ]]; then
183+
echo "Saving SIF images to cache archive..."
184+
tar -cf singularity-images.tar "${sif_list[@]}"
185+
echo Archive size: $(stat --printf="%s" singularity-images.tar)
186+
fi
187+
188+
echo ""
189+
fi
190+
191+
echo "════════════════════════════════════════════════════════════════"
192+
echo " ✓ Build complete!"
193+
echo "════════════════════════════════════════════════════════════════"

build_images.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)