<s> import sys <EOL> import commands <EOL> import getopt <EOL> import os <EOL> import time <EOL> from msct_parser import Parser <EOL> import sct_utils as sct <EOL> from sct_extract_metric import read_label_file <EOL> path_script = os . path . dirname ( __file__ ) <EOL> path_sct = os . path . dirname ( path_script ) <EOL> class Param : <EOL> def __init__ ( self ) : <EOL> self . debug = <NUM_LIT:0> <EOL> self . folder_out = '<STR_LIT:label>' <EOL> self . path_template = path_sct + '<STR_LIT>' <EOL> self . folder_template = '<STR_LIT>' <EOL> self . folder_atlas = '<STR_LIT>' <EOL> self . folder_spinal_levels = '<STR_LIT>' <EOL> self . file_info_label = '<STR_LIT>' <EOL> self . warp_atlas = <NUM_LIT:1> <EOL> self . warp_spinal_levels = <NUM_LIT:0> <EOL> self . list_labels_nn = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . list_labels_spline = [ '<STR_LIT>' ] <EOL> self . verbose = <NUM_LIT:1> <EOL> self . qc = <NUM_LIT:1> <EOL> class WarpTemplate : <EOL> def __init__ ( self , fname_src , fname_transfo , warp_atlas , warp_spinal_levels , folder_out , path_template , verbose , qc ) : <EOL> self . fname_src = fname_src <EOL> self . fname_transfo = fname_transfo <EOL> self . warp_atlas = warp_atlas <EOL> self . warp_spinal_levels = warp_spinal_levels <EOL> self . folder_out = folder_out <EOL> self . path_template = path_template <EOL> self . folder_template = param . folder_template <EOL> self . folder_atlas = param . folder_atlas <EOL> self . folder_spinal_levels = param . folder_spinal_levels <EOL> self . verbose = verbose <EOL> self . qc = qc <EOL> start_time = time . time ( ) <EOL> sct . printv ( '<STR_LIT>' , self . verbose ) <EOL> sct . check_file_exist ( self . fname_src ) <EOL> sct . check_file_exist ( self . fname_transfo ) <EOL> self . path_template = sct . slash_at_the_end ( self . path_template , <NUM_LIT:1> ) <EOL> self . folder_out = sct . slash_at_the_end ( self . folder_out , <NUM_LIT:1> ) <EOL> self . folder_template = sct . slash_at_the_end ( self . folder_template , <NUM_LIT:1> ) <EOL> self . folder_atlas = sct . slash_at_the_end ( self . folder_atlas , <NUM_LIT:1> ) <EOL> self . folder_spinal_levels = sct . slash_at_the_end ( self . folder_spinal_levels , <NUM_LIT:1> ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' + self . fname_src <EOL> print '<STR_LIT>' + self . fname_transfo <EOL> print '<STR_LIT>' + self . path_template <EOL> print '<STR_LIT>' + self . folder_out + '<STR_LIT:\n>' <EOL> path_src , file_src , ext_src = sct . extract_fname ( self . fname_src ) <EOL> if os . path . exists ( self . folder_out ) : <EOL> sct . printv ( '<STR_LIT>' , self . verbose , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + self . folder_out ) <EOL> sct . run ( '<STR_LIT>' + self . folder_out ) <EOL> sct . printv ( '<STR_LIT>' , self . verbose ) <EOL> warp_label ( self . path_template , self . folder_template , param . file_info_label , self . fname_src , self . fname_transfo , self . folder_out ) <EOL> if self . warp_atlas == <NUM_LIT:1> : <EOL> sct . printv ( '<STR_LIT>' , self . verbose ) <EOL> warp_label ( self . path_template , self . folder_atlas , param . file_info_label , self . fname_src , self . fname_transfo , self . folder_out ) <EOL> if self . warp_spinal_levels == <NUM_LIT:1> : <EOL> sct . printv ( '<STR_LIT>' , self . verbose ) <EOL> warp_label ( self . path_template , self . folder_spinal_levels , param . file_info_label , self . fname_src , self . fname_transfo , self . folder_out ) <EOL> sct . printv ( '<STR_LIT>' , self . verbose ) <EOL> sct . printv ( '<STR_LIT>' + self . fname_src + '<STR_LIT:U+0020>' + self . folder_out + self . folder_template + '<STR_LIT>' + self . folder_out + self . folder_template + '<STR_LIT>' + self . folder_out + self . folder_template + '<STR_LIT>' + self . folder_out + self . folder_template + '<STR_LIT>' , self . verbose , '<STR_LIT:info>' ) <EOL> if self . qc : <EOL> from msct_image import Image <EOL> im = Image ( self . fname_src ) <EOL> im_wm = Image ( self . folder_out + self . folder_template + '<STR_LIT>' ) <EOL> im . save_quality_control ( plane = '<STR_LIT>' , n_slices = <NUM_LIT:4> , seg = im_wm , thr = <NUM_LIT:0.5> , cmap_col = '<STR_LIT>' , path_output = self . folder_out ) <EOL> def warp_label ( path_label , folder_label , file_label , fname_src , fname_transfo , path_out ) : <EOL> sct . printv ( '<STR_LIT>' , param . verbose ) <EOL> template_label_ids , template_label_names , template_label_file , combined_labels_ids , combined_labels_names , combined_labels_id_groups = read_label_file ( path_label + folder_label , file_label ) <EOL> sct . run ( '<STR_LIT>' + path_out + folder_label , param . verbose ) <EOL> for i in xrange ( <NUM_LIT:0> , len ( template_label_file ) ) : <EOL> fname_label = path_label + folder_label + template_label_file [ i ] <EOL> sct . run ( '<STR_LIT>' + fname_label + '<STR_LIT>' + path_out + folder_label + template_label_file [ i ] + '<STR_LIT>' + fname_src + '<STR_LIT>' + fname_transfo + '<STR_LIT>' + get_interp ( template_label_file [ i ] ) , param . verbose ) <EOL> sct . run ( '<STR_LIT>' + path_label + folder_label + param . file_info_label + '<STR_LIT:U+0020>' + path_out + folder_label , <NUM_LIT:0> ) <EOL> def get_interp ( file_label ) : <EOL> interp = '<STR_LIT>' <EOL> if file_label in param . list_labels_nn : <EOL> interp = '<STR_LIT>' <EOL> if file_label in param . list_labels_spline : <EOL> interp = '<STR_LIT>' <EOL> return interp <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> param = Param ( ) <EOL> param_default = Param ( ) <EOL> parser = Parser ( __file__ ) <EOL> parser . usage . set_description ( '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT:file>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = True , <EOL> example = "<STR_LIT>" ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT:file>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = True , <EOL> example = "<STR_LIT>" ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> default_value = str ( param_default . warp_atlas ) , <EOL> example = [ '<STR_LIT:0>' , '<STR_LIT:1>' ] ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> default_value = str ( param_default . warp_spinal_levels ) , <EOL> example = [ '<STR_LIT:0>' , '<STR_LIT:1>' ] ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> default_value = param_default . folder_out , <EOL> example = "<STR_LIT:label>" ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = None , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> deprecated_by = '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> default_value = str ( param_default . path_template ) ) <EOL> parser . add_option ( name = '<STR_LIT>' , <EOL> type_value = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> mandatory = False , <EOL> example = [ '<STR_LIT:0>' , '<STR_LIT:1>' ] , <EOL> default_value = '<STR_LIT:1>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = """<STR_LIT>""" , <EOL> mandatory = False , <EOL> default_value = '<STR_LIT:1>' , <EOL> example = [ '<STR_LIT:0>' , '<STR_LIT:1>' ] ) <EOL> arguments = parser . parse ( sys . argv [ <NUM_LIT:1> : ] ) <EOL> fname_src = arguments [ "<STR_LIT>" ] <EOL> fname_transfo = arguments [ "<STR_LIT>" ] <EOL> warp_atlas = int ( arguments [ "<STR_LIT>" ] ) <EOL> warp_spinal_levels = int ( arguments [ "<STR_LIT>" ] ) <EOL> folder_out = arguments [ "<STR_LIT>" ] <EOL> path_template = arguments [ "<STR_LIT>" ] <EOL> verbose = int ( arguments [ "<STR_LIT>" ] ) <EOL> qc = int ( arguments [ "<STR_LIT>" ] ) <EOL> WarpTemplate ( fname_src , fname_transfo , warp_atlas , warp_spinal_levels , folder_out , path_template , verbose , qc ) </s>
