Skip to content

Commit

Permalink
Merge pull request #84 from aces/dev
Browse files Browse the repository at this point in the history
Preparation for release.
  • Loading branch information
natacha-beck committed Nov 21, 2016
2 parents 7710338 + dc7ca3d commit d8c70c7
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 124 deletions.
69 changes: 51 additions & 18 deletions cbrain_task/civet/bourreau/civet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,31 @@ def setup #:nodoc:

self.results_data_provider_id ||= collection ? collection.data_provider_id : t1.data_provider_id

input_symlink_base = prefix.present? ? "#{mincfiles_dir}/#{prefix}_#{dsid}" : "#{mincfiles_dir}/#{dsid}"
# MODE A (collection) symlinks
if collection

t1ext = t1_name.match(/.gz$/i) ? ".gz" : ""
t1sym = "#{mincfiles_dir}/#{prefix}_#{dsid}_t1.mnc#{t1ext}"
t1sym = "#{input_symlink_base}_t1.mnc#{t1ext}"
make_available(collection, t1sym, t1_name)
return false unless validate_minc_file(t1sym)

if mybool(file0[:multispectral]) || mybool(file0[:spectral_mask])
if t2_name.present?
t2ext = t2_name.match(/.gz$/i) ? ".gz" : ""
t2sym = "#{mincfiles_dir}/#{prefix}_#{dsid}_t2.mnc#{t2ext}"
t2sym = "#{input_symlink_base}_t2.mnc#{t2ext}"
make_available(collection, t2sym, t2_name)
return false unless validate_minc_file(t2sym)
end
if pd_name.present?
pdext = pd_name.match(/.gz$/i) ? ".gz" : ""
pdsym = "#{mincfiles_dir}/#{prefix}_#{dsid}_pd.mnc#{pdext}"
pdsym = "#{input_symlink_base}_pd.mnc#{pdext}"
make_available(collection, pdsym, pd_name)
return false unless validate_minc_file(pdsym)
end
if mk_name.present?
mkext = mk_name.match(/.gz$/i) ? ".gz" : ""
mksym = "#{mincfiles_dir}/#{prefix}_#{dsid}_mask.mnc#{mkext}"
mksym = "#{input_symlink_base}_mask.mnc#{mkext}"
make_available(collection, mksym, mk_name)
return false unless validate_minc_file(mksym)
end
Expand All @@ -124,7 +125,7 @@ def setup #:nodoc:

t1_name = t1.name
t1ext = t1_name.match(/.gz$/i) ? ".gz" : ""
t1sym = "#{mincfiles_dir}/#{prefix}_#{dsid}_t1.mnc#{t1ext}"
t1sym = "#{input_symlink_base}_t1.mnc#{t1ext}"
make_available(t1,t1sym)
return false unless validate_minc_file(t1sym)

Expand All @@ -133,7 +134,7 @@ def setup #:nodoc:
t2 = Userfile.find(t2_id)
t2_name = t2.name
t2ext = t2_name.match(/.gz$/i) ? ".gz" : ""
t2sym = "#{mincfiles_dir}/#{prefix}_#{dsid}_t2.mnc#{t2ext}"
t2sym = "#{input_symlink_base}_t2.mnc#{t2ext}"
make_available(t2,t2sym)
return false unless validate_minc_file(t2sym)
end
Expand All @@ -142,7 +143,7 @@ def setup #:nodoc:
pd = Userfile.find(pd_id)
pd_name = pd.name
pdext = pd_name.match(/.gz$/i) ? ".gz" : ""
pdsym = "#{mincfiles_dir}/#{prefix}_#{dsid}_pd.mnc#{pdext}"
pdsym = "#{input_symlink_base}_pd.mnc#{pdext}"
make_available(pd,pdsym)
return false unless validate_minc_file(pdsym)
end
Expand All @@ -151,7 +152,7 @@ def setup #:nodoc:
mk = Userfile.find(mk_id)
mk_name = mk.name
mkext = mk_name.match(/.gz$/i) ? ".gz" : ""
mksym = "#{mincfiles_dir}/#{prefix}_#{dsid}_mask.mnc#{mkext}"
mksym = "#{input_symlink_base}_mask.mnc#{mkext}"
make_available(mk,mksym)
return false unless validate_minc_file(mksym)
end
Expand Down Expand Up @@ -209,6 +210,10 @@ def cluster_commands_single(options_to_ignore={}) #:nodoc:
prefix = file0[:prefix] || "unkpref"
dsid = file0[:dsid] || "unkdsid"

