-
Notifications
You must be signed in to change notification settings - Fork 4
/
pbs2slurm_tests.py
1049 lines (842 loc) · 22.7 KB
/
pbs2slurm_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pbs2slurm as p2s
import sys
import atexit
import difflib
def html_out(fh, pbs, slurm, desc):
pbss = pbs.replace(">", ">").replace("<", "<")
slurms = slurm.replace(">", ">").replace("<", "<")
fh.write("""
<tr><td colspan=2>{desc}</td></tr>
<tr><td>
<pre class="term">{pbss}</pre>
</td>
<td>
<pre class="term">{slurms}</pre>
</td>
</tr>
""".format(**locals()))
def html_header(fh):
fh.write("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>pbs2slurm test cases</title>
<style>pre.term {background-color: #eee; padding: 3px 5px; border: 1px solid #999}</style>
</head>
<body>
<!-- START page content -->
<table id="test_output">
<tr><th><b>PBS script</b></th>
<th><b>SLURM script</b></th>
</tr>
""")
def html_footer(fh):
fh.write("""
</table>
<!-- END page content -->
</body>
</html>
""")
def check(input, exp, obs, desc):
if exp != obs:
d = difflib.Differ()
sys.stdout.writelines(d.compare(
exp.splitlines(1),
obs.splitlines(1)))
assert False
else:
# only output testcases that pass
html_out(html, input, exp, desc)
def test_plain_bash():
desc = "Plain bash scripts remain unchanged"
input = """#!/bin/bash
set -e
set -o pipefail
module load fastqc
cd /data/$USER/test_data
fastqc -d /scratch -f fastq --noextract some.fastq.gz
"""
check(input, input, p2s.convert_batch_script(input), desc)
################################################################################
# PBS environment variables
def test_pbs_o_workdir():
desc = "Change <tt>PBS_O_WORKDIR</tt> to <tt>SLURM_SUBMIT_DIR</tt>"
input = """#!/bin/bash
set -e
set -o pipefail
cd $PBS_O_WORKDIR
echo ${PBS_O_WORKDIR}
module load fastqc
cd /data/$USER/test_data
fastqc -d /scratch -f fastq --noextract some.fastq.gz
"""
expected = """#!/bin/bash
set -e
set -o pipefail
cd $SLURM_SUBMIT_DIR
echo ${SLURM_SUBMIT_DIR}
module load fastqc
cd /data/$USER/test_data
fastqc -d /scratch -f fastq --noextract some.fastq.gz
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_pbs_jobid():
desc = "Change <tt>PBS_JOBID</tt> to <tt>SLURM_JOB_ID</tt>"
input = """#!/bin/bash
set -e
set -o pipefail
module load fastxtoolkit
cd /data/$USER/test_data
echo "Job $PBS_JOBID starting" > logfile
zcat some.fq.gz \\
| tr '.' 'N' \\
| fastx_artifacts_filter \\
| fastx_clipper -a AGATCGGAAGAGC \\
| fastq_quality_trimmer -t 20 -l 10 -z \\
> some.clean.fq.gz
echo "Job $PBS_JOBID done" >> logfile
"""
expected = """#!/bin/bash
set -e
set -o pipefail
module load fastxtoolkit
cd /data/$USER/test_data
echo "Job $SLURM_JOB_ID starting" > logfile
zcat some.fq.gz \\
| tr '.' 'N' \\
| fastx_artifacts_filter \\
| fastx_clipper -a AGATCGGAAGAGC \\
| fastq_quality_trimmer -t 20 -l 10 -z \\
> some.clean.fq.gz
echo "Job $SLURM_JOB_ID done" >> logfile
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_pbs_arrayid():
desc = "Change <tt>PBS_ARRAY_INDEX</tt> to <tt>SLURM_ARRAY_TASK_ID</tt>"
input = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
cd /data/$USER/test_data
module load bowtie/1.1.1 samtools/1.2
gunzip -c sample${PBS_ARRAY_INDEX}.fastq.gz \\
| bowtie --sam --best --strata --all -m1 -n2 \\
--threads=10 /path/to/genome/index - \\
| samtools view -Sb -F4 - \\
> sample${PBS_ARRAY_INDEX}.bam
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
cd /data/$USER/test_data
module load bowtie/1.1.1 samtools/1.2
gunzip -c sample${SLURM_ARRAY_TASK_ID}.fastq.gz \\
| bowtie --sam --best --strata --all -m1 -n2 \\
--threads=10 /path/to/genome/index - \\
| samtools view -Sb -F4 - \\
> sample${SLURM_ARRAY_TASK_ID}.bam
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# misc
def test_missing_shebang():
desc = "If there is not shebang line, insert one (bash by default, can be changed)"
input = """set -e
set -o pipefail
module load bowtie/1.1.1 samtools/1.2
cd /data/$USER/test_data
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load bowtie/1.1.1 samtools/1.2
cd /data/$USER/test_data
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_header_identification():
desc = """PBS directives in the header are identified and transformed. PBS directives
in the body are left unchanged"""
input = """#! /bin/bash
#some other comment
#PBS -N fastqc_job
#PBS -N other_name
set -e
set -o pipefail
#PBS -N other
module load fastqc
cd /data/$USER/test_data
"""
expected = """#! /bin/bash
#some other comment
#SBATCH --job-name="fastqc_job"
#SBATCH --job-name="other_name"
set -e
set -o pipefail
#PBS -N other
module load fastqc
cd /data/$USER/test_data
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# job name
def test_jobname():
desc = "Change <tt>#PBS -N</tt> to <tt>#SBATCH --job-name</tt>"
input = """#! /bin/bash
#PBS -N fastqc_job
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --job-name="fastqc_job"
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_jobname_empty():
desc = "<tt>#PBS -N</tt> is dropped if job name is missing"
input = """#! /bin/bash
#PBS -N
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# email address
def test_valid_email_address():
desc = "Change </tt>#PBS -M</tt> to <tt>#SBATCH --mail-user</tt>"
input = """#! /bin/bash
#PBS -M [email protected]
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --mail-user="[email protected]"
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_empty_email_address():
desc = "<tt>#PBS -M</tt> is dropped if email address is missing"
input = """#! /bin/bash
#PBS -M
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_multiple_email_addresses():
desc = "If <tt>#PBS -M</tt> has a list of valid email addresses, pick first one"
input = """#! /bin/bash
#PBS -M [email protected],[email protected]
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --mail-user="[email protected]"
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_multiple_email_addresses2():
desc = "If <tt>#PBS -M</tt> has a list of email addresses, pick first valid one"
input = """#! /bin/bash
#PBS -M student,[email protected]
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --mail-user="[email protected]"
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# email mode
def test_email_modes_n():
desc = "Drop <tt>#PBS -m n</tt> email modes since this is the default behaviour for Slurm"
input = """#! /bin/bash
#PBS -m n
module load bowtie
"""
expected = """#! /bin/bash
module load bowtie
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_email_modes_a():
desc = "Change <tt>#PBS -m a</tt> to <tt>#SBATCH --mail-type=FAIL</tt>"
input = """#! /bin/bash
#PBS -m a
module load bowtie
"""
expected = """#! /bin/bash
#SBATCH --mail-type=FAIL
module load bowtie
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_email_modes_b():
desc = "Change <tt>#PBS -m b</tt> to <tt>#SBATCH --mail-type=BEGIN</tt>"
input = """#! /bin/bash
#PBS -m b
module load bowtie
"""
expected = """#! /bin/bash
#SBATCH --mail-type=BEGIN
module load bowtie
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_email_modes_e():
desc = "Change <tt>#PBS -m e</tt> to <tt>#SBATCH --mail-type=END</tt>"
input = """#! /bin/bash
#PBS -m e
module load bowtie
"""
expected = """#! /bin/bash
#SBATCH --mail-type=END
module load bowtie
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_email_modes_be():
desc = "Change <tt>#PBS -m be|eb</tt> to <tt>#SBATCH --mail-type=BEGIN,END</tt>"
input = """#! /bin/bash
#PBS -m be
module load bowtie
"""
expected = """#! /bin/bash
#SBATCH --mail-type=BEGIN,END
module load bowtie
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_email_modes_abe():
desc = "Change <tt>#PBS -m abe|aeb|...</tt> to <tt>#SBATCH --mail-type=BEGIN,END,FAIL</tt>"
desc = "Change #PBS -m email modes: abe"
input = """#! /bin/bash
#PBS -m abe
module load bowtie
"""
expected = """#! /bin/bash
#SBATCH --mail-type=BEGIN,END,FAIL
module load bowtie
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_email_modes_aben():
desc = "If <tt>#PBS -m</tt> contains n in addition to other options, n has precedence since it's Slurm's default"
input = """#! /bin/bash
#PBS -m aben
module load bowtie
"""
expected = """#! /bin/bash
module load bowtie
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_email_modes_empty():
desc = "<tt>#PBS -m</tt> is dropped if email mode is missing"
input = """#! /bin/bash
#PBS -m
module load bowtie
"""
expected = """#! /bin/bash
module load bowtie
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# stderr and stdout files
def test_keep_directive_ignored():
desc = "<tt>#PBS -k</tt> is dropped since it is not necessary for Slurm"
input = """#! /bin/bash
#PBS -k oe
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_join_directive_ignored_eo():
desc = "<tt>#PBS -j</tt> is dropped since joining stdout and stderr is the default in Slurm"
input = """#! /bin/bash
#PBS -j eo
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_stdout_directive():
desc = "Change <tt>#PBS -o</tt> to <tt>#SBATCH --output</tt>"
input = """#! /bin/bash
#PBS -o /path/to/some/file
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --output=/path/to/some/file
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_empty_stdout_directive():
desc = "<tt>#PBS -o</tt> is dropped if output path is missing"
input = """#! /bin/bash
#PBS -o
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_stderr_directive():
desc = "Change <tt>#PBS -e</tt> to <tt>#SBATCH --error</tt>"
input = """#! /bin/bash
#PBS -e /path/to/some/file
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --error=/path/to/some/file
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_empty_stderr_directive():
desc = "<tt>#PBS -e</tt> is dropped if error path is missing"
input = """#! /bin/bash
#PBS -e
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# restartable
def test_restartable_directive_y():
desc = "Change <tt>#PBS -r y</tt> to <tt>#SBATCH --requeue</tt>"
input = """#! /bin/bash
#PBS -r y
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --requeue
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_restartable_directive_n():
desc = "Change <tt>#PBS -r n</tt> to <tt>#SBATCH --no-requeue</tt>"
input = """#! /bin/bash
#PBS -r n
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --no-requeue
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_restartable_directive_bad():
desc = "<tt>#PBS -r</tt> is dropped if any other argument is detected or the argument is missing"
input = """#! /bin/bash
#PBS -r fnord
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# shell
def test_drop_shell_directive():
desc = "<tt>#PBS -S</tt> is dropped since Slurm uses shebang lines to determine the interpreter"
input = """#! /bin/bash
#PBS -S /bin/bash
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# export environment variables
def test_export_whole_env():
desc = "Change <tt>#PBS -V</tt> to <tt>#SBATCH --export=ALL</tt> (even though this is the Slurm default"
input = """#! /bin/bash
#PBS -V
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --export=ALL
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_export_individual_variables_1():
desc = "Change <tt>#PBS -v</tt> to <tt>#SBATCH --export=</tt>"
input = """#! /bin/bash
#PBS -v np=300
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --export=np=300
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_export_individual_variables_2():
desc = "Change <tt>#PBS -v</tt> to <tt>#SBATCH --export=</tt>; remove spaces"
input = """#! /bin/bash
#PBS -v np=300, fnord=1
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --export=np=300,fnord=1
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_export_individual_variables_2():
desc = "Change <tt>#PBS -v</tt> to <tt>#SBATCH --export=</tt>; remove spaces"
input = """#! /bin/bash
#PBS -V
#PBS -v np=300, fnord=1
#PBS -v foo=2
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --export=ALL
#SBATCH --export=np=300,fnord=1
#SBATCH --export=foo=2
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# job array
def test_fix_job_array():
desc = "Change <tt>#PBS -J</tt> to <tt>#SBATCH --array</tt>"
input = """#! /bin/bash
#PBS -J 1-20
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --array=1-20
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_drop_empty_job_array():
desc = "<tt>#PBS -J</tt> is dropped if argument is missing"
input = """#! /bin/bash
#PBS -J
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# #PBS -l
# drop everything except walltime; most of this would have been overridden by
# the qsub wrapper script
def test_resources():
desc = "The only thing parsed out of <tt>PBS -l</tt> resource lists is walltime"
input = """#! /bin/bash
#PBS -l jobfs=500MB
#PBS -l ncpus=1
#PBS -l nice=19
#PBS -l nodes=1
#PBS -l nodes=150:gige
#PBS -l nodes=1:htown:gige:ppn=8,walltime=60:00:00
#PBS -l nodes=1:ppn=1
#PBS -l nodes=1:ppn=2
#PBS -l nodes=1:ppn=4
#PBS -l software=amber
#PBS -l vmem=500MB
#PBS -l walltime=00:05:0
#PBS -l walltime=00:15:0
#PBS -l walltime=00:30:0
#PBS -l walltime=12:00:00,mem=1000mb
#PBS -l walltime=20:00:00
#PBS -l walltime=24:00:00
#PBS -l walltime=400:00:00,nodes=1:ppn=4,pmem=800mb
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
#SBATCH --time=60:00:00
#SBATCH --time=00:05:00
#SBATCH --time=00:15:00
#SBATCH --time=00:30:00
#SBATCH --time=12:00:00
#SBATCH --time=20:00:00
#SBATCH --time=24:00:00
#SBATCH --time=400:00:00
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# PBS -q
# should not have worked with the qsub wrapper. the instances i found were not
# actually valid queues. drop -q lines
def test_drop_queue():
desc = "Drop <tt>#PBS -q</tt> since there is not reliable, straight forward translation. Please provide partition on the command line"
input = """#! /bin/bash
#PBS -q serial
#PBS -q batch
#PBS -q tracking
#PBS -q normal
set -e
set -o pipefail
module load fastqc
"""
expected = """#! /bin/bash
set -e
set -o pipefail
module load fastqc
"""
check(input, expected, p2s.convert_batch_script(input), desc)
################################################################################
# complete examples
def test_script1():
desc = "Complete example 1"
input = """#!/bin/csh -v
#PBS -N germline
#PBS -m be
#PBS -k oe
cd $PBS_O_WORKDIR
germline -bits 50 -min_m 1 -err_hom 2 <<EOF
1
CEU.22.map
CEU.22.ped
generated
EOF
"""
expected = """#!/bin/csh -v
#SBATCH --job-name="germline"
#SBATCH --mail-type=BEGIN,END
cd $SLURM_SUBMIT_DIR
germline -bits 50 -min_m 1 -err_hom 2 <<EOF
1
CEU.22.map
CEU.22.ped
generated
EOF
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_script2():
desc = "Complete example 2"
input = """#! /bin/bash
#PBS -N H3K27me3
#PBS -m e
#PBS -k n
cd ${PBS_O_WORKDIR}
# non redundant
slopBed -i K27me3.bed -g mm9.genome -r 126 -s -l 0 \\
| intersectBed -a stdin -b refseqTss.bed -wa -wb\\
| awk '$2 != c {print; c = $2}' \\
| cut -f10 \\
| sort -S1G \\
| uniq -c \\
| sed -r 's/^ +//;s/ /|/' \\
> count_data/K27me3.nr.ncount
"""
expected = """#! /bin/bash
#SBATCH --job-name="H3K27me3"
#SBATCH --mail-type=END
cd ${SLURM_SUBMIT_DIR}
# non redundant
slopBed -i K27me3.bed -g mm9.genome -r 126 -s -l 0 \\
| intersectBed -a stdin -b refseqTss.bed -wa -wb\\
| awk '$2 != c {print; c = $2}' \\
| cut -f10 \\
| sort -S1G \\
| uniq -c \\
| sed -r 's/^ +//;s/ /|/' \\
> count_data/K27me3.nr.ncount
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_script3():
desc = "Complete example 3"
input = """# This is a sample PBS script. It will
# request 1 processor on 1 node
# for 4 hours.
#PBS -l nodes=1:ppn=1
# Request 4 hours of walltime
#PBS -l walltime=4:00:00
#PBS -l pmem=1gb
# Request that stdout and stderr go
# to the same file
#PBS -j oe
#
# ======== BODY ========
cd $PBS_O_WORKDIR
echo "Job started on `hostname` at `date`"
./hello
echo "Job Ended at `date`"
"""
expected = """#! /bin/bash
# This is a sample PBS script. It will
# request 1 processor on 1 node
# for 4 hours.
# Request 4 hours of walltime
#SBATCH --time=4:00:00
# Request that stdout and stderr go
# to the same file
#
# ======== BODY ========
cd $SLURM_SUBMIT_DIR
echo "Job started on `hostname` at `date`"
./hello
echo "Job Ended at `date`"
"""
check(input, expected, p2s.convert_batch_script(input), desc)
def test_script4():
desc = "Complete example 4"
input = """#!/bin/bash -l
#PBS -l walltime=8:00:00,nodes=3:ppn=8,pmem=1000mb
#PBS -m abe
#PBS -M [email protected]
cd ~/program_directory
module load intel
module load ompi/intel
mpirun -np 24 program_name < inputfile > outputfile
"""
expected = """#!/bin/bash -l
#SBATCH --time=8:00:00
#SBATCH --mail-type=BEGIN,END,FAIL
#SBATCH --mail-user="[email protected]"
cd ~/program_directory
module load intel
module load ompi/intel
mpirun -np 24 program_name < inputfile > outputfile
"""
check(input, expected, p2s.convert_batch_script(input), desc)
if __name__ == '__main__':
# this is a pretty stupid way of doing this - should have used a testing
# framework
testfunctions = (
test_plain_bash,