├── READ_ME.txt ├── NatureProtocols_step7.txt ├── NatureProtocols_step2.txt ├── NatureProtocols_step4.txt ├── NatureProtocols_step3-1.txt ├── NatureProtocols_step5.txt ├── NatureProtocols_step8.txt ├── NatureProtocols_step6.txt ├── NatureProtocols_step3-2.txt ├── NatureProtocols_step1.txt ├── sameBrainAlignment.py ├── normalisation_comparison.py ├── exportTiffStack.py ├── internalAlignment.py ├── edgeDetection.py ├── atlasAlignment.py ├── convertTiffFiles.py ├── median_brainOnly.py ├── fileMerging.py ├── file_merging.cpp ├── help.txt ├── edge_detection_Prewitt.cpp └── gpl-3.0.txt /READ_ME.txt: -------------------------------------------------------------------------------- 1 | The code in this directory is released under the GNU GPL v3 license. 2 | Please see gpl-3.0.txt for details. 3 | 4 | It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 5 | 6 | We have tried to make the pipeline as user-friendly as possible and in most cases, you should only need to edit the parameter files before the analysis can be used on your dataset. 7 | For more details, please see refer to the attached user manual (help.txt). 8 | 9 | For more information on the overall CUBIC method, please see the Nature Protocols article for which this code was released: . 10 | 11 | When using the CUBIC method, please remember to cite the relevant papers. 12 | 13 | 14 | -------------------------------------------------------------------------------- /NatureProtocols_step7.txt: -------------------------------------------------------------------------------- 1 | ################################################# 2 | ## Parameters for step 7 of the CUBIC Analysis ## 3 | ################################################# 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the NIfTI files 16 | /Users/perrin2/Desktop/CUBIC/nii_merged/ 17 | # 18 | # 19 | # 20 | ########## 21 | # Brains # 22 | ########## 23 | # 24 | # List of brain IDs 25 | 001,002,003 26 | # 27 | # Internal reference brain 28 | 003 29 | # 30 | # Median intensity for each brain 31 | 6064.06,5803.39,6640.76 32 | # 33 | # Control brain 34 | 003 35 | # 36 | # Positive brain 37 | 002 38 | # 39 | # 40 | # 41 | ############ 42 | # Log file # 43 | ############ 44 | # 45 | # Name of the log file (including full path) 46 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step7.txt 47 | # 48 | # 49 | # 50 | ######### 51 | ## END ## 52 | ######### -------------------------------------------------------------------------------- /NatureProtocols_step2.txt: -------------------------------------------------------------------------------- 1 | ################################################# 2 | ## Parameters for step 2 of the CUBIC Analysis ## 3 | ################################################# 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the NIfTI files 16 | /Users/perrin2/Desktop/CUBIC/nii_individual/ 17 | # 18 | # Folder containing the registration files 19 | /Users/perrin2/Desktop/CUBIC/registration/ 20 | # 21 | # 22 | # 23 | ########## 24 | # Brains # 25 | ########## 26 | # 27 | # List of brain IDs 28 | 001,002,003 29 | # 30 | # 31 | # 32 | ################ 33 | # Registration # 34 | ################ 35 | # 36 | # Registration method ("affine" for affine-only, "SyN" for Symmetric Normalisation) 37 | affine 38 | # 39 | # 40 | # 41 | ############ 42 | # Log file # 43 | ############ 44 | # 45 | # Name of the output file (including full path) 46 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step2.txt 47 | # 48 | # 49 | # 50 | ######### 51 | ## END ## 52 | ######### -------------------------------------------------------------------------------- /NatureProtocols_step4.txt: -------------------------------------------------------------------------------- 1 | ################################################# 2 | ## Parameters for step 4 of the CUBIC Analysis ## 3 | ################################################# 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the NIfTI files 16 | /Users/perrin2/Desktop/CUBIC/nii_merged/ 17 | # 18 | # Folder containing the registration files 19 | /Users/perrin2/Desktop/CUBIC/registration/ 20 | # 21 | # 22 | # 23 | ########## 24 | # Brains # 25 | ########## 26 | # 27 | # List of brain IDs 28 | 001,002,003 29 | # 30 | # Internal reference brain for the registration 31 | 003 32 | # 33 | # 34 | # 35 | ################ 36 | # Registration # 37 | ################ 38 | # 39 | # Registration method ("affine" for affine-only, "SyN" for Symmetric Normalisation) 40 | affine 41 | # 42 | # 43 | # 44 | ############ 45 | # Log file # 46 | ############ 47 | # 48 | # Name of the log file (including full path) 49 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step4.txt 50 | # 51 | # 52 | # 53 | ######### 54 | ## END ## 55 | ######### -------------------------------------------------------------------------------- /NatureProtocols_step3-1.txt: -------------------------------------------------------------------------------- 1 | ################################################### 2 | ## Parameters for step 3-1 of the CUBIC Analysis ## 3 | ################################################### 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the NIfTI files 16 | /Users/perrin2/Desktop/CUBIC/nii_individual/ 17 | # 18 | # Folder containing the ASCII files 19 | /Users/perrin2/Desktop/CUBIC/ascii/ 20 | # 21 | # 22 | # 23 | ########## 24 | # Brains # 25 | ########## 26 | # 27 | # List of brain IDs 28 | 001,002,003 29 | # 30 | # Number of sagittal slices 31 | 640 32 | # 33 | # Number of coronal slices 34 | 540 35 | # 36 | # Number of horizontal slices for each of these brains 37 | 169,157,169 38 | # 39 | # 40 | # 41 | ############ 42 | # Log file # 43 | ############ 44 | # 45 | # Name of the log file (including full path) 46 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step3-1.txt 47 | # 48 | # Name of the results file (including full path) 49 | /Users/perrin2/Desktop/CUBIC/logs/results_NatureProtocols_step3-1.txt 50 | # 51 | # 52 | # 53 | ######### 54 | ## END ## 55 | ######### -------------------------------------------------------------------------------- /NatureProtocols_step5.txt: -------------------------------------------------------------------------------- 1 | ################################################# 2 | ## Parameters for step 5 of the CUBIC Analysis ## 3 | ################################################# 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the NIfTI files 16 | /Users/perrin2/Desktop/CUBIC/nii_merged/ 17 | # 18 | # Folder containing the registration files 19 | /Users/perrin2/Desktop/CUBIC/registration/ 20 | # 21 | # 22 | # 23 | ########## 24 | # Brains # 25 | ########## 26 | # 27 | # List of brain IDs 28 | 001,002,003 29 | # 30 | # Internal reference brain 31 | 003 32 | # 33 | # Brain atlas (including full path) 34 | /Users/perrin2/Dropbox/Code_for_macubic_computer/atlas/atlas_rescaled.nii 35 | # 36 | # 37 | # 38 | ################ 39 | # Registration # 40 | ################ 41 | # 42 | # Registration method ("affine" or "SyN"). It should be the same as in step 4. 43 | affine 44 | # 45 | # 46 | # 47 | ############ 48 | # Log file # 49 | ############ 50 | # 51 | # Name of the log file (including full path) 52 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step5.txt 53 | # 54 | # 55 | # 56 | ######### 57 | ## END ## 58 | ######### -------------------------------------------------------------------------------- /NatureProtocols_step8.txt: -------------------------------------------------------------------------------- 1 | ################################################# 2 | ## Parameters for step 8 of the CUBIC Analysis ## 3 | ################################################# 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the raw TIFF files 16 | /Users/perrin2/Desktop/CUBIC/raw/ 17 | # 18 | # Folder containing the NIfTI-1 files 19 | /Users/perrin2/Desktop/CUBIC/nii_merged/ 20 | # 21 | # Folder containing the normalised TIFF files 22 | /Users/perrin2/Desktop/CUBIC/tiff/ 23 | # 24 | # 25 | # 26 | ########## 27 | # Brains # 28 | ########## 29 | # 30 | # List of brain IDs (for raw TIFF stack normalisation) 31 | 001,002,003 32 | # 33 | # Median intensity for each brain 34 | 6064.06,5803.39,6640.76 35 | # 36 | # List of brain IDs (for NIfTI-1 to TIFF export) 37 | sub_003_from_002_normalised 38 | # 39 | # Number of slices for these brains to export (should be same value for all) 40 | 169 41 | # 42 | # 43 | ############ 44 | # Log file # 45 | ############ 46 | # 47 | # Name of the log file (including full path) 48 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step8.txt 49 | # 50 | # 51 | # 52 | ######### 53 | ## END ## 54 | ######### -------------------------------------------------------------------------------- /NatureProtocols_step6.txt: -------------------------------------------------------------------------------- 1 | ################################################# 2 | ## Parameters for step 6 of the CUBIC Analysis ## 3 | ################################################# 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the NIfTI files 16 | /Users/perrin2/Desktop/CUBIC/nii_merged/ 17 | # 18 | # Folder containing the registration files 19 | /Users/perrin2/Desktop/CUBIC/registration/ 20 | # 21 | # Folder containing the analysis results 22 | /Users/perrin2/Desktop/CUBIC/analysis/ 23 | # 24 | # 25 | # 26 | ########## 27 | # Brains # 28 | ########## 29 | # 30 | # List of brain IDs 31 | 001,002,003 32 | # 33 | # Internal reference brain 34 | 003 35 | # 36 | # Brain atlas (including full path) 37 | /Users/perrin2/Dropbox/Code_for_macubic_computer/atlas/atlas_rescaled.nii 38 | # 39 | # 40 | # 41 | ################ 42 | # Registration # 43 | ################ 44 | # 45 | # Registration method used in steps 4 and 5 ("affine" or "SyN") 46 | affine 47 | # 48 | # 49 | # 50 | ############ 51 | # Log file # 52 | ############ 53 | # 54 | # Name of the log file (including full path) 55 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step6.txt 56 | # 57 | # 58 | # 59 | ######### 60 | ## END ## 61 | ######### -------------------------------------------------------------------------------- /NatureProtocols_step3-2.txt: -------------------------------------------------------------------------------- 1 | ################################################### 2 | ## Parameters for step 3-2 of the CUBIC Analysis ## 3 | ################################################### 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the NIfTI files 16 | /Users/perrin2/Desktop/CUBIC/nii_individual/ 17 | # 18 | # Folder containing the registration files 19 | /Users/perrin2/Desktop/CUBIC/ascii/ 20 | # 21 | # Folder containing the merged files 22 | /Users/perrin2/Desktop/CUBIC/nii_merged/ 23 | # 24 | # Folder containing the registration files 25 | /Users/perrin2/Desktop/CUBIC/registration/ 26 | # 27 | # 28 | # 29 | ########## 30 | # Brains # 31 | ########## 32 | # 33 | # List of brain IDs 34 | 001,002,003 35 | # 36 | # Number of sagittal slices 37 | 640 38 | # 39 | # Number of coronal slices 40 | 540 41 | # 42 | # Number of horizontal slices for each of these brains 43 | 169,157,169 44 | # 45 | # 46 | # 47 | ########### 48 | # Merging # 49 | ########### 50 | # 51 | # n values (staining) 52 | 88,78,83 53 | # 54 | # m values (staining) 55 | 91,82,87 56 | # 57 | # n values (fluorescent signal) 58 | 90,79,68 59 | # 60 | # m values (fluorescent signal) 61 | 101,86,92 62 | # 63 | # 64 | # 65 | ############ 66 | # Log file # 67 | ############ 68 | # 69 | # Name of the log file (including full path) 70 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step3-2.txt 71 | # 72 | # 73 | # 74 | ######### 75 | ## END ## 76 | ######### -------------------------------------------------------------------------------- /NatureProtocols_step1.txt: -------------------------------------------------------------------------------- 1 | ################################################# 2 | ## Parameters for step 1 of the CUBIC Analysis ## 3 | ################################################# 4 | # 5 | # 6 | # Note: to avoid any problem, please do not 7 | # change the file structure, only the 8 | # parameter values 9 | # 10 | # 11 | ########### 12 | # Folders # 13 | ########### 14 | # 15 | # Folder containing the raw files 16 | /Users/perrin2/Desktop/CUBIC/raw/ 17 | # 18 | # Folder that will contain the NIfTI files 19 | /Users/perrin2/Desktop/CUBIC/nii_individual/ 20 | # 21 | # Folder for temporary files 22 | /Users/perrin2/Desktop/CUBIC/temp/ 23 | # 24 | # 25 | # 26 | ########## 27 | # Images # 28 | ########## 29 | # 30 | # Resolution of the TIFF images (XY direction, in mm) 31 | 0.00645 32 | # 33 | # Step in the Z direction (in mm) 34 | 0.01 35 | # 36 | # 37 | # 38 | ########### 39 | # Scaling # 40 | ########### 41 | # 42 | # Scaling factor (XY direction) 43 | 0.25 44 | # 45 | # Step factor (Z direction) 46 | 4 47 | # 48 | # 49 | # 50 | ######### 51 | # Files # 52 | ######### 53 | # 54 | # Position (in filename) that contains information about acquisition direction 55 | 21,23 56 | # 57 | # Position (in filename) that contains information about brain ID 58 | 9,12 59 | # 60 | # Position (in filename) that contains information about signal type 61 | 13,20 62 | # 63 | # 64 | # 65 | ############ 66 | # Log file # 67 | ############ 68 | # 69 | # Name of the output file (including full path) 70 | /Users/perrin2/Desktop/CUBIC/logs/log_NatureProtocols_step1.txt 71 | # 72 | # 73 | # 74 | ######### 75 | ## END ## 76 | ######### -------------------------------------------------------------------------------- /sameBrainAlignment.py: -------------------------------------------------------------------------------- 1 | # sameBrainAlignment.py | Aligns two 3D images of the same brain acquired 2 | # from opposite directions. 3 | # Please see the user manual for details. 4 | # 5 | # Copyright (C) 2015, Dimitri Perrin 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | 21 | import os 22 | import glob 23 | from time import localtime, strftime 24 | from subprocess import call 25 | import sys 26 | 27 | 28 | if len(sys.argv)!=2: 29 | print "\nUsage: "+sys.argv[0]+" " 30 | quit() 31 | 32 | 33 | 34 | # Reading the parameters 35 | 36 | parameter_file = open(sys.argv[1],'r') 37 | parameters = [] 38 | for line in parameter_file: 39 | if line[0] == "#": 40 | continue 41 | parameters.append(line.rstrip()) 42 | parameter_file.close() 43 | 44 | 45 | 46 | # Processing the parameters 47 | 48 | nii_dir = parameters[0] 49 | reg_dir = parameters[1] 50 | 51 | brains = parameters[2].split(",") 52 | 53 | reg_method = parameters[3] 54 | 55 | log = parameters[4] 56 | 57 | 58 | 59 | # Checking the parameters 60 | 61 | print "The method will: " 62 | print " - read from, and save to "+nii_dir 63 | print " - save registration data to "+reg_dir 64 | print " - save the log data to "+log 65 | 66 | print "\nBrains to be processed: " 67 | print brains 68 | 69 | print "\nRegistration method: " 70 | print reg_method 71 | 72 | print " " 73 | while 1: 74 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 75 | if feedback == "yes": 76 | print "Program starting...\n" 77 | break 78 | if feedback == "no": 79 | print "Please edit the parameter file." 80 | quit() 81 | 82 | 83 | 84 | 85 | # Running the analysis step 86 | 87 | reg_param = "" 88 | if reg_method == "affine": 89 | reg_param = "-i 0" 90 | elif reg_method == "SyN": 91 | reg_param = "-i 10x10x10" 92 | else: 93 | print "Unrecognised registration method." 94 | quit() 95 | 96 | 97 | log_file = open(log,'w') 98 | 99 | 100 | for br in brains: 101 | 102 | DV_stain = nii_dir+"DV_"+br+"_nuclear.nii.gz" 103 | DV_fluo = nii_dir+"DV_"+br+"_geneExp.nii.gz" 104 | VD_stain = nii_dir+"VD_"+br+"_nuclear.nii.gz" 105 | 106 | DV_stain_aligned = nii_dir+"DV_"+br+"_nuclear_aligned_VD.nii.gz" 107 | DV_fluo_aligned = nii_dir+"DV_"+br+"_geneExp_aligned_VD.nii.gz" 108 | 109 | reg = reg_dir+"internal_reg_"+br+"_.nii" 110 | log = reg_dir+"log_"+br+".txt" 111 | 112 | output_message = strftime("%H:%M:%S", localtime())+": Registering "+br 113 | print output_message 114 | log_file.write(output_message+"\n") 115 | 116 | cmd = "ANTS 3 "+reg_param+" -o "+reg+" --MI-option 64x30000 -m CC["+VD_stain+","+DV_stain+",1,5] >> "+log 117 | call([cmd],shell=True) 118 | 119 | output_message = strftime("%H:%M:%S", localtime())+": Aligning both nuclear staining and fluorescent signal files." 120 | print output_message 121 | log_file.write(output_message+"\n") 122 | 123 | if reg_method == "affine": 124 | cmd = "WarpImageMultiTransform 3 "+DV_stain+" "+DV_stain_aligned+" -R "+VD_stain+" "+reg[:-4]+"Affine.txt" 125 | call([cmd],shell=True) 126 | cmd = "WarpImageMultiTransform 3 "+DV_fluo+" "+DV_fluo_aligned+" -R "+VD_stain+" "+reg[:-4]+"Affine.txt" 127 | call([cmd],shell=True) 128 | 129 | if reg_method == "SyN": 130 | cmd = "WarpImageMultiTransform 3 "+DV_stain+" "+DV_stain_aligned+" -R "+VD_stain+" "+reg[:-4]+"Warp.nii "+reg[:-4]+"Affine.txt" 131 | call([cmd],shell=True) 132 | cmd = "WarpImageMultiTransform 3 "+DV_fluo+" "+DV_fluo_aligned+" -R "+VD_stain+" "+reg[:-4]+"Warp.nii "+reg[:-4]+"Affine.txt" 133 | call([cmd],shell=True) 134 | 135 | 136 | output_message = strftime("%H:%M:%S", localtime())+": Done." 137 | print output_message 138 | log_file.write(output_message+"\n") 139 | 140 | log_file.close() 141 | -------------------------------------------------------------------------------- /normalisation_comparison.py: -------------------------------------------------------------------------------- 1 | # normalisation_comparison | "Normalises" a number of 3D brain images 2 | # by applying factors based on the median signal intensity calculated at 3 | # the previous step. 4 | # an internal reference) to a brain atlas. 5 | # Please see the user manual for details. 6 | # 7 | # Copyright (C) 2015, Dimitri Perrin 8 | # 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | 23 | from time import localtime, strftime 24 | from subprocess import call 25 | import ast 26 | import sys 27 | 28 | 29 | if len(sys.argv)!=2: 30 | print "\nUsage: "+sys.argv[0]+" " 31 | quit() 32 | 33 | 34 | 35 | # Reading the parameters 36 | 37 | parameter_file = open(sys.argv[1],'r') 38 | parameters = [] 39 | for line in parameter_file: 40 | if line[0] == "#": 41 | continue 42 | parameters.append(line.rstrip()) 43 | parameter_file.close() 44 | 45 | 46 | 47 | # Processing the parameters 48 | 49 | merged_dir = parameters[0] 50 | 51 | brains = parameters[1].split(",") 52 | internal_ref = parameters[2] 53 | 54 | temp = parameters[3].split(",") 55 | median = dict() 56 | for i in range(0,len(brains)): 57 | median[brains[i]] = ast.literal_eval(temp[i]) 58 | 59 | neg_brain = parameters[4] 60 | pos_brain = parameters[5] 61 | 62 | log = parameters[6] 63 | 64 | 65 | # Checking the parameters 66 | 67 | print "The method will: " 68 | print " - read/write NIfTI-1 from/to "+merged_dir 69 | 70 | print "\nBrains to be processed: " 71 | print brains 72 | 73 | print "\nInternal reference brain: " 74 | print internal_ref 75 | 76 | print "\nMedian intensity: " 77 | print median 78 | 79 | print "\nNegative (control) brain: " 80 | print neg_brain 81 | 82 | print "\nPositive brain: " 83 | print pos_brain 84 | 85 | 86 | print " " 87 | while 1: 88 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 89 | if feedback == "yes": 90 | print "Program starting...\n" 91 | break 92 | if feedback == "no": 93 | print "Please edit the parameter file." 94 | quit() 95 | 96 | 97 | 98 | 99 | # Running the analysis step 100 | 101 | 102 | log_file = open(log,'w') 103 | 104 | 105 | 106 | # calculating the highest value 107 | highestMedian = 0 108 | for el in median: 109 | val = median[el] 110 | if val > highestMedian: 111 | highestMedian = val 112 | 113 | 114 | # Normalisation 115 | 116 | output_message = strftime("%H:%M:%S", localtime())+": Normalising." 117 | print output_message 118 | log_file.write(output_message+"\n") 119 | 120 | 121 | for i in range(0,len(brains)): 122 | 123 | normalisationFactor = highestMedian/median[brains[i]] 124 | 125 | raw = merged_dir+brains[i]+"_geneExp_aligned_"+internal_ref+".nii.gz" 126 | normd = merged_dir+brains[i]+"_geneExp_aligned_"+internal_ref+"_normalised.nii.gz" 127 | if brains[i]==internal_ref: 128 | raw = merged_dir+brains[i]+"_geneExp.nii.gz" 129 | normd = merged_dir+brains[i]+"_geneExp_normalised.nii.gz" 130 | 131 | cmd = "fslmaths "+raw+" -mul "+str(normalisationFactor)+" "+normd 132 | call([cmd],shell=True) 133 | 134 | 135 | 136 | # Difference between two brains 137 | 138 | output_message = strftime("%H:%M:%S", localtime())+": Subtracting brains." 139 | print output_message 140 | log_file.write(output_message+"\n") 141 | 142 | neg = merged_dir+neg_brain+"_geneExp_aligned_"+internal_ref+"_normalised.nii.gz" 143 | if neg_brain == internal_ref: 144 | neg = merged_dir+neg_brain+"_geneExp_normalised.nii.gz" 145 | 146 | pos = merged_dir+pos_brain+"_geneExp_aligned_"+internal_ref+"_normalised.nii.gz" 147 | if pos_brain == internal_ref: 148 | pos = merged_dir+pos_brain+"_geneExp_normalised.nii.gz" 149 | 150 | diff = merged_dir+"sub_"+neg_brain+"_from_"+pos_brain+"_normalised.nii.gz" 151 | cmd = "fslmaths "+pos+" -sub "+neg+" "+diff 152 | call([cmd],shell=True) 153 | 154 | 155 | output_message = strftime("%H:%M:%S", localtime())+": Done." 156 | print output_message 157 | log_file.write(output_message+"\n") 158 | 159 | log_file.close() 160 | -------------------------------------------------------------------------------- /exportTiffStack.py: -------------------------------------------------------------------------------- 1 | # exportTiffStack.py | Gives two examples of further operations: 2 | # - one set of raw TIFF stacks is normalised using the same factors as in 3 | # the NIfTI-1 file normalisation 4 | # - one set of NIfTI-1 files is exported to TIFF stacks 5 | # Please see the user manual for details. 6 | # 7 | # Copyright (C) 2015, Dimitri Perrin 8 | # 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | 23 | from time import localtime, strftime 24 | from subprocess import call 25 | import ast 26 | import glob 27 | import ast 28 | import sys 29 | 30 | 31 | if len(sys.argv)!=2: 32 | print "\nUsage: "+sys.argv[0]+" " 33 | quit() 34 | 35 | 36 | 37 | # Reading the parameters 38 | 39 | parameter_file = open(sys.argv[1],'r') 40 | parameters = [] 41 | for line in parameter_file: 42 | if line[0] == "#": 43 | continue 44 | parameters.append(line.rstrip()) 45 | parameter_file.close() 46 | 47 | 48 | 49 | # Processing the parameters 50 | 51 | raw_dir = parameters[0] 52 | nii_dir = parameters[1] 53 | out_dir = parameters[2] 54 | 55 | brains_norm = parameters[3].split(",") 56 | 57 | temp = parameters[4].split(",") 58 | median = dict() 59 | for i in range(0,len(brains_norm)): 60 | median[brains_norm[i]] = ast.literal_eval(temp[i]) 61 | 62 | brains_conv = parameters[5].split(",") 63 | 64 | nb_slices = ast.literal_eval(parameters[6]) 65 | 66 | log = parameters[7] 67 | 68 | 69 | # Checking the parameters 70 | 71 | print "The method will: " 72 | print " - read raw files from "+raw_dir 73 | print " - write normalised files to "+out_dir 74 | 75 | print "\nBrains to be normalise: " 76 | print brains_norm 77 | 78 | print "\nMedian intensity: " 79 | print median 80 | 81 | print "\nBrains to be export: " 82 | print brains_conv 83 | 84 | 85 | 86 | print " " 87 | while 1: 88 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 89 | if feedback == "yes": 90 | print "Program starting...\n" 91 | break 92 | if feedback == "no": 93 | print "Please edit the parameter file." 94 | quit() 95 | 96 | 97 | 98 | 99 | # Running the analysis step 100 | 101 | 102 | log_file = open(log,'w') 103 | 104 | 105 | 106 | #################################### 107 | #################################### 108 | ## ## 109 | ## Normalising the raw (DV) TIFF ## 110 | ## stacks for the signal channel ## 111 | ## ## 112 | #################################### 113 | #################################### 114 | 115 | 116 | # calculating the highest value 117 | highestMedian = 0 118 | for el in median: 119 | val = median[el] 120 | if val > highestMedian: 121 | highestMedian = val 122 | 123 | 124 | for j in range(0,len(brains_norm)): 125 | 126 | normalisationFactor = highestMedian/median[brains_norm[j]] 127 | 128 | output_message = strftime("%H:%M:%S", localtime())+": Exporting results for brain "+brains_norm[j] 129 | print output_message 130 | log_file.write(output_message+"\n") 131 | 132 | name_stem = raw_dir+"*"+brains_norm[j]+"_geneExp_DV" 133 | dir_name = glob.glob(name_stem)[0]+"/" 134 | 135 | nb_images = len(glob.glob(dir_name+"*.tif")) 136 | for i in range(0,nb_images): 137 | img = dir_name+"*Z%04d*.ome.tif" % (i) 138 | cmd = "convert "+img+" -evaluate multiply "+str(normalisationFactor)+" "+out_dir+brains_norm[j]+"_geneExp_%04d.tif" % (i) 139 | call([cmd],shell=True) 140 | 141 | 142 | 143 | 144 | 145 | ################################## 146 | ################################## 147 | ## ## 148 | ## Exporting files from ## 149 | ## from NIfTI-1 to TIFF stack ## 150 | ## ## 151 | ################################## 152 | ################################## 153 | 154 | for b in brains_conv: 155 | output_message = strftime("%H:%M:%S", localtime())+": Exporting from NIfTI-1 to TIFF for brain "+b 156 | print output_message 157 | log_file.write(output_message+"\n") 158 | 159 | for sl in range(0,nb_slices): 160 | b_out = b+"_%03d.tif" % (sl) 161 | cmd = "c3d "+nii_dir+b+".nii.gz -slice z "+str(sl)+" -o "+out_dir+b_out 162 | call([cmd],shell=True) 163 | 164 | output_message = strftime("%H:%M:%S", localtime())+": Done." 165 | print output_message 166 | log_file.write(output_message+"\n") 167 | 168 | 169 | log_file.close() 170 | -------------------------------------------------------------------------------- /internalAlignment.py: -------------------------------------------------------------------------------- 1 | # internalAlignment.py | Aligns individual brain samples to an internal 2 | # reference brain chosen by the user. 3 | # Please see the user manual for details. 4 | # 5 | # Copyright (C) 2015, Dimitri Perrin 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | 21 | import glob 22 | from time import localtime, strftime 23 | from subprocess import call 24 | import sys 25 | 26 | 27 | if len(sys.argv)!=2: 28 | print "\nUsage: "+sys.argv[0]+" " 29 | quit() 30 | 31 | 32 | 33 | # Reading the parameters 34 | 35 | parameter_file = open(sys.argv[1],'r') 36 | parameters = [] 37 | for line in parameter_file: 38 | if line[0] == "#": 39 | continue 40 | parameters.append(line.rstrip()) 41 | parameter_file.close() 42 | 43 | 44 | 45 | # Processing the parameters 46 | 47 | nii_dir = parameters[0] 48 | reg_dir = parameters[1] 49 | 50 | brains = parameters[2].split(",") 51 | internal_ref = parameters[3] 52 | 53 | reg_method = parameters[4] 54 | 55 | log = parameters[5] 56 | 57 | 58 | 59 | # Checking the parameters 60 | 61 | print "The method will: " 62 | print " - read NIfTI-1 from "+nii_dir 63 | print " - save registration data to "+reg_dir 64 | 65 | print "\nBrains to be processed: " 66 | print brains 67 | 68 | print "\nInternal reference brain: " 69 | print internal_ref 70 | 71 | print "\nRegistration method: " 72 | print reg_method 73 | 74 | 75 | print " " 76 | while 1: 77 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 78 | if feedback == "yes": 79 | print "Program starting...\n" 80 | break 81 | if feedback == "no": 82 | print "Please edit the parameter file." 83 | quit() 84 | 85 | 86 | 87 | 88 | # Running the analysis step 89 | 90 | 91 | reg_param = "" 92 | if reg_method == "affine": 93 | reg_param = "-i 0" 94 | elif reg_method == "SyN": 95 | reg_param = "-i 10x10x10" 96 | else: 97 | print "Unrecognised registration method." 98 | quit() 99 | 100 | 101 | log_file = open(log,'w') 102 | 103 | 104 | ref_stain = nii_dir+internal_ref+"_nuclear.nii.gz" 105 | 106 | for i in range(0,len(brains)): 107 | output_message = strftime("%H:%M:%S", localtime())+": Starting to process brain "+brains[i] 108 | print output_message 109 | log_file.write(output_message+"\n") 110 | 111 | 112 | if internal_ref == brains[i]: 113 | output_message = "\t\t(internal reference brain, skipped)" 114 | print output_message 115 | log_file.write(output_message+"\n") 116 | continue 117 | 118 | current_stain = nii_dir+brains[i]+"_nuclear.nii.gz" 119 | current_fluo = nii_dir+brains[i]+"_geneExp.nii.gz" 120 | aligned_stain = nii_dir+brains[i]+"_nuclear_aligned_"+internal_ref+".nii.gz" 121 | aligned_fluo = nii_dir+brains[i]+"_geneExp_aligned_"+internal_ref+".nii.gz" 122 | 123 | # Registration 124 | 125 | output_message = strftime("%H:%M:%S", localtime())+": Registration" 126 | print output_message 127 | log_file.write(output_message+"\n") 128 | 129 | reg = reg_dir+"merged_reg_"+brains[i]+"_to_"+internal_ref+"_.nii" 130 | log = reg_dir+"log_"+brains[i]+"_to_"+internal_ref+"_.txt" 131 | 132 | cmd = "ANTS 3 "+reg_param+" -o "+reg+" --MI-option 64x300000 -m CC["+ref_stain+","+current_stain+",1,5] >> "+log 133 | 134 | call([cmd],shell=True) 135 | 136 | 137 | # Alignement 138 | 139 | output_message = strftime("%H:%M:%S", localtime())+": Alignment" 140 | print output_message 141 | log_file.write(output_message+"\n") 142 | 143 | if reg_method == "affine": 144 | cmd = "WarpImageMultiTransform 3 "+current_stain+" "+aligned_stain+" -R "+ref_stain+" "+reg[:-4]+"Affine.txt" 145 | call([cmd],shell=True) 146 | cmd = "WarpImageMultiTransform 3 "+current_fluo+" "+aligned_fluo+" -R "+ref_stain+" "+reg[:-4]+"Affine.txt" 147 | call([cmd],shell=True) 148 | 149 | if reg_method == "SyN": 150 | cmd = "WarpImageMultiTransform 3 "+current_stain+" "+aligned_stain+" -R "+ref_stain+" "+reg[:-4]+"Warp.nii "+reg[:-4]+"Affine.txt" 151 | call([cmd],shell=True) 152 | cmd = "WarpImageMultiTransform 3 "+current_fluo+" "+aligned_fluo+" -R "+ref_stain+" "+reg[:-4]+"Warp.nii "+reg[:-4]+"Affine.txt" 153 | call([cmd],shell=True) 154 | 155 | 156 | output_message = strftime("%H:%M:%S", localtime())+": Done." 157 | print output_message 158 | log_file.write(output_message+"\n") 159 | -------------------------------------------------------------------------------- /edgeDetection.py: -------------------------------------------------------------------------------- 1 | # edgeDetection.py | Measures the "edge content" of horizontal slices of 2 | # two 3D images of same brain acquired from opposite directions. 3 | # Please see the user manual for details. 4 | # 5 | # Copyright (C) 2015, Dimitri Perrin 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | 21 | from time import localtime, strftime 22 | from subprocess import call 23 | import ast 24 | import sys 25 | 26 | 27 | if len(sys.argv)!=2: 28 | print "\nUsage: "+sys.argv[0]+" " 29 | quit() 30 | 31 | 32 | 33 | # Reading the parameters 34 | 35 | parameter_file = open(sys.argv[1],'r') 36 | parameters = [] 37 | for line in parameter_file: 38 | if line[0] == "#": 39 | continue 40 | parameters.append(line.rstrip()) 41 | parameter_file.close() 42 | 43 | 44 | 45 | # Processing the parameters 46 | 47 | nii_dir = parameters[0] 48 | ascii_dir = parameters[1] 49 | 50 | brains = parameters[2].split(",") 51 | 52 | sag_size = ast.literal_eval(parameters[3]) 53 | cor_size = ast.literal_eval(parameters[4]) 54 | 55 | hor_size = [] 56 | temp = parameters[5].split(",") 57 | for i in range(0,len(temp)): 58 | hor_size.append(ast.literal_eval(temp[i])) 59 | 60 | log = parameters[6] 61 | results_file = parameters[7] 62 | 63 | 64 | 65 | # Checking the parameters 66 | 67 | print "The method will: " 68 | print " - read from "+nii_dir 69 | print " - save ASCII files to "+ascii_dir 70 | print " - save the log data to "+log 71 | 72 | print "\nBrains to be processed: " 73 | print brains 74 | 75 | print "\nBrain size: " 76 | print "- sagittal: "+str(sag_size) 77 | print "- coronal: "+str(cor_size) 78 | print "- horizontal: "+str(hor_size) 79 | 80 | 81 | print " " 82 | while 1: 83 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 84 | if feedback == "yes": 85 | print "Program starting...\n" 86 | break 87 | if feedback == "no": 88 | print "Please edit the parameter file." 89 | quit() 90 | 91 | 92 | 93 | 94 | # Running the analysis step 95 | 96 | 97 | log_file = open(log,'w') 98 | 99 | 100 | 101 | 102 | for i in range(0,len(brains)): 103 | br = brains[i] 104 | output_message = strftime("%H:%M:%S", localtime())+": Starting to process brain "+br 105 | print output_message 106 | log_file.write(output_message+"\n") 107 | 108 | DV_stain = nii_dir+"DV_"+br+"_nuclear_aligned_VD.nii.gz" 109 | VD_stain = nii_dir+"VD_"+br+"_nuclear.nii.gz" 110 | DV_fluo = nii_dir+"DV_"+br+"_geneExp_aligned_VD.nii.gz" 111 | VD_fluo = nii_dir+"VD_"+br+"_geneExp.nii.gz" 112 | 113 | ascii_DV_stain = ascii_dir+"DV_"+br+"_nuclear.txt" 114 | ascii_VD_stain = ascii_dir+"VD_"+br+"_nuclear.txt" 115 | ascii_DV_fluo = ascii_dir+"DV_"+br+"_geneExp.txt" 116 | ascii_VD_fluo = ascii_dir+"VD_"+br+"_geneExp.txt" 117 | 118 | 119 | # Converting from NIfTI-1 to ASCII 120 | 121 | output_message = strftime("%H:%M:%S", localtime())+": Converting to ASCII" 122 | print output_message 123 | log_file.write(output_message+"\n") 124 | 125 | cmd = "fsl2ascii "+DV_stain+" "+ascii_DV_stain 126 | call([cmd],shell=True) 127 | cmd = "mv "+ascii_DV_stain+"00000 "+ascii_DV_stain 128 | call([cmd],shell=True) 129 | 130 | cmd = "fsl2ascii "+VD_stain+" "+ascii_VD_stain 131 | call([cmd],shell=True) 132 | cmd = "mv "+ascii_VD_stain+"00000 "+ascii_VD_stain 133 | call([cmd],shell=True) 134 | 135 | cmd = "fsl2ascii "+DV_fluo+" "+ascii_DV_fluo 136 | call([cmd],shell=True) 137 | cmd = "mv "+ascii_DV_fluo+"00000 "+ascii_DV_fluo 138 | call([cmd],shell=True) 139 | 140 | cmd = "fsl2ascii "+VD_fluo+" "+ascii_VD_fluo 141 | call([cmd],shell=True) 142 | cmd = "mv "+ascii_VD_fluo+"00000 "+ascii_VD_fluo 143 | call([cmd],shell=True) 144 | 145 | 146 | # Prewitt-based C-implemented edge detection 147 | 148 | output_message = strftime("%H:%M:%S", localtime())+": Edge detection - nuclear" 149 | print output_message 150 | log_file.write(output_message+"\n") 151 | 152 | cmd = "./edge_detection_Prewitt "+str(hor_size[i])+" "+str(sag_size)+" "+str(cor_size)+" "+ascii_DV_stain+" "+ascii_VD_stain+" >> "+results_file 153 | call([cmd],shell=True) 154 | 155 | 156 | # Prewitt-based C-implemented edge detection 157 | 158 | output_message = strftime("%H:%M:%S", localtime())+": Edge detection - geneExp" 159 | print output_message 160 | log_file.write(output_message+"\n") 161 | 162 | cmd = "./edge_detection_Prewitt "+str(hor_size[i])+" "+str(sag_size)+" "+str(cor_size)+" "+ascii_DV_fluo+" "+ascii_VD_fluo+" >> "+results_file 163 | call([cmd],shell=True) 164 | 165 | 166 | 167 | output_message = strftime("%H:%M:%S", localtime())+": Done." 168 | print output_message 169 | log_file.write(output_message+"\n") 170 | 171 | log_file.close() 172 | -------------------------------------------------------------------------------- /atlasAlignment.py: -------------------------------------------------------------------------------- 1 | # atlasAlignment.py | Aligns individual brain samples (already aligned to 2 | # an internal reference) to a brain atlas. 3 | # Please see the user manual for details. 4 | # 5 | # Copyright (C) 2015, Dimitri Perrin 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | 21 | import glob 22 | from time import localtime, strftime 23 | from subprocess import call 24 | import sys 25 | 26 | 27 | if len(sys.argv)!=2: 28 | print "\nUsage: "+sys.argv[0]+" " 29 | quit() 30 | 31 | 32 | 33 | # Reading the parameters 34 | 35 | parameter_file = open(sys.argv[1],'r') 36 | parameters = [] 37 | for line in parameter_file: 38 | if line[0] == "#": 39 | continue 40 | parameters.append(line.rstrip()) 41 | parameter_file.close() 42 | 43 | 44 | 45 | # Processing the parameters 46 | 47 | nii_dir = parameters[0] 48 | reg_dir = parameters[1] 49 | 50 | brains = parameters[2].split(",") 51 | internal_ref = parameters[3] 52 | atlas = parameters[4] 53 | 54 | reg_method = parameters[5] 55 | 56 | log = parameters[6] 57 | 58 | 59 | 60 | # Checking the parameters 61 | 62 | print "The method will: " 63 | print " - read NIfTI-1 from "+nii_dir 64 | print " - save registration data to "+reg_dir 65 | 66 | print "\nBrains to be processed: " 67 | print brains 68 | 69 | print "\nInternal reference brain: " 70 | print internal_ref 71 | 72 | print "\nRegistration method: " 73 | print reg_method 74 | 75 | 76 | print " " 77 | while 1: 78 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 79 | if feedback == "yes": 80 | print "Program starting...\n" 81 | break 82 | if feedback == "no": 83 | print "Please edit the parameter file." 84 | quit() 85 | 86 | 87 | 88 | 89 | # Running the analysis step 90 | 91 | 92 | reg_param = "" 93 | if reg_method == "affine": 94 | reg_param = "-i 0" 95 | elif reg_method == "SyN": 96 | reg_param = "-i 10x10x10" 97 | else: 98 | print "Unrecognised registration method." 99 | quit() 100 | 101 | log_file = open(log,'w') 102 | 103 | 104 | # Registration of the internal reference to the atlas 105 | 106 | output_message = strftime("%H:%M:%S", localtime())+": Registration of brain "+internal_ref 107 | print output_message 108 | log_file.write(output_message+"\n") 109 | 110 | ref_stain = nii_dir+internal_ref+"_nuclear.nii.gz" 111 | ref_fluo = nii_dir+internal_ref+"_geneExp.nii.gz" 112 | 113 | aligned_stain = nii_dir+internal_ref+"_nuclear_aligned_Atlas.nii.gz" 114 | aligned_fluo = nii_dir+internal_ref+"_geneExp_aligned_Atlas.nii.gz" 115 | 116 | reg = reg_dir+"merged_reg_"+internal_ref+"_to_Atlas_.nii" 117 | log = reg_dir+"log_"+internal_ref+"_to_Atlas.txt" 118 | 119 | cmd = "ANTS 3 "+reg_param+" -o "+reg+" --MI-option 64x300000 -m CC["+atlas+","+ref_stain+",1,5] >> "+log 120 | call([cmd],shell=True) 121 | 122 | 123 | # Alignment of the internal reference to the atlas 124 | 125 | output_message = strftime("%H:%M:%S", localtime())+": Alignment of brain "+internal_ref 126 | print output_message 127 | log_file.write(output_message+"\n") 128 | 129 | if reg_method == "affine": 130 | cmd = "WarpImageMultiTransform 3 "+ref_stain+" "+aligned_stain+" -R "+atlas+" "+reg[:-4]+"Affine.txt" 131 | call([cmd],shell=True) 132 | cmd = "WarpImageMultiTransform 3 "+ref_fluo+" "+aligned_fluo+" -R "+atlas+" "+reg[:-4]+"Affine.txt" 133 | call([cmd],shell=True) 134 | 135 | if reg_method == "SyN": 136 | cmd = "WarpImageMultiTransform 3 "+ref_stain+" "+aligned_stain+" -R "+atlas+" "+reg[:-4]+"Warp.nii "+reg[:-4]+"Affine.txt" 137 | call([cmd],shell=True) 138 | cmd = "WarpImageMultiTransform 3 "+ref_fluo+" "+aligned_fluo+" -R "+atlas+" "+reg[:-4]+"Warp.nii "+reg[:-4]+"Affine.txt" 139 | call([cmd],shell=True) 140 | 141 | 142 | # Alignment of all other samples 143 | 144 | for i in range(0,len(brains)): 145 | if internal_ref == brains[i]: 146 | continue 147 | 148 | output_message = strftime("%H:%M:%S", localtime())+": Alignment of brain "+brains[i] 149 | print output_message 150 | log_file.write(output_message+"\n") 151 | 152 | current_stain = nii_dir+brains[i]+"_nuclear_aligned_"+internal_ref+".nii.gz" 153 | current_fluo = nii_dir+brains[i]+"_geneExp_aligned_"+internal_ref+".nii.gz" 154 | 155 | aligned_stain = nii_dir+brains[i]+"_nuclear_aligned_"+internal_ref+"_aligned_Atlas.nii.gz" 156 | aligned_fluo = nii_dir+brains[i]+"_geneExp_aligned_"+internal_ref+"_aligned_Atlas.nii.gz" 157 | 158 | if reg_method == "affine": 159 | cmd = "WarpImageMultiTransform 3 "+current_stain+" "+aligned_stain+" -R "+atlas+" "+reg[:-4]+"Affine.txt" 160 | call([cmd],shell=True) 161 | cmd = "WarpImageMultiTransform 3 "+current_fluo+" "+aligned_fluo+" -R "+atlas+" "+reg[:-4]+"Affine.txt" 162 | call([cmd],shell=True) 163 | 164 | if reg_method == "SyN": 165 | cmd = "WarpImageMultiTransform 3 "+current_stain+" "+aligned_stain+" -R "+atlas+" "+reg[:-4]+"Warp.nii "+reg[:-4]+"Affine.txt" 166 | call([cmd],shell=True) 167 | cmd = "WarpImageMultiTransform 3 "+current_fluo+" "+aligned_fluo+" -R "+atlas+" "+reg[:-4]+"Warp.nii "+reg[:-4]+"Affine.txt" 168 | call([cmd],shell=True) 169 | 170 | 171 | output_message = strftime("%H:%M:%S", localtime())+": Done." 172 | print output_message 173 | log_file.write(output_message+"\n") 174 | 175 | log_file.close() 176 | -------------------------------------------------------------------------------- /convertTiffFiles.py: -------------------------------------------------------------------------------- 1 | # convertTiffFiles.py | Converts stacks of TIFF images to NIfTI-1 3D images. 2 | # Please see the user manual for details. 3 | # 4 | # Copyright (C) 2015, Dimitri Perrin 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | 20 | import os 21 | import glob 22 | from time import localtime, strftime 23 | from subprocess import call 24 | import ast 25 | import sys 26 | 27 | 28 | if len(sys.argv)!=2: 29 | print "\nUsage: "+sys.argv[0]+" " 30 | quit() 31 | 32 | 33 | 34 | # Reading the parameters 35 | 36 | parameter_file = open(sys.argv[1],'r') 37 | parameters = [] 38 | for line in parameter_file: 39 | if line[0] == "#": 40 | continue 41 | parameters.append(line.rstrip()) 42 | parameter_file.close() 43 | 44 | 45 | 46 | # Processing the parameters 47 | 48 | initial_dir = parameters[0] 49 | nii_dir = parameters[1] 50 | temp_dir = parameters[2] 51 | 52 | 53 | XY_resolution = ast.literal_eval(parameters[3]) 54 | Z_step = ast.literal_eval(parameters[4]) 55 | factor = ast.literal_eval(parameters[5]) 56 | step = ast.literal_eval(parameters[6]) 57 | 58 | scaling=str(factor*100)+"%" 59 | 60 | direction_start = ast.literal_eval(parameters[7].split(",")[0]) 61 | direction_end = ast.literal_eval(parameters[7].split(",")[1]) 62 | 63 | brainID_start = ast.literal_eval(parameters[8].split(",")[0]) 64 | brainID_end = ast.literal_eval(parameters[8].split(",")[1]) 65 | 66 | signal_start = ast.literal_eval(parameters[9].split(",")[0]) 67 | signal_end = ast.literal_eval(parameters[9].split(",")[1]) 68 | 69 | log = parameters[10] 70 | 71 | 72 | 73 | 74 | # Checking the parameters 75 | 76 | print "The method will: " 77 | print " - read data from "+initial_dir 78 | print " - save results to "+nii_dir 79 | print " - use "+temp_dir+" for temporary files" 80 | print " - save the log data to "+log 81 | 82 | print "\nThe raw image resolution is "+str(XY_resolution)+"mm in the XY direction, and "+str(Z_step)+"mm in the Z direction." 83 | print "The NIfTI files will be downscaled to "+scaling+" in the XY direction, and by a factor of "+str(step)+" in the Z direction." 84 | 85 | list_samples = glob.glob(initial_dir+"*") 86 | example = list_samples[0][len(initial_dir):] 87 | 88 | print "\nA typical file format is: "+example 89 | print "In that file: " 90 | print "- the acquisition direction is "+example[direction_start:direction_end] 91 | print "- the brain ID is "+example[brainID_start:brainID_end] 92 | print "- the signal is "+example[signal_start:signal_end] 93 | 94 | print " " 95 | while 1: 96 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 97 | if feedback == "yes": 98 | print "Program starting...\n" 99 | break 100 | if feedback == "no": 101 | print "Please edit the parameter file." 102 | quit() 103 | 104 | 105 | 106 | 107 | # Running the analysis step 108 | 109 | log_file = open(log,'w') 110 | 111 | for s in list_samples: 112 | sample_dir = s[len(initial_dir):] 113 | direction = sample_dir[direction_start:direction_end] 114 | brainID = sample_dir[brainID_start:brainID_end] 115 | nbSlices = len(glob.glob(initial_dir+sample_dir+"/*")) 116 | signal = sample_dir[signal_start:signal_end] 117 | 118 | name = direction+"_"+brainID+"_"+signal 119 | output_message = strftime("%H:%M:%S", localtime())+": Starting to process "+name 120 | print output_message 121 | log_file.write(output_message+"\n") 122 | 123 | 124 | if len(glob.glob(nii_dir+name+".nii.gz"))>0: 125 | output_message = strftime("%H:%M:%S", localtime())+": \tNIfTI-1 file already available. Moving on to next file." 126 | print output_message 127 | log_file.write(output_message+"\n") 128 | continue 129 | 130 | output_message = strftime("%H:%M:%S", localtime())+": \tStarting to convert Tiff files." 131 | print output_message 132 | log_file.write(output_message+"\n") 133 | 134 | # Convert (and rescale) original Tiff files 135 | for i in range(0,nbSlices,step): 136 | slice = "%04d" % (i) 137 | outfile = "%03d" % (i/step) 138 | file = initial_dir+sample_dir+"/*Z"+slice+"*.ome.tif" 139 | 140 | call(["convert",file,"-resize",scaling,"-depth","16",temp_dir+outfile+".tif"]) 141 | 142 | output_message = strftime("%H:%M:%S", localtime())+": \tDone." 143 | print output_message 144 | log_file.write(output_message+"\n") 145 | 146 | # Create 3D volume as NII file 147 | 148 | orient = " -orient RAI " 149 | if direction == "DV": 150 | orient = " -orient RAS " 151 | elif direction != "VD": 152 | output_message = "Error in direction detection?" 153 | print output_message 154 | log_file.write(output_message+"\n") 155 | 156 | quit() 157 | scale = " -spacing "+str(XY_resolution/factor)+"x"+str(XY_resolution/factor)+"x"+str(Z_step*step)+"mm " 158 | cmd = "c3d "+temp_dir+"*.tif -tile z "+orient+scale+" -o "+nii_dir+name+".nii.gz" 159 | 160 | output_message = strftime("%H:%M:%S", localtime())+": \tStarting construct the 3D volume." 161 | print output_message 162 | log_file.write(output_message+"\n") 163 | 164 | call([cmd],shell=True) 165 | output_message = strftime("%H:%M:%S", localtime())+": \tDone." 166 | print output_message 167 | log_file.write(output_message+"\n") 168 | 169 | # Remove the temporary files 170 | for tempFile in glob.glob(temp_dir+"*.tif"): 171 | os.remove(tempFile) 172 | 173 | 174 | log_file.close() 175 | 176 | quit() 177 | 178 | -------------------------------------------------------------------------------- /median_brainOnly.py: -------------------------------------------------------------------------------- 1 | # median_brainOnly | Calculates the median signal intensity for a series 2 | # of brain samples, only considering the signal inside the brain. 3 | # Please see the user manual for details. 4 | # 5 | # Copyright (C) 2015, Dimitri Perrin 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | 21 | import glob 22 | from time import localtime, strftime 23 | from subprocess import call 24 | import ast 25 | import numpy 26 | import sys 27 | 28 | 29 | if len(sys.argv)!=2: 30 | print "\nUsage: "+sys.argv[0]+" " 31 | quit() 32 | 33 | 34 | 35 | # Reading the parameters 36 | 37 | parameter_file = open(sys.argv[1],'r') 38 | parameters = [] 39 | for line in parameter_file: 40 | if line[0] == "#": 41 | continue 42 | parameters.append(line.rstrip()) 43 | parameter_file.close() 44 | 45 | 46 | 47 | # Processing the parameters 48 | 49 | nii_dir = parameters[0] 50 | reg_dir = parameters[1] 51 | ana_dir = parameters[2] 52 | 53 | brains = parameters[3].split(",") 54 | internal_ref = parameters[4] 55 | atlas = parameters[5] 56 | 57 | reg_method = parameters[6] 58 | 59 | log = parameters[7] 60 | 61 | 62 | # Checking the parameters 63 | 64 | print "The method will: " 65 | print " - read NIfTI-1 from "+nii_dir 66 | print " - load registration data to "+reg_dir 67 | print " - save ASCII data to "+ana_dir 68 | 69 | print "\nBrains to be processed: " 70 | print brains 71 | 72 | print "\nInternal reference brain: " 73 | print internal_ref 74 | 75 | print "\nRegistration method used in steps 4-5: " 76 | print reg_method 77 | 78 | 79 | 80 | print " " 81 | while 1: 82 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 83 | if feedback == "yes": 84 | print "Program starting...\n" 85 | break 86 | if feedback == "no": 87 | print "Please edit the parameter file." 88 | quit() 89 | 90 | 91 | 92 | 93 | # Running the analysis step 94 | 95 | 96 | log_file = open(log,'w') 97 | 98 | internal_reference = nii_dir+internal_ref+"_nuclear.nii.gz" 99 | 100 | warp = reg_dir+"merged_reg_"+internal_ref+"_to_Atlas_InverseWarp.nii" 101 | affine = reg_dir+"merged_reg_"+internal_ref+"_to_Atlas_Affine.txt" 102 | 103 | aligned_atlas =nii_dir+"atlas_aligned_to_"+internal_ref+".nii.gz" 104 | ascii_atlas = ana_dir+"atlas.txt" 105 | 106 | 107 | 108 | 109 | # (assumes the list is already sorted) 110 | def median(l): 111 | half = len(l) / 2 112 | if len(l) % 2 == 0: 113 | return (l[half-1] + l[half]) / 2.0 114 | else: 115 | return l[half] 116 | 117 | 118 | 119 | 120 | 121 | # Alignment of the atlas to the internal reference 122 | # Note: 123 | # - the internal reference has already been registered to the atlas 124 | # - because we use the reverse transformation, the order is affine-warp, instead of warp-affine, if using SyN 125 | 126 | if reg_method != "affine" and reg_method != "SyN": 127 | print "Unrecognised registration method." 128 | quit() 129 | 130 | output_message = strftime("%H:%M:%S", localtime())+": Atlas alignment.\n" 131 | print output_message 132 | log_file.write(output_message+"\n") 133 | 134 | if reg_method == "affine": 135 | cmd = "WarpImageMultiTransform 3 "+atlas+" "+aligned_atlas+" -R "+internal_reference+" -i "+affine 136 | call([cmd],shell=True) 137 | 138 | if reg_method == "SyN": 139 | cmd = "WarpImageMultiTransform 3 "+atlas+" "+aligned_atlas+" -R "+internal_reference+" -i "+affine+" "+warp 140 | call([cmd],shell=True) 141 | 142 | 143 | # Exporting aligned brain atlas to ASCII 144 | 145 | output_message = strftime("%H:%M:%S", localtime())+": Atlas export.\n" 146 | print output_message 147 | log_file.write(output_message+"\n") 148 | 149 | cmd = "fsl2ascii "+aligned_atlas+" "+ascii_atlas 150 | call([cmd],shell=True) 151 | cmd = "mv "+ascii_atlas+"00000 "+ascii_atlas 152 | call([cmd],shell=True) 153 | 154 | output_message = strftime("%H:%M:%S", localtime())+": Atlas loading." 155 | print output_message 156 | log_file.write(output_message+"\n") 157 | 158 | atlas_data = [] 159 | inFile = open(ascii_atlas,'r') 160 | for line in inFile: 161 | tempArray = line.rstrip().split(" ") 162 | if len(tempArray)>1: 163 | for val in tempArray: 164 | atlas_data.append(ast.literal_eval(val)) 165 | inFile.close() 166 | output_message = "\t\t"+str(len(atlas_data))+" pixels" 167 | print output_message 168 | log_file.write(output_message+"\n") 169 | 170 | 171 | # Processing each brain 172 | for i in range(0,len(brains)): 173 | 174 | output_message = "\n"+strftime("%H:%M:%S", localtime())+": Brain "+brains[i] 175 | print output_message 176 | log_file.write(output_message+"\n") 177 | 178 | filename = nii_dir+brains[i]+"_geneExp_aligned_"+internal_ref+".nii.gz" 179 | if brains[i]==internal_ref: 180 | filename = nii_dir+brains[i]+"_geneExp.nii.gz" 181 | ascii_brain = ana_dir+brains[i]+".txt" 182 | 183 | # Exporting to ASCII 184 | 185 | output_message = strftime("%H:%M:%S", localtime())+":\tExporting." 186 | print output_message 187 | log_file.write(output_message+"\n") 188 | 189 | cmd = "fsl2ascii "+filename+" "+ascii_brain 190 | call([cmd],shell=True) 191 | cmd = "mv "+ascii_brain+"00000 "+ascii_brain 192 | call([cmd],shell=True) 193 | 194 | 195 | # Loading 196 | 197 | output_message = strftime("%H:%M:%S", localtime())+":\tLoading." 198 | print output_message 199 | log_file.write(output_message+"\n") 200 | 201 | brain_data = [] 202 | inFile = open(ascii_brain,'r') 203 | for line in inFile: 204 | tempArray = line.rstrip().split(" ") 205 | if len(tempArray)>1: 206 | for val in tempArray: 207 | brain_data.append(ast.literal_eval(val)) 208 | inFile.close() 209 | output_message = "\t\t"+str(len(brain_data))+" pixels" 210 | print output_message 211 | log_file.write(output_message+"\n") 212 | 213 | 214 | # Filtering 215 | output_message = strftime("%H:%M:%S", localtime())+":\tFiltering." 216 | print output_message 217 | log_file.write(output_message+"\n") 218 | 219 | filtered_brain_data = [] 220 | for i in range(0,len(brain_data)): 221 | if atlas_data[i]>=1: 222 | filtered_brain_data.append(brain_data[i]) 223 | output_message = "\t\t"+str(len(filtered_brain_data))+" pixels" 224 | print output_message 225 | log_file.write(output_message+"\n") 226 | 227 | 228 | # Median 229 | output_message = strftime("%H:%M:%S", localtime())+":\tMedian: " 230 | print output_message 231 | log_file.write(output_message+"\n") 232 | 233 | filtered_brain_data.sort() 234 | med = median(filtered_brain_data) 235 | output_message = "\t\t"+str(med) 236 | print output_message 237 | log_file.write(output_message+"\n") 238 | 239 | 240 | 241 | output_message = "\n"+strftime("%H:%M:%S", localtime())+": Done." 242 | print output_message 243 | log_file.write(output_message+"\n") 244 | 245 | 246 | log_file.close() 247 | -------------------------------------------------------------------------------- /fileMerging.py: -------------------------------------------------------------------------------- 1 | # fileMerging.py | Merges two 3D images of same brain acquired from 2 | # opposite directions, based on threshold values obtained from the 3 | # "edge detection" step. 4 | # Please see the user manual for details. 5 | # 6 | # Copyright (C) 2015, Dimitri Perrin 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | 22 | from time import localtime, strftime 23 | from subprocess import call 24 | import ast 25 | import sys 26 | 27 | 28 | if len(sys.argv)!=2: 29 | print "\nUsage: "+sys.argv[0]+" " 30 | quit() 31 | 32 | 33 | 34 | # Reading the parameters 35 | 36 | parameter_file = open(sys.argv[1],'r') 37 | parameters = [] 38 | for line in parameter_file: 39 | if line[0] == "#": 40 | continue 41 | parameters.append(line.rstrip()) 42 | parameter_file.close() 43 | 44 | 45 | 46 | # Processing the parameters 47 | 48 | nii_dir = parameters[0] 49 | ascii_dir = parameters[1] 50 | merged_dir = parameters[2] 51 | reg_dir = parameters[3] 52 | 53 | 54 | brains = parameters[4].split(",") 55 | 56 | sag_size = ast.literal_eval(parameters[5]) 57 | cor_size = ast.literal_eval(parameters[6]) 58 | 59 | hor_size = [] 60 | temp = parameters[7].split(",") 61 | for i in range(0,len(temp)): 62 | hor_size.append(ast.literal_eval(temp[i])) 63 | 64 | n_stain = [] 65 | temp = parameters[8].split(",") 66 | for i in range(0,len(temp)): 67 | n_stain.append(ast.literal_eval(temp[i])) 68 | 69 | m_stain = [] 70 | temp = parameters[9].split(",") 71 | for i in range(0,len(temp)): 72 | m_stain.append(ast.literal_eval(temp[i])) 73 | 74 | n_fluo = [] 75 | temp = parameters[10].split(",") 76 | for i in range(0,len(temp)): 77 | n_fluo.append(ast.literal_eval(temp[i])) 78 | 79 | m_fluo = [] 80 | temp = parameters[11].split(",") 81 | for i in range(0,len(temp)): 82 | m_fluo.append(ast.literal_eval(temp[i])) 83 | 84 | log = parameters[12] 85 | 86 | 87 | 88 | # Checking the parameters 89 | 90 | print "The method will: " 91 | print " - read NIfTI-1 from "+nii_dir 92 | print " - read ASCII from "+ascii_dir 93 | print " - save registration data to "+reg_dir 94 | print " - save merged NIfTI-1 to "+merged_dir 95 | print " - save the log data to "+log 96 | 97 | print "\nBrains to be processed: " 98 | print brains 99 | 100 | 101 | 102 | print " " 103 | while 1: 104 | feedback = raw_input("Is this correct? (yes/no)\t").rstrip() 105 | if feedback == "yes": 106 | print "Program starting...\n" 107 | break 108 | if feedback == "no": 109 | print "Please edit the parameter file." 110 | quit() 111 | 112 | 113 | 114 | 115 | # Running the analysis step 116 | 117 | 118 | log_file = open(log,'w') 119 | 120 | 121 | 122 | for i in range(0,len(brains)): 123 | output_message = strftime("%H:%M:%S", localtime())+": Starting to process brain "+brains[i] 124 | print output_message 125 | log_file.write(output_message+"\n") 126 | 127 | DV_stain = nii_dir+"DV_"+brains[i]+"_nuclear_aligned_VD.nii.gz" 128 | VD_stain = nii_dir+"VD_"+brains[i]+"_nuclear.nii.gz" 129 | DV_fluo = nii_dir+"DV_"+brains[i]+"_geneExp_aligned_VD.nii.gz" 130 | VD_fluo = nii_dir+"VD_"+brains[i]+"_geneExp.nii.gz" 131 | 132 | ascii_DV_stain = ascii_dir+"DV_"+brains[i]+"_nuclear.txt" 133 | ascii_VD_stain = ascii_dir+"VD_"+brains[i]+"_nuclear.txt" 134 | ascii_DV_fluo = ascii_dir+"DV_"+brains[i]+"_geneExp.txt" 135 | ascii_VD_fluo = ascii_dir+"VD_"+brains[i]+"_geneExp.txt" 136 | 137 | ascii_merged_stain = ascii_dir+"merged_"+brains[i]+"_nuclear.txt" 138 | ascii_merged_fluo = ascii_dir+"merged_"+brains[i]+"_geneExp.txt" 139 | 140 | merged_stain = merged_dir+brains[i]+"_nuclear.nii.gz" 141 | merged_fluo = merged_dir+brains[i]+"_geneExp.nii.gz" 142 | 143 | temp_stain_1 = merged_dir+"temp_nuclear_1.nii.gz" 144 | temp_fluo_1 = merged_dir+"temp_geneExp_1.nii.gz" 145 | temp_stain_2 = merged_dir+"temp_nuclear_2.nii.gz" 146 | temp_fluo_2 = merged_dir+"temp_geneExp_2.nii.gz" 147 | 148 | 149 | # Edge-based C-implemented file merging 150 | 151 | output_message = strftime("%H:%M:%S", localtime())+": Merging ASCII files" 152 | print output_message 153 | log_file.write(output_message+"\n") 154 | 155 | cmd = "./file_merging "+str(hor_size[i])+" "+str(sag_size)+" "+str(cor_size)+" "+ascii_DV_stain+" "+ascii_VD_stain+" "+ascii_merged_stain+" "+str(n_stain[i])+" "+str(m_stain[i]) 156 | call([cmd],shell=True) 157 | 158 | cmd = "./file_merging "+str(hor_size[i])+" "+str(sag_size)+" "+str(cor_size)+" "+ascii_DV_fluo+" "+ascii_VD_fluo+" "+ascii_merged_fluo+" "+str(n_fluo[i])+" "+str(m_fluo[i]) 159 | call([cmd],shell=True) 160 | 161 | 162 | # Converting from ASCII to NIfTI-1 163 | 164 | output_message = strftime("%H:%M:%S", localtime())+": Converting merged file to NIfTI-1" 165 | print output_message 166 | log_file.write(output_message+"\n") 167 | 168 | cmd = "fslascii2img "+ascii_merged_stain+" "+str(sag_size)+" "+str(cor_size)+" "+str(hor_size[i])+" 1 0.0258 0.0258 0.04 1 "+temp_stain_1 169 | call([cmd],shell=True) 170 | 171 | cmd = "fslascii2img "+ascii_merged_fluo+" "+str(sag_size)+" "+str(cor_size)+" "+str(hor_size[i])+" 1 0.0258 0.0258 0.04 1 "+temp_fluo_1 172 | call([cmd],shell=True) 173 | 174 | 175 | # Re-orienting the merged NIfTI-1 file 176 | 177 | output_message = strftime("%H:%M:%S", localtime())+": Reorienting" 178 | print output_message 179 | log_file.write(output_message+"\n") 180 | 181 | cmd = "c3d "+temp_stain_1+" -orient RAI -o "+temp_stain_2+" && rm "+temp_stain_1 182 | call([cmd],shell=True) 183 | 184 | cmd = "c3d "+temp_fluo_1+" -orient RAI -o "+temp_fluo_2+" && rm "+temp_fluo_1 185 | call([cmd],shell=True) 186 | 187 | 188 | # Registration to original VD_stain 189 | 190 | output_message = strftime("%H:%M:%S", localtime())+": Registration" 191 | print output_message 192 | log_file.write(output_message+"\n") 193 | 194 | reg = reg_dir+"merged_reg_"+brains[i]+"_.nii" 195 | log = reg_dir+"log_merged_"+brains[i]+".txt" 196 | 197 | cmd = "ANTS 3 -i 0 -o "+reg+" --MI-option 64x300000 -m CC["+VD_stain+","+temp_stain_2+",1,5] >> "+log 198 | call([cmd],shell=True) 199 | 200 | 201 | # Alignment 202 | 203 | output_message = strftime("%H:%M:%S", localtime())+": Alignment" 204 | print output_message 205 | log_file.write(output_message+"\n") 206 | 207 | cmd = "WarpImageMultiTransform 3 "+temp_stain_2+" "+merged_stain+" -R "+VD_stain+" "+reg[:-4]+"Affine.txt" 208 | call([cmd],shell=True) 209 | cmd = "WarpImageMultiTransform 3 "+temp_fluo_2+" "+merged_fluo+" -R "+VD_stain+" "+reg[:-4]+"Affine.txt" 210 | call([cmd],shell=True) 211 | cmd = "rm "+temp_stain_2+" "+temp_fluo_2 212 | call([cmd],shell=True) 213 | 214 | 215 | output_message = strftime("%H:%M:%S", localtime())+": Done." 216 | print output_message 217 | log_file.write(output_message+"\n") 218 | 219 | log_file.close() 220 | -------------------------------------------------------------------------------- /file_merging.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 3 | file_merging.cpp | Merges two 3D brain images given as ASCII files based 4 | on the threshold values calculated during "edge detection". 5 | Called from fileMerging.py 6 | Please see the user manual for details. 7 | 8 | Copyright (C) 2015, Dimitri Perrin 9 | 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program. If not, see . 22 | 23 | ************************************************************************/ 24 | 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define BUFFER_SIZE 10000 34 | 35 | using namespace std; 36 | 37 | 38 | 39 | /**************************************/ 40 | /** printTimestamp() **/ 41 | /**************************************/ 42 | 43 | /* 44 | Prints a custom string with the current time and a given message 45 | Input: the message we want to include 46 | Output: none 47 | */ 48 | 49 | int printTimestamp(string infoString) { 50 | time_t rawtime; 51 | struct tm * timeinfo; 52 | char buffer1 [15]; 53 | 54 | time (&rawtime); 55 | timeinfo = localtime (&rawtime); 56 | strftime (buffer1,80,"%H:%M:%S ->\t",timeinfo); 57 | 58 | cout << buffer1 << infoString << endl; 59 | 60 | return 0; 61 | } 62 | 63 | 64 | 65 | 66 | /********************************/ 67 | /** factor_DV() **/ 68 | /********************************/ 69 | 70 | /* 71 | Calculates the weight for the DV image 72 | Input: position, size, n/m thresholds 73 | Output: weight 74 | */ 75 | 76 | double factor_DV(int position, int n, int m) { 77 | double weight; 78 | if(position<=n) { 79 | weight=0.0; 80 | } 81 | else { 82 | if(position>=m) { 83 | weight=1.0; 84 | } 85 | else { 86 | double a,b; 87 | a = 1.0 / (m-n); 88 | b = ((float)n) / (n-m); 89 | weight = a*position + b; 90 | } 91 | } 92 | return weight; 93 | } 94 | 95 | 96 | 97 | 98 | /******************************/ 99 | /** access() **/ 100 | /******************************/ 101 | 102 | /* 103 | Access a specific position in the array 104 | Input: array, dimensions, position 105 | Output: value at this position 106 | */ 107 | 108 | double access(double* array, int x, int y, int max_x) { 109 | return array[y*max_x+x]; 110 | } 111 | 112 | 113 | 114 | 115 | /********************/ 116 | /** main() **/ 117 | /********************/ 118 | 119 | int main(int argc, char* argv[]) { 120 | int hor_size, sag_size, cor_size; 121 | int i, j; 122 | int h, c, s; 123 | int n,m; 124 | char *DV_ascii, *VD_ascii, *out_ascii; 125 | double **VD_data, **DV_data, **merged_data; 126 | double DV_value, VD_value, factor; 127 | ifstream file_in; 128 | ofstream file_out; 129 | string line; 130 | 131 | 132 | if(argc!=9) { 133 | cout << "*** Error. Exactly eight arguments are needed.\n"; 134 | return 9; 135 | } 136 | 137 | hor_size = atoi(argv[1]); 138 | sag_size = atoi(argv[2]); 139 | cor_size = atoi(argv[3]); 140 | DV_ascii = argv[4]; 141 | VD_ascii = argv[5]; 142 | out_ascii = argv[6]; 143 | n = atoi(argv[7]); 144 | m = atoi(argv[8]); 145 | 146 | printTimestamp("Ready to start."); 147 | 148 | VD_data = new double*[hor_size*cor_size]; 149 | DV_data = new double*[hor_size*cor_size]; 150 | merged_data = new double*[hor_size*cor_size]; 151 | 152 | for(i=0;i0) { 182 | istringstream sin(line); 183 | double val; 184 | int nb_values=0; 185 | while(sin>>val) { 186 | VD_data[i][nb_values]=val; 187 | ++nb_values; 188 | } 189 | if(nb_values!=sag_size) { 190 | cout << "Error? size=" << sag_size << ", but " << nb_values << " VD values read.\n"; 191 | return -1; 192 | } 193 | ++i; 194 | 195 | } 196 | } 197 | 198 | file_in.close(); 199 | 200 | /* DV */ 201 | 202 | printTimestamp(DV_ascii); 203 | 204 | file_in.open(DV_ascii); 205 | if (not file_in.is_open()) { 206 | cout << "*** Error opening DV file.\n"; 207 | return 2; 208 | } 209 | 210 | i=0; 211 | 212 | // cout << "Reading DV." << endl; 213 | 214 | /* We read line by line */ 215 | while (getline(file_in,line)) { 216 | if(line.length()>0) { 217 | istringstream sin(line); 218 | double val; 219 | int nb_values=0; 220 | while(sin>>val) { 221 | DV_data[i][nb_values]=val; 222 | ++nb_values; 223 | } 224 | if(nb_values!=sag_size) { 225 | cout << "Error? size=" << sag_size << ", but " << nb_values << " DV values read.\n"; 226 | return -1; 227 | } 228 | ++i; 229 | 230 | } 231 | } 232 | 233 | file_in.close(); 234 | 235 | 236 | 237 | /************************************/ 238 | /** PROCESSING THE FILES **/ 239 | /************************************/ 240 | 241 | printTimestamp("Starting to combine the horizontal slices."); 242 | 243 | 244 | for(h=0; h=0; --i) { 280 | delete[] DV_data[i]; 281 | delete[] VD_data[i]; 282 | delete[] merged_data[i]; 283 | } 284 | delete[] DV_data; 285 | delete[] VD_data; 286 | delete[] merged_data; 287 | 288 | printTimestamp("Done."); 289 | return 0; 290 | } 291 | -------------------------------------------------------------------------------- /help.txt: -------------------------------------------------------------------------------- 1 | 2 | *********************** 3 | ** BRIEF USER MANUAL ** 4 | *********************** 5 | 6 | 7 | REQUIREMENTS 8 | 9 | In the following, we assume that the required software (e.g. ImageMagick, ANTS; see manuscript for complete list) are already installed, and accessible via the command line. 10 | For help with a specific software, please refer to that software's website. 11 | We also assume that the C++ programs we provide are already compiled. 12 | 13 | For clarity, we recommend to use separate folders for each type of data. 14 | For instance, we usually have one external hard-drive for each dataset and use the following structure: 15 | - the 'raw' folder contains the TIFF stacks obtained from the microscope (one subfolder per stack). 16 | - the 'nii_individual' contains the NIfTI-1 files from the VD and DV directions. 17 | - the 'nii_merged' contains the NIfTI-1 files obtained after merging VD and DV. 18 | - the 'registration' folder all the data generated for registration and alignment. 19 | - the 'temp' folder is used for all temporary files. 20 | - the 'ascii' folder is used for NIfTI-1 images exported as text files. 21 | - the 'analysis' folder is used for image processing (e.g. when calculation the median signal intensity). 22 | - the 'logs' folder is used to save all log files generated during the analysis. 23 | - the 'tiff' folder is used to store the NIfTI-1 images exported as TIFF stacks. 24 | 25 | We recommend using a similar structure, but this can be modified in the parameter files. 26 | Please ensure any folder listed in these parameter files actually exists, as our methods will not attempt to create them. 27 | 28 | 29 | 30 | STEP 1: convertTiffFiles.py 31 | 32 | In this step, we convert each 2D TIFF image stack obtained from the microscope to a 3D NIfTI-1 image. 33 | Typically, each brain corresponds to four stacks: two channels (nuclear counterstaining and expression signal) x 2 acquisition directions (D-V and V-D). 34 | The script expects each stack to be stored in its own folder, which follows a specific naming rule with four fields separated by an underscore: information about the experiment (including imaging date), a unique ID for this brain, information about the imaging direction ("VD" or "DV") and information about the channel ("nuclear" for the nuclear counterstaining and "geneExp" for the signal channel). For instance, 20131118LAdV_001_nuclear_DV. 35 | 36 | To run the script, type: python convertTiffFiles.py 37 | where is the name of the file giving all the required parameters 38 | 39 | The script takes 11 parameters. 40 | An example is given in NatureProtocols_step1.txt 41 | Lines starting with # are comments to help understand the file structure, and are ignored by the script. 42 | 43 | For the "files" parameters, please note that: 44 | - in Python, the first character is at position 0. 45 | - the two values are separated by a comma (with no space). 46 | 47 | We recommend downscaling the samples to 25%-resolution given the limitations of current imaging processing tools, (especially registration). 48 | In this step, this is done by only keeping one every 4 horizontal slices ('step factor' of 4 in the parameter file) and rescaling each of these ('scaling factor' of 0.25 in the parameter file). 49 | Future version of this code may allow higher resolutions. 50 | 51 | 52 | 53 | STEP 2: sameBrainAlignment.py 54 | 55 | In this step, we align the DV images to the VD images of the same brain. 56 | The registration relies on ANTS, and a parameter is used to specify whether to use SyN or affine registration. 57 | 58 | To run the script, type: python sameBrainAlignment.py 59 | where is the name of the file giving all the required parameters 60 | 61 | An example of parameter file is given in NatureProtocols_step2.txt 62 | Note that the list of brain IDs uses commas (with no space) to separate the IDs. 63 | 64 | 65 | 66 | STEP 3-1: edgeDetection.py 67 | 68 | In this step, we calculate the "edge content" of the horizontal slices of the DV and VD images of the same brain (using the 'aligned' image for VD, of course). 69 | This is used to calculate the values n and m. For convenience, the method gives results at two threshold values, 5% and 10%. We recommend using the 5% values. 70 | 71 | The results are shown in the following format: 72 | 73 | 74 | For each slice the result is either VD, DV, or mix. 75 | For each pair of images, there is (usually near the middle of the brain) a region where the results change from 'VD' to 'mix', stays at 'mix' for a number of consecutive slices (typically 5-15 slices), and then changes to 'DV'. In that region, the first 'mix' gives the n value, and the last one gives the m value. 76 | There may be regions where 'mix' appears in between consecutive 'VD' or consecutive 'DV' (but without the change from 'VD' to 'DV'). These can be ignored. 77 | 78 | To run the script, type: python edgeDetection.py 79 | where is the name of the file giving all the required parameters 80 | 81 | An example of parameter file is given in NatureProtocols_step3-1.txt 82 | Note that lists (of brain IDs, or number of slices) use commas (with no space) as separators. 83 | 84 | To easily find the number of slices of a NIfTI-1 file, you can open it in ITK-SNAP, or use the PrintHeader function in the command line. 85 | 86 | 87 | 88 | STEP 3-2: fileMerging.py 89 | 90 | In this step, we use the n and m values calculated above to merge the DV and VD images of the same brain into a single 3D image. 91 | 92 | To run the script, type: python fileMerging.py 93 | where is the name of the file giving all the required parameters 94 | 95 | An example of parameter file is given in NatureProtocols_step3-2.txt 96 | Note that lists (of brain IDs, n/m values, or number of slices) use commas (with no space) as separators. 97 | In the lists for n and m, the values must be listed in the same order as the brain IDs. 98 | 99 | 100 | 101 | STEP 4: internalAlignment.py 102 | 103 | In this step, we register and align all merged brain images from a given dataset to one of these brains, selected as an internal reference for that dataset. This is to ensure that images can later be compared pixel by pixel. 104 | As for earlier registrations, a parameter specifies whether to use SyN or affine registration. 105 | 106 | To run the script, type: python internalAlignment.py 107 | where is the name of the file giving all the required parameters 108 | 109 | An example of parameter file is given in NatureProtocols_step4.txt 110 | Note that lists use commas (with no space) as separators. 111 | 112 | 113 | 114 | STEP 5: atlasAlignment.py 115 | 116 | In this step, the internal reference brain is registered to a brain atlas, so that all samples (previously aligned to this internal reference) can now be aligned to the atlas. 117 | In the example files, we use the Allen Brain Atlas, but other atlases (e.g. Walxhom Space) can be used. 118 | As for earlier registrations, a parameter specifies whether to use SyN or affine registration. 119 | 120 | To run the script, type: python atlasAlignment.py 121 | where is the name of the file giving all the required parameters 122 | 123 | An example of parameter file is given in NatureProtocols_step5.txt 124 | Note that lists use commas (with no space) as separators. 125 | 126 | 127 | 128 | STEP 6: median_brainOnly.py 129 | 130 | In this step, we calculate the median intensity of the signal channel (so that can later normalise the various samples). Using the atlas and the alignment performed during step 5, we make sure to only consider the pixels located inside the brain. 131 | 132 | For each sample, the output will show the total number of pixels, the number of pixels located inside the brain, and the median intensity for these pixels. 133 | For the first two values should be the same for all samples within a given dataset. The third value will be used in the next step. 134 | 135 | To run the script, type: python median_brainOnly.py 136 | where is the name of the file giving all the required parameters 137 | 138 | An example of parameter file is given in NatureProtocols_step6.txt 139 | Note that lists use commas (with no space) as separators. 140 | 141 | 142 | 143 | STEP 7: normalisation_comparison.py 144 | 145 | In this step, we normalise the samples based on the median intensities calculated at step 6, and give an example of brain to brain signal comparison. 146 | Depending on the dataset structure, there are of course a large number of possible comparisons. 147 | 148 | To run the script, type: python normalisation_comparison.py 149 | where is the name of the file giving all the required parameters 150 | 151 | An example of parameter file is given in NatureProtocols_step7.txt 152 | Note that lists use commas (with no space) as separators. 153 | The median values must be listed in the same order as the brain IDs. 154 | 155 | 156 | 157 | STEP 8: exportTiffStack.py 158 | 159 | In this step, we give two examples of export. First, we normalise some of the original (raw) TIFF stacks using the median intensities (as in step 7 for the NIfTI-1 files). Then, we give an example of how to export some processed NIfTI-1 files to TIFF stacks, (for instance for visualisation with tools such as Imaris). 160 | 161 | To run the script, type: python exportTiffStack.py 162 | where is the name of the file giving all the required parameters 163 | 164 | An example of parameter file is given in NatureProtocols_step8.txt 165 | Note that lists use commas (with no space) as separators. 166 | The median values must be listed in the same order as the brain IDs of the raw TIFF stacks. 167 | 168 | 169 | -------------------------------------------------------------------------------- /edge_detection_Prewitt.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 3 | edge_detection_Prewitt.cpp | Calculates the "edge content" of 3D brain 4 | images given as ASCII files. Called from edgeDetection.py 5 | Please see the user manual for details. 6 | 7 | Copyright (C) 2015, Dimitri Perrin 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see . 21 | 22 | ************************************************************************/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | 36 | 37 | /**************************************/ 38 | /** printTimestamp() **/ 39 | /**************************************/ 40 | 41 | /* 42 | Prints a custom string with the current time and a given message 43 | Input: the message we want to include 44 | Output: none 45 | */ 46 | 47 | int printTimestamp(string infoString) { 48 | time_t rawtime; 49 | struct tm * timeinfo; 50 | char buffer1 [15]; 51 | 52 | time (&rawtime); 53 | timeinfo = localtime (&rawtime); 54 | strftime (buffer1,80,"%H:%M:%S ->\t",timeinfo); 55 | 56 | cout << buffer1 << infoString << endl; 57 | 58 | return 0; 59 | } 60 | 61 | 62 | 63 | 64 | /********************************/ 65 | /** whichOne() **/ 66 | /********************************/ 67 | 68 | /* 69 | Decides which image to use, based on the edge content 70 | Input: edge content of each image, threshold 71 | Output: image to use (1: VD, -1: DV, 0: mix) 72 | */ 73 | 74 | int whichOne(double VD, double DV, double threshold) { 75 | double val = (VD-DV)/VD; 76 | int a=0, b=0; 77 | if (fabs(val)>threshold) 78 | a = 1; 79 | if (val<-threshold) 80 | b = -2; 81 | return a+b; 82 | } 83 | 84 | 85 | 86 | 87 | /******************************/ 88 | /** access() **/ 89 | /******************************/ 90 | 91 | /* 92 | Access a specific position in the array 93 | Input: array, dimensions, position 94 | Output: value at this position 95 | */ 96 | 97 | double access(double* array, int x, int y, int max_x) { 98 | return array[y*max_x+x]; 99 | } 100 | 101 | 102 | 103 | 104 | /********************************/ 105 | /** edgeness_Prewitt() **/ 106 | /********************************/ 107 | 108 | /* 109 | Calculates the total edge content using the Prewitt operator 110 | Input: array, dimensions 111 | Output: edge content 112 | */ 113 | 114 | double edgeness_Prewitt(double* array,int max_x, int max_y) { 115 | double total = 0.0, centers = 0.0; 116 | double up, down, left, right, up_left, up_right, down_left, down_right; 117 | double conv_x, conv_y; 118 | int x,y; 119 | for(y=1; y0) { 204 | istringstream sin(line); 205 | double val; 206 | int nb_values=0; 207 | while(sin>>val) { 208 | VD_data[i][nb_values]=val; 209 | ++nb_values; 210 | } 211 | if(nb_values!=sag_size) { 212 | cout << "Error? size=" << sag_size << ", but " << nb_values << " VD values read.\n"; 213 | return -1; 214 | } 215 | ++i; 216 | 217 | } 218 | } 219 | 220 | file_in.close(); 221 | 222 | /* DV */ 223 | 224 | printTimestamp(DV_ascii); 225 | 226 | file_in.open(DV_ascii); 227 | if (not file_in.is_open()) { 228 | cout << "*** Error opening DV file.\n"; 229 | return 2; 230 | } 231 | 232 | i=0; 233 | 234 | // cout << "Reading DV." << endl; 235 | 236 | /* We read line by line */ 237 | while (getline(file_in,line)) { 238 | if(line.length()>0) { 239 | istringstream sin(line); 240 | double val; 241 | int nb_values=0; 242 | while(sin>>val) { 243 | DV_data[i][nb_values]=val; 244 | ++nb_values; 245 | } 246 | if(nb_values!=sag_size) { 247 | cout << "Error? size=" << sag_size << ", but " << nb_values << " DV values read.\n"; 248 | return -1; 249 | } 250 | ++i; 251 | 252 | } 253 | } 254 | 255 | file_in.close(); 256 | 257 | 258 | 259 | /************************************/ 260 | /** PROCESSING THE FILES **/ 261 | /************************************/ 262 | 263 | printTimestamp("Starting to process horizontal slices for both files."); 264 | 265 | VD_hor_slices = new double*[hor_size]; 266 | DV_hor_slices = new double*[hor_size]; 267 | 268 | r1 = new int[hor_size]; 269 | r2 = new int[hor_size]; 270 | VD_edge = new double[hor_size]; 271 | DV_edge = new double[hor_size]; 272 | 273 | 274 | for(h=0; h=0; --i) { 339 | delete[] VD_hor_slices[i]; 340 | delete[] DV_hor_slices[i]; 341 | } 342 | delete[] VD_hor_slices; 343 | delete[] DV_hor_slices; 344 | 345 | delete[] r1; 346 | delete[] r2; 347 | delete[] VD_edge; 348 | delete[] DV_edge; 349 | 350 | 351 | for(i=hor_size*cor_size-1; i>=0; --i) { 352 | delete[] DV_data[i]; 353 | delete[] VD_data[i]; 354 | } 355 | delete[] DV_data; 356 | delete[] VD_data; 357 | 358 | printTimestamp("Done."); 359 | return 0; 360 | } 361 | -------------------------------------------------------------------------------- /gpl-3.0.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------