is_version_1_1_12 = self.tool_config.is_version("1.1.12")
is_at_least_version_2_0_0 = self.tool_config.is_at_least_version("2.0.0")
is_at_least_version_2_1_0 = self.tool_config.is_at_least_version("2.1.0")

# -----------------------------------------------------------
# More validations of params that are substituted in commands
# -----------------------------------------------------------
Expand All @@ -221,10 +226,10 @@ def cluster_commands_single(options_to_ignore={}) #:nodoc:
# Model
if params[:model].present?
cb_error "Bad model name." unless params[:model] =~ /^\s*[\w\.]+\s*$/
cb_error "Model is not valid for this CIVET version" if params[:model] == "ADNInl" && !self.tool_config.is_version("1.1.12")
cb_error "Model is not valid for this CIVET version" if params[:model] == "icbm152nl_09a" && !self.tool_config.is_at_least_version("2.0.0")
cb_error "Model is not valid for this CIVET version" if params[:model] == "icbm152nl_09s" && !self.tool_config.is_at_least_version("2.0.0")
cb_error "Model is not valid for this CIVET version" if params[:model] == "ADNIhires" && !self.tool_config.is_at_least_version("2.0.0")
cb_error "Model is not valid for this CIVET version" if params[:model] == "ADNInl" && !is_version_1_1_12
cb_error "Model is not valid for this CIVET version" if params[:model] == "icbm152nl_09a" && !is_at_least_version_2_0_0
cb_error "Model is not valid for this CIVET version" if params[:model] == "icbm152nl_09s" && !is_at_least_version_2_0_0
cb_error "Model is not valid for this CIVET version" if params[:model] == "ADNIhires" && !is_at_least_version_2_0_0
end

# Interp
Expand All @@ -244,7 +249,11 @@ def cluster_commands_single(options_to_ignore={}) #:nodoc:

# LSQ
if params[:lsq].present?
cb_error "Bad LSQ value." unless params[:lsq] =~ /^\s*(?:6|9|12)\s*$/
if is_at_least_version_2_1_0
cb_error "Bad LSQ value." unless params[:lsq] =~ /^\s*(?:0|6|9|12)\s*$/
else
cb_error "Bad LSQ value." unless params[:lsq] =~ /^\s*(?:6|9|12)\s*$/
end
end

# Resamp surf kern area
Expand Down Expand Up @@ -274,7 +283,11 @@ def cluster_commands_single(options_to_ignore={}) #:nodoc:
args += "-N3-distance #{params[:N3_distance].bash_escape} " if params[:N3_distance].present?
args += "-headheight #{params[:headheight].bash_escape} " if params[:headheight].present? && !options_to_ignore[:headheight]
args += "-mask-blood-vessels " if mybool(params[:mask_blood_vessels]) && !options_to_ignore[:mask_blood_vessels]
args += "-lsq#{params[:lsq]} " if params[:lsq] && params[:lsq].to_i != 9 # there is NO -lsq9 option!
if params[:lsq] != 0
args += "-lsq#{params[:lsq]} " if params[:lsq] && params[:lsq].to_i != 9 # there is NO -lsq9 option!
else
args += "-input_is_stx "
end
args += "-no-surfaces " if mybool(params[:no_surfaces])
args += "-correct-pve " if mybool(params[:correct_pve])
args += "-hi-res-surfaces " if mybool(params[:high_res_surfaces]) && !options_to_ignore[:high_res_surfaces]
Expand All @@ -283,12 +296,30 @@ def cluster_commands_single(options_to_ignore={}) #:nodoc:
args += "-multispectral " if mybool(file0[:multispectral])
args += "-spectral_mask " if mybool(file0[:spectral_mask])

# PVE
if is_at_least_version_2_1_0
if params[:pve] == "classic"
args += "-no-correct-pve -no-subcortical -no-mask-cerebellum "
elsif params[:pve] == "advanced"
args += "-correct-pve -subcortical -mask-cerebellum "
end
end

