-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
executable file
·84 lines (66 loc) · 2.42 KB
/
Snakefile
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
"""Snakemake GRASS test Snakefile, to run all tests::
$ snakemake -j 3 all
$ snakemake clean
"""
import os.path as osp
from snakemake_grass import *
TEST_DB = './grassdb/'
grass_ll = GrassLocation(TEST_DB, 'lonlat', epsg=4326)
grass_eu = GrassLocation(TEST_DB, 'eu', epsg=3035)
rule new_location:
output: grass_ll.location
shell: grass_ll('g.proj -p')
rule new_mapset:
input: rules.new_location.output
output: grass_ll.mapset('new_mapset')
shell: grass_ll('g.region -p', mapset='new_mapset')
rule new_raster:
input: rules.new_location.output
output: grass_ll.raster('new_raster')
shell: grass_ll('r.mapcalc', exp='new_raster=1')
rule new_rasters:
input: rules.new_raster.output
output: grass_ll.rasters("raster_{i}@new_rasters", i=range(3))
shell:
grass_ll('g.copy', mapset='new_rasters',
raster=[input_to_map()+',raster_%i' % i
for i in range(3)])
rule new_vector:
input: rules.new_location.output
output: grass_ll.vector('new_vector')
shell: grass_ll('v.in.region', output='new_vector')
rule new_vectors:
input: rules.new_vector.output
output: grass_ll.vectors("vector_{i}@new_vectors", i=range(3))
shell:
grass_ll('g.copy', mapset='new_vectors',
vector=[input_to_map()+','+output_to_map(i) for i in range(3)])
rule new_location_mapset_raster:
output: grass_eu.raster('test_raster@test_raster')
shell:
grass_eu('r.mapcalc', exp=output_to_map()+'=1', mapset='test_raster')
rule raster_template:
input: rules.new_raster.output
output: grass_ll.raster('raster{i}@raster{i}')
shell:
grass_ll('r.mapcalc', mapset=output_to_map(),
exp='raster{wildcards.i}={wildcards.i}')
rule merged_raster:
input: grass_ll.rasters('raster{i}@raster{i}', i=range(6))
output: grass_ll.raster('merged_raster')
shell:
grass_ll('r.series', input=[input_to_map(i) for i in range(6)],
method='count', output=output_to_map())
rule all:
input:
rules.new_mapset.output,
rules.new_rasters.output,
rules.new_vectors.output,
rules.new_location_mapset_raster.output,
rules.merged_raster.output
rule clean:
shell: "rm -r "+TEST_DB
rule workflow_graph:
input: 'Snakefile'
output: "{type}-{rule}.png"
shell: "snakemake --nolock --{wildcards.type} {wildcards.rule} | dot -T png -o {output}"