CGATcore Pipeline Module¶
The pipeline
module is the core component of CGAT-core, providing essential functionality for building and executing computational pipelines.
Core Functions¶
Pipeline Decorators¶
@transform(input_files, suffix(".input"), ".output")
def task_function(infile, outfile):
"""Transform a single input file to an output file."""
pass
@merge(input_files, "output.txt")
def merge_task(infiles, outfile):
"""Merge multiple input files into a single output."""
pass
@split(input_file, "*.split")
def split_task(infile, outfiles):
"""Split a single input file into multiple outputs."""
pass
@follows(previous_task)
def dependent_task():
"""Execute after previous_task completes."""
pass
S3-Aware Decorators¶
@s3_transform("s3://bucket/input.txt", suffix(".txt"), ".processed")
def process_s3_file(infile, outfile):
"""Process files directly from S3."""
pass
@s3_merge(["s3://bucket/*.txt"], "s3://bucket/merged.txt")
def merge_s3_files(infiles, outfile):
"""Merge multiple S3 files."""
pass
Configuration Functions¶
Pipeline Setup¶
# Initialize pipeline
pipeline.initialize(options)
# Get pipeline parameters
params = pipeline.get_params()
# Configure cluster execution
pipeline.setup_cluster()
Resource Management¶
# Set memory requirements
pipeline.set_job_memory("4G")
# Set CPU requirements
pipeline.set_job_threads(4)
# Configure temporary directory
pipeline.set_tmpdir("/path/to/tmp")
Execution Functions¶
Running Tasks¶
# Execute a command
pipeline.run("samtools sort input.bam")
# Submit a Python function
pipeline.submit(
module="my_module",
function="process_data",
infiles="input.txt",
outfiles="output.txt"
)
Job Control¶
# Check job status
pipeline.is_running(job_id)
# Wait for job completion
pipeline.wait_for_jobs()
# Clean up temporary files
pipeline.cleanup()
Error Handling¶
Best Practices¶
- Resource Management
- Always specify memory and CPU requirements
- Use appropriate cluster queue settings
-
Clean up temporary files
-
Error Handling
- Implement proper error checking
- Use pipeline.log for logging
-
Handle temporary file cleanup
-
Performance
- Use appropriate chunk sizes for parallel processing
- Monitor resource usage
- Optimize cluster settings
For more details, see the Pipeline Overview and Writing Workflows guides.
pipeline.py - Tools for CGAT Ruffus Pipelines¶
This module provides a comprehensive set of tools to facilitate the creation and management of data processing pipelines using CGAT Ruffus. It includes functionalities for:
- Pipeline Control
- Task execution and dependency management
- Command-line interface for pipeline operations
-
Logging and error handling
-
Resource Management
- Cluster job submission and monitoring
- Memory and CPU allocation
-
Temporary file handling
-
Configuration
- Parameter management via YAML configuration
- Cluster settings customization
-
Pipeline state persistence
-
Cloud Integration
- AWS S3 support for input/output files
- Cloud-aware pipeline decorators
- Remote file handling
Example Usage¶
A basic pipeline using local files:
.. code-block:: python
from cgatcore import pipeline as P
# Standard pipeline task
@P.transform("input.txt", suffix(".txt"), ".processed")
def process_local_file(infile, outfile):
# Processing logic here
pass
Using S3 integration:
.. code-block:: python
# S3-aware pipeline task
@P.s3_transform("s3://bucket/input.txt", suffix(".txt"), ".processed")
def process_s3_file(infile, outfile):
# Processing logic here
pass
For detailed documentation, see: https://cgat-core.readthedocs.io/
ContainerConfig
¶
Container configuration for pipeline execution.
Source code in cgatcore/pipeline/execution.py
__init__(image=None, volumes=None, env_vars=None, runtime='docker')
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
str
|
Container image (e.g., "ubuntu:20.04"). |
None
|
volumes
|
list
|
Volume mappings (e.g., ['/data:/data']). |
None
|
env_vars
|
dict
|
Environment variables for the container. |
None
|
runtime
|
str
|
Container runtime ("docker" or "singularity"). |
'docker'
|
Source code in cgatcore/pipeline/execution.py
get_container_command(statement)
¶
Convert a statement to run inside a container.
Source code in cgatcore/pipeline/execution.py
DRMAACluster
¶
Bases: object
Source code in cgatcore/pipeline/cluster.py
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 |
|
collect_single_job_from_cluster(job_id, statement, stdout_path, stderr_path, job_path)
¶
collects a single job on the cluster.
This method waits until a job has completed and returns stdout, stderr and resource usage.
Source code in cgatcore/pipeline/cluster.py
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 |
|
get_drmaa_job_stdout_stderr(stdout_path, stderr_path, tries=5, encoding='utf-8')
¶
get stdout/stderr allowing for some lag.
Try at most tries times. If unsuccessfull, throw OSError
Removes the files once they are read.
Returns tuple of stdout and stderr as unicode strings.
Source code in cgatcore/pipeline/cluster.py
map_resource_usage(resource_usage, data2type)
¶
return job metrics mapped to common name and converted to right type.
Source code in cgatcore/pipeline/cluster.py
set_drmaa_job_paths(job_template, job_path)
¶
Adds the job_path, stdout_path and stderr_paths to the job_template.
Source code in cgatcore/pipeline/cluster.py
setup_drmaa_job_template(drmaa_session, job_name, job_memory, job_threads, working_directory, **kwargs)
¶
Sets up a Drmma job template. Currently SGE, SLURM, Torque and PBSPro are supported
Source code in cgatcore/pipeline/cluster.py
EventPool
¶
Bases: Pool
Source code in cgatcore/pipeline/control.py
Executor
¶
Bases: object
Source code in cgatcore/pipeline/execution.py
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
|
build_job_script(statement)
¶
build job script from statement.
returns (name_of_script, stdout_path, stderr_path)
Source code in cgatcore/pipeline/execution.py
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 |
|
cleanup_all_jobs()
¶
Clean up all remaining active jobs on interruption.
Source code in cgatcore/pipeline/execution.py
cleanup_failed_job(job_info)
¶
Clean up files generated by a failed job.
Source code in cgatcore/pipeline/execution.py
collect_benchmark_data(statements, resource_usage)
¶
collect benchmark data from a job's stdout and any resource usage information that might be present.
If time_data is given, read output from time command.
Source code in cgatcore/pipeline/execution.py
expand_statement(statement)
¶
add generic commands before and after statement.
The method scans the statement for arvados mount points and inserts appropriate prefixes to make sure that the mount point exists.
Arguments¶
statement : string Command line statement to expand
Returns¶
statement : string The expanded statement.
Source code in cgatcore/pipeline/execution.py
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 |
|
finish_job(job_info)
¶
Remove a job from active_jobs list when it finishes.
run(statement_list, job_memory=None, job_threads=None, container_runtime=None, image=None, volumes=None, env_vars=None, **kwargs)
¶
Execute a list of statements with optional container support.
Args:
statement_list (list): List of commands to execute.
job_memory (str): Memory requirements (e.g., "4G").
job_threads (int): Number of threads to use.
container_runtime (str): Container runtime ("docker" or "singularity").
image (str): Container image to use.
volumes (list): Volume mappings (e.g., ['/data:/data']).
env_vars (dict): Environment variables for the container.
**kwargs: Additional arguments.
Source code in cgatcore/pipeline/execution.py
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
|
set_container_config(image, volumes=None, env_vars=None, runtime='docker')
¶
Set container configuration for all tasks executed by this executor.
Source code in cgatcore/pipeline/execution.py
setup_signal_handlers()
¶
Set up signal handlers to clean up jobs on SIGINT and SIGTERM.
Source code in cgatcore/pipeline/execution.py
KubernetesExecutor
¶
Bases: BaseExecutor
Executor for managing and running jobs on a Kubernetes cluster.
This class is responsible for submitting jobs to a Kubernetes cluster, monitoring their execution, and collecting benchmark data related to their performance.
Attributes:
Name | Type | Description |
---|---|---|
namespace |
str
|
The Kubernetes namespace in which to run the jobs. Defaults to 'default'. |
api |
CoreV1Api
|
The Kubernetes Core API client for interacting with the cluster. |
batch_api |
BatchV1Api
|
The Kubernetes Batch API client for managing jobs. |
Source code in cgatcore/pipeline/kubernetes.py
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 |
|
__init__(**kwargs)
¶
Initializes the KubernetesExecutor with the specified configuration options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional configuration options, including the namespace. |
{}
|
Source code in cgatcore/pipeline/kubernetes.py
collect_benchmark_data(statements, resource_usage=None)
¶
Collect benchmark data for Kubernetes jobs.
This method gathers information about the executed statements and any resource usage data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements
|
list
|
List of executed statements. |
required |
resource_usage
|
list
|
Resource usage data. |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the task name, total execution time, executed statements, and resource usage data. |
Source code in cgatcore/pipeline/kubernetes.py
collect_metric_data(process, start_time, end_time, time_data_file)
¶
Collects metric data related to job duration and writes it to a file.
Parameters: - process (str): Process name for tracking purposes. - start_time (datetime): Timestamp when the job started. - end_time (datetime): Timestamp when the job ended. - time_data_file (str): Path to a file where timing data will be saved.
Source code in cgatcore/pipeline/kubernetes.py
run(statement, job_path, job_condaenv)
¶
Submits a job to the Kubernetes cluster to run the specified command.
This method creates a Kubernetes Job object and submits it to the cluster. The job runs the specified command in a container, using the provided Conda environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement
|
str
|
The command to execute in the job. |
required |
job_path
|
str
|
The path to the job script. |
required |
job_condaenv
|
str
|
The name of the Conda environment to use. |
required |
Source code in cgatcore/pipeline/kubernetes.py
LoggingFilterProgress
¶
Bases: Filter
add progress information to the log-stream.
A :term:task
is a ruffus_ decorated function, which will execute
one or more :term:jobs
.
Valid task/job status: update task/job needs updating completed task/job completed successfully failed task/job failed running task/job is running ignore ignore task/job (is up-to-date)
This filter adds the following context to a log record:
task task_name
task_status task status
task_total number of jobs in task
task_completed number of jobs in task completed
task_completed_percent percentage of task completed
The filter will also generate an additional log message in json format with the fields above.
Arguments¶
ruffus_text : string Log messages from ruffus.pipeline_printout. These are used to collect all tasks that will be executed during pipeline execution.
Source code in cgatcore/pipeline/control.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
|
LoggingFilterpipelineName
¶
Bases: Filter
add pipeline name to log message.
With this filter, %(app_name)s can be used in log formats.
Source code in cgatcore/pipeline/control.py
MultiLineFormatter
¶
Bases: Formatter
logfile formatter: add identation for multi-line entries.
Source code in cgatcore/experiment.py
SGEExecutor
¶
Bases: BaseExecutor
Source code in cgatcore/pipeline/executors.py
build_job_script(statement)
¶
collect_benchmark_data(statements, resource_usage=None)
¶
Collect benchmark data for SGE jobs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements
|
list
|
List of executed statements |
required |
resource_usage
|
list
|
Resource usage data |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Benchmark data including task name and execution time |
Source code in cgatcore/pipeline/executors.py
monitor_job_completion(job_id)
¶
Monitor the completion of an SGE job.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job_id
|
str
|
The SGE job ID to monitor. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the job fails or times out. |
Source code in cgatcore/pipeline/executors.py
SlurmExecutor
¶
Bases: BaseExecutor
Executor for running jobs on Slurm cluster.
Source code in cgatcore/pipeline/executors.py
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 |
|
build_job_script(statement)
¶
collect_benchmark_data(statements, resource_usage=None)
¶
Collect benchmark data for Slurm jobs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements
|
list
|
List of executed statements |
required |
resource_usage
|
list
|
Resource usage data |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Benchmark data including task name and execution time |
Source code in cgatcore/pipeline/executors.py
monitor_job_completion(job_id)
¶
Monitor the completion of a Slurm job.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job_id
|
str
|
The Slurm job ID to monitor. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the job fails or times out. |
Source code in cgatcore/pipeline/executors.py
TorqueExecutor
¶
Bases: BaseExecutor
Executor for running jobs on Torque cluster.
Source code in cgatcore/pipeline/executors.py
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 |
|
build_job_script(statement)
¶
collect_benchmark_data(statements, resource_usage=None)
¶
Collect benchmark data for Torque jobs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statements
|
list
|
List of executed statements |
required |
resource_usage
|
list
|
Resource usage data |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Benchmark data including task name and execution time |
Source code in cgatcore/pipeline/executors.py
monitor_job_completion(job_id)
¶
Monitor the completion of a Torque job.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job_id
|
str
|
The Torque job ID to monitor. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the job fails or times out. |
Source code in cgatcore/pipeline/executors.py
add_doc(value, replace=False)
¶
add doc string of value to function that is decorated.
The original doc-string is added as the first paragraph(s) inside the new doc-string.
Parameter¶
bool
If True, replace documentation rather than appending
Source code in cgatcore/pipeline/utils.py
as_list(value)
¶
return a value as a list.
If the value is a string and contains a ,
, the string will
be split at ,
.
Returns¶
list
Source code in cgatcore/pipeline/parameters.py
build_load_statement(tablename, retry=True, options='')
¶
build a command line statement to upload data.
Upload is performed via the :doc:csv2db
script.
The returned statement is suitable to use in pipe expression. This method is aware of the configuration values for database access and the chosen database backend.
For example::
load_statement = P.build_load_statement("data")
statement = "cat data.txt | %(load_statement)s"
P.run(statement)
Arguments¶
tablename : string
Tablename for upload
retry : bool
Add the --retry
option to csv2db.py
options : string
Command line options to be passed on to csv2db.py
Returns¶
string
Source code in cgatcore/pipeline/database.py
check_executables(filenames)
¶
check for the presence/absence of executables
Source code in cgatcore/pipeline/files.py
check_parameter(param)
¶
check_scripts(filenames)
¶
check for the presence/absence of scripts
Source code in cgatcore/pipeline/files.py
clean(files, logfile)
¶
clean up files given by glob expressions.
Files are cleaned up by zapping, i.e. the files are set to size 0. Links to files are replaced with place-holders.
Information about the original file is written to logfile
.
Arguments¶
files : list List of glob expressions of files to clean up. logfile : string Filename of logfile.
Source code in cgatcore/pipeline/control.py
clone_pipeline(srcdir, destdir=None)
¶
clone a pipeline.
Cloning entails creating a mirror of the source pipeline. Generally, data files are mirrored by linking. Configuration files and the pipeline database will be copied.
Without modification of any files, building the cloned pipeline in
destdir
should not re-run any commands. However, on deleting
selected files, the pipeline should run from the appropriate
point. Newly created files will not affect the original pipeline.
Cloning pipelines permits sharing partial results between pipelines, for example for parameter optimization.
Arguments¶
scrdir : string Source directory destdir : string Destination directory. If None, use the current directory.
Source code in cgatcore/pipeline/control.py
close_session()
¶
cluster_runnable(func)
¶
A dectorator that allows a function to be run on the cluster.
The decorated function now takes extra arguments. The most important is submit. If set to true, it will submit the function to the cluster via the pipeline.submit framework. Arguments to the function are pickled, so this will only work if arguments are picklable. Other arguments to submit are also accepted.
Note that this allows the unusal combination of submit false, and to_cluster true. This will submit the function as an external job, but run it on the local machine.
Note: all arguments in the decorated function must be passed as key-word arguments.
Source code in cgatcore/pipeline/execution.py
concatenate_and_load(infiles, outfile, regex_filename=None, header=None, cat='track', has_titles=True, missing_value='na', retry=True, tablename=None, options='', job_memory=None, to_cluster=True)
¶
concatenate multiple tab-separated files and upload into database.
The table name is given by outfile without the ".load" suffix.
A typical concatenate and load task in ruffus would look like this::
@merge("*.tsv.gz", ".load")
def loadData(infile, outfile):
P.concatenateAndLoad(infiles, outfile)
Upload is performed via the :doc:csv2db
script.
Arguments¶
infiles : list
Filenames of the input data
outfile : string
Output filename. This will contain the logging information. The
table name is derived from outfile
.
regex_filename : string
If given, regex_filename is applied to the filename to extract
the track name. If the pattern contains multiple groups, they are
added as additional columns. For example, if cat
is set to
track,method
and regex_filename
is (.*)_(.*).tsv.gz
it will add the columns track
and method to the table.
header : string
Comma-separated list of values for header.
cat : string
Column title for column containing the track name. The track name
is derived from the filename, see regex_filename
.
has_titles : bool
If True, files are expected to have column titles in their first row.
missing_value : string
String to use for missing values.
retry : bool
If True, multiple attempts will be made if the data can
not be loaded at the first try, for example if a table is locked.
tablename: string
Name to use for table. If unset derive from outfile.
options : string
Command line options for the csv2db.py
script.
job_memory : string
Amount of memory to allocate for job. If unset, uses the global
default. Implies to_cluster=True.
to_cluster : bool
By default load jobs are not submitted to the cluster as they sometimes
become blocked. Setting this true will override this behavoir.
Source code in cgatcore/pipeline/database.py
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 |
|
config_to_dictionary(config)
¶
convert the contents of a :py:class:ConfigParser.ConfigParser
object to a dictionary
This method works by iterating over all configuration values in a
:py:class:ConfigParser.ConfigParser
object and inserting values
into a dictionary. Section names are prefixed using and underscore.
Thus::
[sample]
name=12
is entered as sample_name=12
into the dictionary. The sections
general
and DEFAULT
are treated specially in that both
the prefixed and the unprefixed values are inserted: ::
[general] genome=hg19
will be added as general_genome=hg19
and genome=hg19
.
Numbers will be automatically recognized as such and converted into integers or floats.
Returns¶
config : dict A dictionary of configuration values
Source code in cgatcore/pipeline/parameters.py
connect()
¶
connect to SQLite database used in this pipeline.
.. note:: This method is currently only implemented for sqlite databases. It needs refactoring for generic access. Alternatively, use an full or partial ORM.
If annotations_database
is in params, this method
will attach the named database as annotations
.
Returns¶
dbh a database handle
Source code in cgatcore/pipeline/database.py
create_view(dbhandle, tables, tablename, outfile, view_type='TABLE', ignore_duplicates=True)
¶
create a database view for a list of tables.
This method performs a join across multiple tables and stores the result either as a view or a table in the database.
Arguments¶
dbhandle : A database handle. tables : list of tuples Tables to merge. Each tuple contains the name of a table and the field to join with the first table. For example::
tables = (
"reads_summary", "track",
"bam_stats", "track",
"context_stats", "track",
"picard_stats_alignment_summary_metrics", "track")
string
Name of the view or table to be created.
outfile : string
Output filename for status information.
view_type : string
Type of view, either VIEW
or TABLE
. If a view is to be
created across multiple databases, use TABLE
.
ignore_duplicates : bool
If set to False, duplicate column names will be added with the
tablename as prefix. The default is to ignore.
Source code in cgatcore/pipeline/database.py
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 |
|
execute(statement, **kwargs)
¶
execute a statement locally.
This method implements the same parameter interpolation
as the function :func:run
.
Arguments¶
statement : string Command line statement to run.
Returns¶
stdout : string Data sent to standard output by command stderr : string Data sent to standard error by command
Source code in cgatcore/pipeline/execution.py
file_is_mounted(filename)
¶
return True if filename is mounted.
A file is likely to be mounted if it is located inside a subdirectory of the local scratch directory.
Source code in cgatcore/pipeline/execution.py
get_caller(decorators=0)
¶
return the name of the calling class/module
Arguments¶
decorators : int Number of contexts to go up to reach calling function of interest.
Returns¶
mod : object The calling module/class
Source code in cgatcore/pipeline/utils.py
get_caller_locals(decorators=0)
¶
returns the locals of the calling function.
from http://pylab.blogspot.com/2009/02/ python-accessing-caller-locals-from.html
Arguments¶
decorators : int Number of contexts to go up to reach calling function of interest.
Returns¶
locals : dict Dictionary of variable defined in the context of the calling function.
Source code in cgatcore/pipeline/utils.py
get_calling_function(decorators=0)
¶
get_database_name()
¶
Return the database name associated with the pipeline.
This method lookis in different sections in the ini file to permit
both old style database
and new style database_name
.
This method has been implemented for backwards compatibility.
Returns¶
databasename : string database name. Returns empty string if not found.
Raises¶
KeyError If no database name is found
Source code in cgatcore/pipeline/database.py
get_executor(options=None)
¶
Return an executor instance based on the specified queue manager in options.
- options (dict): Dictionary containing execution options, including "cluster_queue_manager".
Returns: - Executor instance appropriate for the specified queue manager.
Source code in cgatcore/pipeline/execution.py
get_header()
¶
return a header string with command line options and timestamp
Source code in cgatcore/experiment.py
get_mounted_location(filename)
¶
get_param_output(options=None)
¶
return a string containing script parameters.
Parameters are all variables that start with param_
.
Source code in cgatcore/pipeline/control.py
get_param_section(section)
¶
return config values in section
Sections are built by common prefixes.
Source code in cgatcore/pipeline/parameters.py
get_parameters(filenames=None, defaults=None, site_ini=True, user=True, only_import=None)
¶
read one or more config files and build global PARAMS configuration dictionary.
Arguments¶
filenames : list
List of filenames of the configuration files to read.
defaults : dict
Dictionary with default values. These will be overwrite
any hard-coded parameters, but will be overwritten by user
specified parameters in the configuration files.
user : bool
If set, configuration files will also be read from a
file called :file:.cgat.yml
in the users
home directory.
only_import : bool
If set to a boolean, the parameter dictionary will be a
defaultcollection. This is useful for pipelines that are
imported (for example for documentation generation) but not
executed as there might not be an appropriate .yml file
available. If
only_import` is None, it will be set to the
default, which is to raise an exception unless the calling
script is imported or the option --is-test
has been passed
at the command line.
Returns¶
params : dict Global configuration dictionary.
Source code in cgatcore/pipeline/parameters.py
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 |
|
get_parameters_as_namedtuple(*args, **kwargs)
¶
return PARAM dictionary as a namedtuple.
get_params()
¶
get_s3_pipeline()
¶
Instantiate and return the S3Pipeline instance, lazy-loaded to avoid circular imports.
Source code in cgatcore/pipeline/__init__.py
get_temp_dir(dir=None, shared=False, clear=False)
¶
get a temporary directory.
The directory is created and the caller needs to delete the temporary directory once it is not used any more.
If dir does not exist, it will be created.
Arguments¶
dir : string Directory of the temporary directory and if not given is set to the default temporary location in the global configuration dictionary. shared : bool If set, the tempory directory will be in a shared temporary location.
Returns¶
filename : string Absolute pathname of temporary file.
Source code in cgatcore/pipeline/files.py
get_temp_file(dir=None, shared=False, suffix='', mode='w+', encoding='utf-8')
¶
get a temporary file.
The file is created and the caller needs to close and delete the
temporary file once it is not used any more. By default, the file
is opened as a text file (mode w+
) with encoding utf-8
instead of the default mode w+b
used in
:class:tempfile.NamedTemporaryFile
If dir does not exist, it will be created.
Arguments¶
dir : string Directory of the temporary file and if not given is set to the default temporary location in the global configuration dictionary. shared : bool If set, the tempory file will be in a shared temporary location (given by the global configuration directory). suffix : string Filename suffix
Returns¶
file : File A file object of the temporary file.
Source code in cgatcore/pipeline/files.py
get_temp_filename(dir=None, shared=False, clear=True, suffix='')
¶
return a temporary filename.
The file is created and the caller needs to delete the temporary
file once it is not used any more (unless clear
is set`).
If dir does not exist, it will be created.
Arguments¶
dir : string Directory of the temporary file and if not given is set to the default temporary location in the global configuration dictionary. shared : bool If set, the tempory file will be in a shared temporary location. clear : bool If set, remove the temporary file after creation. suffix : string Filename suffix
Returns¶
filename : string Absolute pathname of temporary file.
Source code in cgatcore/pipeline/files.py
initialize(argv=None, caller=None, defaults=None, optparse=True, **kwargs)
¶
setup the pipeline framework.
Arguments¶
options: object Container for command line arguments. args : list List of command line arguments. defaults : dictionary Dictionary with default values to be added to global parameters dictionary.
Additional keyword arguments will be passed to the
:func:~.parse_commandline
function to set command-line defaults.
Source code in cgatcore/pipeline/control.py
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 |
|
input_validation(PARAMS, pipeline_script='')
¶
Inspects the PARAMS dictionary looking for problematic input values.
So far we just check that:
* all required 3rd party tools are on the PATH
* input parameters are not empty
* input parameters do not contain the "?" character (used as a
placeholder in different pipelines)
* if the input is a file, check whether it exists and
is readable
Source code in cgatcore/pipeline/parameters.py
interpolate_statement(statement, kwargs)
¶
interpolate command line statement with parameters
The skeleton of the statement should be defined in kwargs. The
method then applies string interpolation using a dictionary built
from the global configuration dictionary PARAMS, but augmented by
kwargs
. The latter takes precedence.
Arguments¶
statement: string Command line statement to be interpolated. kwargs : dict Keyword arguments that are used for parameter interpolation.
Returns¶
statement : string The command line statement with interpolated parameters.
Raises¶
KeyError
If statement
contains unresolved references.
Source code in cgatcore/pipeline/execution.py
is_test()
¶
return True if the pipeline is run in a "testing" mode.
This method checks if -is-test
has been given as a
command line option.
is_true(param, **kwargs)
¶
return True if param has a True value.
A parameter is False if it is:
- not set
- 0
- the empty string
- false or False
Otherwise the value is True.
Arguments¶
param : string
Parameter to be tested
kwargs : dict
Dictionary of local configuration values. These will be passed
to :func:substitute_parameters
before evaluating param
Returns¶
bool
Source code in cgatcore/pipeline/parameters.py
join_statements(statements, infile, outfile=None)
¶
join a chain of statements into a single statement.
Each statement contains an @IN@ or a @OUT@ placeholder or both. These will be replaced by the names of successive temporary files.
In the first statement, @IN@ is replaced with infile
and, if given,
the @OUT@ is replaced by outfile in the last statement.
Arguments¶
statements : list A list of command line statements. infile : string Filename of the first data set. outfile : string Filename of the target data set.
Returns¶
last_file : string Filename of last file created, outfile, if given. statement : string A command line statement built from merging the statements cleanup : string A command line statement for cleaning up.
Source code in cgatcore/pipeline/execution.py
load(infile, outfile=None, options='', collapse=False, transpose=False, tablename=None, retry=True, limit=0, shuffle=False, job_memory=None, to_cluster=False)
¶
import data from a tab-separated file into database.
The table name is given by outfile without the ".load" suffix.
A typical load task in ruffus would look like this::
@transform("*.tsv.gz", suffix(".tsv.gz"), ".load")
def loadData(infile, outfile):
P.load(infile, outfile)
Upload is performed via the :doc:csv2db
script.
Arguments¶
infile : string
Filename of the input data
outfile : string
Output filename. This will contain the logging information. The
table name is derived from outfile
if tablename
is not set.
options : string
Command line options for the csv2db.py
script.
collapse : string
If set, the table will be collapsed before loading. This
transforms a data set with two columns where the first column
is the row name into a multi-column table. The value of
collapse is the value used for missing values.
transpose : string
If set, the table will be transposed before loading. The first
column in the first row will be set to the string within
transpose.
retry : bool
If True, multiple attempts will be made if the data can
not be loaded at the first try, for example if a table is locked.
limit : int
If set, only load the first n lines.
shuffle : bool
If set, randomize lines before loading. Together with limit
this permits loading a sample of rows.
job_memory : string
Amount of memory to allocate for job. If unset, uses the global
default. Implies to_cluster=True.
to_cluster : bool
By default load jobs are not submitted to the cluster as they sometimes
become blocked. Setting this true will override this behavoir.
Source code in cgatcore/pipeline/database.py
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 |
|
load_from_iterator(outfile, tablename, iterator, columns=None, indices=None)
¶
import data from an iterator into a database.
Arguments¶
outfile : string Output file name tablename : string Table name iterator : iterator Iterator to import data from. The iterator should yield either list/tuples or dictionaries for each row in the table. columns : list Column names. If not given, the assumption is that iterator will dictionaries and column names are derived from that. indices : list List of column names to add indices on.
Source code in cgatcore/pipeline/database.py
main(argv=None)
¶
command line control function for a pipeline.
This method defines command line options for the pipeline and updates the global configuration dictionary correspondingly.
It then provides a command parser to execute particular tasks using the ruffus pipeline control functions. See the generated command line help for usage.
To use it, add::
import CGAT.pipeline as P
if __name__ == "__main__":
sys.exit(P.main(sys.argv))
to your pipeline script.
Arguments¶
args : list List of command line arguments.
Source code in cgatcore/pipeline/control.py
match_parameter(param)
¶
find an exact match or prefix-match in the global configuration dictionary param.
Arguments¶
param : string Parameter to search for.
Returns¶
name : string The full parameter name.
Raises¶
KeyError if param can't be matched.
Source code in cgatcore/pipeline/parameters.py
merge_and_load(infiles, outfile, suffix=None, columns=(0, 1), regex=None, row_wise=True, retry=True, options='', prefixes=None)
¶
merge multiple categorical tables and load into a database.
The tables are merged and entered row-wise, i.e, the contents of each file are a row.
For example, the statement::
mergeAndLoad(['file1.txt', 'file2.txt'],
"test_table.load")
with the two files:: > cat file1.txt Category Result length 12 width 100
> cat file2.txt
Category Result
length 20
width 50
will be added into table test_table
as::
track length width
file1 12 100
file2 20 50
If row-wise is set:: mergeAndLoad(['file1.txt', 'file2.txt'], "test_table.load", row_wise=True)
test_table
will be transposed and look like this::
track file1 file2
length 12 20
width 20 50
Arguments¶
infiles : list
Filenames of the input data
outfile : string
Output filename. This will contain the logging information. The
table name is derived from outfile
.
suffix : string
If suffix
is given, the suffix will be removed from the filenames.
columns : list
The columns to be taken. By default, the first two columns are
taken with the first being the key. Filenames are stored in a
track
column. Directory names are chopped off. If
columns
is set to None, all columns will be taken. Here,
column names will receive a prefix given by prefixes
. If
prefixes
is None, the filename will be added as a prefix.
regex : string
If set, the full filename will be used to extract a
track name via the supplied regular expression.
row_wise : bool
If set to False, each table will be a column in the resulting
table. This is useful if histograms are being merged.
retry : bool
If True, multiple attempts will be made if the data can
not be loaded at the first try, for example if a table is locked.
options : string
Command line options for the csv2db.py
script.
prefixes : list
If given, the respective prefix will be added to each
column. The number of prefixes
and infiles
needs to be the
same.
Source code in cgatcore/pipeline/database.py
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 |
|
nested_update(old, new)
¶
Update potentially nested dictionaries. If both old[x] and new[x] inherit from collections.abc.Mapping, then update old[x] with entries from new[x], otherwise set old[x] to new[x]
Source code in cgatcore/pipeline/parameters.py
parse_commandline(argv=None, optparse=True, **kwargs)
¶
parse command line.
Create option parser and parse command line.
Arguments¶
argv : list List of command line options to parse. If None, use sys.argv.
**kwargs: dict Additional arguments overwrite default option settings.
Source code in cgatcore/pipeline/control.py
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 |
|
peek_parameters(workingdir, pipeline, on_error_raise=None, prefix=None, update_interface=False, restrict_interface=False)
¶
peek configuration parameters from external pipeline.
As the paramater dictionary is built at runtime, this method executes the pipeline in workingdir, dumping its configuration values and reading them into a dictionary.
If either pipeline
or workingdir
are not found, an error is
raised. This behaviour can be changed by setting on_error_raise
to False. In that case, an empty dictionary is returned.
Arguments¶
workingdir : string
Working directory. This is the directory that the pipeline
was executed in.
pipeline : string
Name of the pipeline script. The pipeline is assumed to live
in the same directory as the current pipeline.
on_error_raise : Bool
If set to a boolean, an error will be raised (or not) if there
is an error during parameter peeking, for example if
workingdir
can not be found. If on_error_raise
is None, it
will be set to the default, which is to raise an exception
unless the calling script is imported or the option
--is-test
has been passed at the command line.
prefix : string
Add a prefix to all parameters. This is useful if the paramaters
are added to the configuration dictionary of the calling pipeline.
update_interface : bool
If True, this method will prefix any options in the
[interface]
section with workingdir
. This allows
transparent access to files in the external pipeline.
restrict_interface : bool
If True, only interface parameters will be imported.
Returns¶
config : dict Dictionary of configuration values.
Source code in cgatcore/pipeline/control.py
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 |
|
print_config_files()
¶
Print the list of .ini files used to configure the pipeline along with their associated priorities. Priority 1 is the highest.
Source code in cgatcore/pipeline/control.py
run(statement, **kwargs)
¶
run a command line statement.
This function runs a single or multiple statements either locally or on the cluster using drmaa. How a statement is executed or how it is modified depends on the context.
The context is provided by keyword arguments provided as named function arguments ('kwargs') but also from defaults (see below). The following keyword arguments are recognized:
job_memory memory to use for the job per thread. Memory specification should be in a format that is accepted by the job scheduler. Note that memory is per thread. If you have 6 threads and the total memory is 6Gb, use 1G as job_memory. job_total_memory total memory to use for a job. This will be divided by the number of threads. job_threads number of threads to request for the job. job_options options to the job scheduler. job_condaenv conda environment to use for the job. job_array if set, run statement as an array job. Job_array should be tuple with start, end, and increment.
In addition, any additional variables will be used to interpolate the command line string using python's '%' string interpolation operator.
The context is build in a hierarchical manner with successive operations overwriting previous values.
- Global variables The context is initialized with system-wide defaults stored in the global PARAMS singleton.
- Context of caller The context of the calling function is examined and any local variables defined in this context are added.
- kwargs Any options given explicitely as options to the run() method are added.
- params If the context of the calling function contains a params variable, its contents are added to the context. This permits setting variables in configuration files in TaskLibrary functions.
By default, a job is sent to the cluster, unless:
* ``to_cluster`` is present and set to None.
* ``without_cluster`` is True.
* ``--local`` has been specified on the command line
and the option ``without_cluster`` has been set as
a result.
* no libdrmaa is present
* the global session is not initialized (GLOBAL_SESSION is
None)
Troubleshooting:
-
DRMAA creates sessions and their is a limited number of sessions available. If there are two many or sessions become not available after failed jobs, use
qconf -secl
to list sessions andqconf -kec #
to delete sessions. -
Memory: 1G of free memory can be requested using the job_memory variable:
job_memory = "1G"
If there are error messages like "no available queue", then the problem could be that a particular complex attribute has not been defined (the code should behc
forhost:complex
and nothl
forhost:local
. Note that qrsh/qsub directly still works.
The job will be executed within PARAMS["work_dir"], unless PARAMS["work_dir"] is not local. In that case, the job will be executed in a shared temporary directory.
Arguments¶
statement : string or list of strings A command line statement or a list of command line statements to be executed. kwargs : dictionary Context for job. The context is used to interpolate the command line statement.
Source code in cgatcore/pipeline/execution.py
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
|
run_pickled(params)
¶
run a function whose arguments have been pickled.
expects that params is [module_name, function_name, arguments_file]
Source code in cgatcore/pipeline/execution.py
shellquote(statement)
¶
shell quote a string to be used as a function argument.
from http://stackoverflow.com/questions/967443/ python-module-to-shellquote-unshellquote
Source code in cgatcore/pipeline/execution.py
snip(filename, extension=None, alt_extension=None, strip_path=False)
¶
return prefix of filename
, that is the part without the
extension.
If extension
is given, make sure that filename has the
extension (or alt_extension
). Both extension or alt_extension
can be list of extensions.
If strip_path
is set to true, the path is stripped from the file
name.
Source code in cgatcore/iotools.py
start_session()
¶
start and initialize the global DRMAA session.
Source code in cgatcore/pipeline/execution.py
submit(module, function, args=None, infiles=None, outfiles=None, to_cluster=True, logfile=None, job_options='', job_threads=1, job_memory=False)
¶
submit a python function as a job to the cluster.
This method runs the script :file:run_function
using the
:func:run
method in this module thus providing the same
control options as for command line tools.
Arguments¶
module : string
Module name that contains the function. If module
is
not part of the PYTHONPATH, an absolute path can be given.
function : string
Name of function to execute
infiles : string or list
Filenames of input data
outfiles : string or list
Filenames of output data
logfile : filename
Logfile to provide to the --log
option
job_options : string
String for generic job options for the queuing system
job_threads : int
Number of slots (threads/cores/CPU) to use for the task
job_memory : string
Amount of memory to reserve for the job.
Source code in cgatcore/pipeline/execution.py
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 |
|
substitute_parameters(**kwargs)
¶
return a parameter dictionary.
This method builds a dictionary of parameter values to apply for a specific task. The dictionary is built in the following order:
- take values from the global dictionary (:py:data:
PARAMS
) - substitute values appearing in
kwargs
. - Apply task specific configuration values by looking for the
presence of
outfile
in kwargs.
The substition of task specific values works by looking for any
parameter values starting with the value of outfile
. The
suffix of the parameter value will then be substituted.
For example::
PARAMS = {"tophat_threads": 4,
"tophat_cutoff": 0.5,
"sample1.bam.gz_tophat_threads" : 6}
outfile = "sample1.bam.gz"
print(substitute_parameters(**locals()))
{"tophat_cutoff": 0.5, "tophat_threads": 6}
Returns¶
params : dict Dictionary with parameter values.
Source code in cgatcore/pipeline/parameters.py
tablequote(track)
¶
to_table(outfile)
¶
convert a filename from a load statement into a table name.
This method checks if the filename ends with ".load". The suffix is then removed and the filename quoted so that it is suitable as a table name.
Arguments¶
outfile : string A filename ending in ".load".
Returns¶
tablename : string
Source code in cgatcore/pipeline/database.py
touch_file(filename, mode=438, times=None, dir_fd=None, ref=None, **kwargs)
¶
update/create a sentinel file.
modified from: https://stackoverflow.com/questions/1158076/implement-touch-using-python
Compressed files (ending in .gz) are created as empty 'gzip' files, i.e., with a header.
Source code in cgatcore/iotools.py
update_params_with_commandline_options(params, args)
¶
add and update selected parameters in the parameter dictionary with command line args.
Source code in cgatcore/pipeline/control.py
write_config_files(pipeline_path, general_path)
¶
create default configuration files in path
.