# Thickness methods and kernel
if ( params[:thickness_method].present? &&
params[:thickness_kernel].present? &&
is_valid_integer_list(params[:thickness_kernel], allow_blanks: false)
)
args += "-thickness #{params[:thickness_method].bash_escape} #{params[:thickness_kernel].bash_escape} "
if is_at_least_version_2_1_0
thickness_methods = Array(params[:thickness_method])
thickness_methods = thickness_methods & ["tlaplace", "tlink","tfs"]
thickness_methods = thickness_methods.unshift(params[:thickness_method_for_qc]) if params[:thickness_method_for_qc].present?
thickness_string = thickness_methods.uniq.join(":")
else
# Safegard should already be a String
thickness_string = Array(params[:thickness_method])[0].to_s
end
args += "-thickness #{thickness_string.bash_escape} #{params[:thickness_kernel].bash_escape} "
end

# Surface resampling
Expand All @@ -302,7 +333,7 @@ def cluster_commands_single(options_to_ignore={}) #:nodoc:
# Atlas
if params[:atlas].present? && ! options_to_ignore[:atlas]
atlas_name = params[:atlas].strip
if self.tool_config.is_at_least_version("2.0.0")
if is_at_least_version_2_0_0
args += "-surface-atlas #{atlas_name.bash_escape} "
else
args += "-surface-atlas $MNI_CIVET_ROOT/models/AAL_atlas_left.txt $MNI_CIVET_ROOT/models/AAL_atlas_right.txt " if atlas_name == "AAL"
Expand Down Expand Up @@ -331,8 +362,10 @@ def cluster_commands_single(options_to_ignore={}) #:nodoc:
args += "-reset-from #{reset_from.bash_escape} "
end

mincfiles_dir = "mincfiles_input"
civet_command = "CIVET_Processing_Pipeline -prefix #{prefix.bash_escape} -source #{mincfiles_dir} -target civet_out -spawn #{args} -run #{dsid.bash_escape}"
mincfiles_dir = "mincfiles_input"
civet_command = "CIVET_Processing_Pipeline -source #{mincfiles_dir} -target civet_out -spawn #{args} "
civet_command += "-prefix #{prefix.bash_escape} " if prefix.present?
civet_command += "-run #{dsid.bash_escape}" if dsid.present?

self.addlog("Full CIVET command:\n #{civet_command.gsub(/ -/, "\n -")}") if self.user.has_role? :admin_user

Expand Down
7 changes: 5 additions & 2 deletions cbrain_task/civet/common/civet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def job_walltime_estimate #:nodoc:
else
# Added 2 extra hours, just in case user specify ANIMAL.
if mybool(params[:high_res_surfaces])
params[:template] == "1.00" ? 16.hours : 22.hours
params[:template] == "1.00" ? 24.hours : 36.hours
else
params[:template] == "1.00" ? 10.hours : 12.hours
params[:template] == "1.00" ? 22.hours : 30.hours
end
end
end
Expand Down Expand Up @@ -110,6 +110,9 @@ def identify_options_to_ignore(ignored_options={}) #:nodoc:
ignored_options[:animal] = true
ignored_options[:lobe_atlas] = true
end
if !self.tool_config.is_at_least_version("2.1.0")
ignored_options[:pve] = true
end

ignored_options
end
Expand Down
22 changes: 14 additions & 8 deletions cbrain_task/civet/portal/civet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ def self.default_launch_args #:nodoc:
def before_form #:nodoc:
params = self.params

params[:model] = "icbm152nl_09s" if self.tool_config && self.tool_config.is_version("2.0.0")
params[:model] = "icbm152nl_09s" if self.tool_config && self.tool_config.is_at_least_version("2.0.0")
if self.tool_config && self.tool_config.is_at_least_version("2.1.0")
params[:thickness_method] = ["tlaplace"]
params[:thickness_method_for_qc] = "tlaplace"
end

file_ids = params[:interface_userfile_ids]

Expand Down Expand Up @@ -238,6 +242,8 @@ def after_form #:nodoc:
dsid = (fa[:dsid] || "").strip
fa[:dsid] = dsid

is_at_least_version_2_1_0 = self.tool_config && self.tool_config.is_at_least_version("2.1.0")

# Verify the subject ID
message = nil
if dsid.blank?
Expand All @@ -258,7 +264,9 @@ def after_form #:nodoc:

# Verify the prefix
message = nil
if prefix.blank?
if prefix.blank? && is_at_least_version_2_1_0
message = nil
elsif prefix.blank?
message = " is blank?"
elsif prefix !~ /^\w[\w\-]*$/
message = " is not a simple identifier."
Expand Down Expand Up @@ -439,8 +447,8 @@ def old_get_default_args_for_collection(collection) #:nodoc:
prefix = Regexp.last_match[1]
dsid = Regexp.last_match[2]
else
prefix = "prefix"
dsid = "subject" # maybe "auto_#{idx}"
prefix = self.tool_config && !self.tool_config.is_version("2.1.0") ? "prefix" : ""
dsid = "subject" # maybe "auto_#{idx}"
end

file_args_array << {
Expand Down Expand Up @@ -496,8 +504,8 @@ def old_get_default_args_for_t1list(minc_userfiles) #:nodoc:
prefix = Regexp.last_match[1]
dsid = Regexp.last_match[2]
else
prefix = "prefix"
dsid = "subject" # maybe "auto_#{idx}"
prefix = self.tool_config && !self.tool_config.is_version("2.1.0") ? "prefix" : ""
dsid = "subject" # maybe "auto_#{idx}"
end

file_args_array << {
Expand Down Expand Up @@ -569,7 +577,6 @@ def create_combiner(study_name,tids) #:nodoc:
combiner.description = study_name
combiner.status = 'New'
combiner.group_id = self.group_id
combiner.launch_time = self.launch_time
combiner.batch_id = self.batch_id
combiner.params = {
:civet_study_name => study_name,
Expand All @@ -595,7 +602,6 @@ def create_qc(cid) #:nodoc:
qc.description = params[:study_name]
qc.status = 'New'
qc.group_id = self.group_id
qc.launch_time = self.launch_time
qc.batch_id = self.batch_id
qc.params = { :study_from_task_id => cid }
qc.add_prerequisites_for_setup(cid)
Expand Down
2 changes: 1 addition & 1 deletion cbrain_task/civet/views/_civet_file_from_col.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<%= form.params_hidden_field "file_args[#{idx}][mk_name]" %>
</td>

<td><%= form.params_text_field "file_args[#{idx}][prefix]" %></td>
<td><%= form.params_text_field "file_args[#{idx}][prefix]" %></td>
<td><%= form.params_text_field "file_args[#{idx}][dsid]" %></td>

<% if file[:t2_name].blank? %>
Expand Down
32 changes: 24 additions & 8 deletions cbrain_task/civet/views/_task_params.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
not_at_least_1_1_11 = !@tool_config || !@tool_config.is_at_least_version("1.1.11")
not_at_least_1_1_12 = !@tool_config || !@tool_config.is_at_least_version("1.1.12")
not_at_least_2_0_0 = !@tool_config || !@tool_config.is_at_least_version("2.0.0")
not_at_least_2_1_0 = !@tool_config || !@tool_config.is_at_least_version("2.1.0")

# Models
default_models = [ "icbm152nl", "icbm152lin" ]
Expand All @@ -51,6 +52,7 @@


default_template = not_at_least_2_0_0 ? ["1.00"] : ["0.50","0.75","1.00"]
default_lsq = not_at_least_2_1_0 ? [ "6", "9", "12" ] : [ "0", "6", "9", "12" ]
%>


Expand Down Expand Up @@ -83,8 +85,9 @@

<br>

<%= form.params_label :lsq, "Degrees of freedom for linear registration:", :title => "Degrees of freedom for linear registration to stereotaxic space" %>
<%= form.params_select :lsq, [ "6", "9", "12" ] %>
<%= form.params_label :lsq, "Degrees of freedom for linear registration:", :title => "Degrees of freedom for linear registration to stereotaxic space.\n0 means that the input volume is already in stereotaxic space and linear registration will be skipped.
" %>
<%= form.params_select :lsq, default_lsq %>

<br>

Expand All @@ -107,6 +110,13 @@

<%= form.params_label :N3_distance, "N3 distance:", :title => "N3 spline distance in mm (suggested values: 200 for 1.5T scan; 125 or 100 for 3T scan; 0 for MP2RAGE scan in later version than 1.1.12)" %>
<%= form.params_text_field :N3_distance, :size => 4 %>
<% if !not_at_least_2_1_0 %>
<br>

<%= form.params_label :pve, "PVE:", :title => "PVE: advanced = -correct-pve -subcortical -mask-cerebellum\nclassic = -no-correct-pve -no-subcortical -no-mask-cerebellum (old behaviour)" %>
<%= form.params_select :pve, [ "advanced", "classic" ] %>
<% end %>
</fieldset>

<P>
Expand Down Expand Up @@ -144,7 +154,6 @@

<br>

<%= form.params_label :thickness_method, "Thickness method:", :title => "Thickness method" %>
<%
tmethods = [ "tlink", "tlaplace"]
if !@task.new_record? && ! @task.params[:thickness_method].blank?
Expand All @@ -153,16 +162,23 @@
tmethods << old_val
end
end
# tnear only for version < 2.0.0
tnear_disabled = not_at_least_2_0_0 ? {} : { :disabled => '1' }
params[:thickness_method] = nil if tnear_disabled.present? && params[:thickness_method] == 'tnear'
tmethods << [ "tnear", "tnear", tnear_disabled ]
# Add tfs for version >= 2.0.0
tfs_disabled = not_at_least_2_0_0 ? { :disabled => '1' } : {}
params[:thickness_method] = nil if tfs_disabled.present? && params[:thickness_method] == 'tfs'
tmethods << [ "tfs", "tfs", tfs_disabled ]
%>
<%= form.params_select :thickness_method, tmethods %>
<% if not_at_least_2_1_0 %>
<%= form.params_label :thickness_method, "Thickness method:", :title => "Thickness method" %>
<%= form.params_select :thickness_method, tmethods %>
<% else %>
<%= form.params_label "thickness_method[]", "Thickness methods:", :title => "Thickness methods" %>
<%= form.params_select "thickness_method[]", tmethods, {}, :multiple => true, :size => 3 %>
<p>
<%= form.params_label :thickness_method_for_qc, "Thickness method for QC:", :title => "Thickness method for QC" %>
<%= form.params_select :thickness_method_for_qc, tmethods %>
<% end %>
<%= form.params_label :thickness_kernel, "and kernel size:",
:title => "FWHM for surface blurring,\n default: 20 for version 1.1.11 and lower,\n default: 30 for version 1.1.12 and later\nList of integers separated by a ':' is accepted for version 2.0.0 and later" %>
<%= form.params_text_field :thickness_kernel, :size => not_at_least_2_0_0 ? 4 : 12 %>
Expand Down
4 changes: 3 additions & 1 deletion cbrain_task/civet/views/public/edit_params_help.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h1>Civet Options</h1>
<li><b>Head height:</b> Head height in mm for neck cropping. Suggested value: 170. Only available for version 1.1.12 and later.</li>
<li><b>Mask blood vessels:</b> Mask blood vessels prior to white surface extraction. Only available for version 1.1.12 and later.</li>
<li><b>N3 distance:</b> N3 spline distance in mm (suggested values: 200 for 1.5T scan; 50-125 for 3T scan. For older 3T scans, low values nearer 50 may work best; for newer 3T scans, high values nearer 125 may work best).</li>
<li><b>PVE:</b> advanced = -correct-pve -subcortical -mask-cerebellum or classic = -no-correct-pve -no-subcortical -no-mask-cerebellum (default for version lower than 2.1.0).</li>
</ul>


Expand All @@ -50,7 +51,8 @@ <h1>Civet Options</h1>
<li><b>Do NOT build surfaces:</b> Don't build surfaces, if checked.</li>
<li><b>High resolution surface:</b> Build high resolution surfaces. Only available for version 2.0.0 and later.</li>
<li><b>Combine left/right surfaces:</b> Combine left and right cortical surfaces, if checked.</li>
<li><b>Thickness method:</b> Choose cortical thickness metric [default: tlink; also available: tlaplace, tnear (only for version 2.0.0 and lower), tfs (Freesurfer's metric, only for version 2.0.0 and later)].</li>
<li><b>Thickness method:</b> Choose cortical thickness metric [default: tlink; also available: tlaplace, tfs (Freesurfer's metric, only for version 2.0.0 and later)], starting to version 2.1.0 you can select more than one method.</li>
<li><b>Thickness method for QC: Choose the cortical thickness that will be used for the QC, is accepted for version 2.1.0 and later.</b> </li>
<li><b>Kernel size:</b> Default: 20mm for version 1.1.11 and lower and 30mm for version 1.1.12 and later.
List of integers separated by a ':' is accepted for version 2.0.0 and later, e.g. 10:20:30.</li>
<li><b>Resample surfaces:</b> Resample cortical surfaces, if checked.</li>
Expand Down
Loading

0 comments on commit d8c70c7

Please sign in to comment.