cicada 0.9.2-java → 0.9.3-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #--
4
+ # /* ***** BEGIN LICENSE BLOCK *****
5
+ # *
6
+ # * Copyright (c) 2013 Colin J. Fuller
7
+ # *
8
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # * of this software and associated documentation files (the Software), to deal
10
+ # * in the Software without restriction, including without limitation the rights
11
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # * copies of the Software, and to permit persons to whom the Software is
13
+ # * furnished to do so, subject to the following conditions:
14
+ # *
15
+ # * The above copyright notice and this permission notice shall be included in
16
+ # * all copies or substantial portions of the Software.
17
+ # *
18
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ # * SOFTWARE.
25
+ # *
26
+ # * ***** END LICENSE BLOCK ***** */
27
+ #++
28
+
29
+ require 'cicada'
30
+
31
+ p = Cicada::CicadaMain.parse_parameter_file(ARGV[0])
32
+
33
+ c = Cicada::CicadaMain.new(p)
34
+
35
+ c.do_and_save_fits
36
+
37
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #--
4
+ # /* ***** BEGIN LICENSE BLOCK *****
5
+ # *
6
+ # * Copyright (c) 2013 Colin J. Fuller
7
+ # *
8
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # * of this software and associated documentation files (the Software), to deal
10
+ # * in the Software without restriction, including without limitation the rights
11
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # * copies of the Software, and to permit persons to whom the Software is
13
+ # * furnished to do so, subject to the following conditions:
14
+ # *
15
+ # * The above copyright notice and this permission notice shall be included in
16
+ # * all copies or substantial portions of the Software.
17
+ # *
18
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ # * SOFTWARE.
25
+ # *
26
+ # * ***** END LICENSE BLOCK ***** */
27
+ #++
28
+
29
+ require 'trollop'
30
+
31
+ require 'cicada'
32
+ require 'cicada/file_interaction'
33
+ require 'cicada/aberration_map'
34
+ require 'cicada/correction/correction'
35
+
36
+ opts = Trollop.options do
37
+ opt :parameter_file, "Parameter file", type: :string
38
+ opt :size_x, "Width of map in pixels", type: :integer, default: 256
39
+ opt :size_y, "Height of map in pixels", type: :integer, default: 256
40
+ opt :output_file, "Map output filename", type: :string
41
+ end
42
+
43
+ p = Cicada::CicadaMain.parse_parameter_file(opts[:parameter_file])
44
+
45
+ corr_file_fn = Cicada::FileInteraction.correction_filename(p)
46
+
47
+ c = Cicada::Correction.read_from_file(corr_file_fn)
48
+
49
+ ab_map = Cicada::AberrationMap.generate(c, [0, opts[:size_x]], [0, opts[:size_y]], p)
50
+
51
+ ab_map.write_to_file(opts[:output_file])
52
+
@@ -0,0 +1,75 @@
1
+ #--
2
+ # /* ***** BEGIN LICENSE BLOCK *****
3
+ # *
4
+ # * Copyright (c) 2013 Colin J. Fuller
5
+ # *
6
+ # * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # * of this software and associated documentation files (the Software), to deal
8
+ # * in the Software without restriction, including without limitation the rights
9
+ # * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # * copies of the Software, and to permit persons to whom the Software is
11
+ # * furnished to do so, subject to the following conditions:
12
+ # *
13
+ # * The above copyright notice and this permission notice shall be included in
14
+ # * all copies or substantial portions of the Software.
15
+ # *
16
+ # * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # * SOFTWARE.
23
+ # *
24
+ # * ***** END LICENSE BLOCK ***** */
25
+ #++
26
+
27
+ require 'cicada/correction/position_corrector'
28
+ require 'rimageanalysistools'
29
+ require 'rimageanalysistools/image_shortcuts'
30
+ require 'rimageanalysistools/create_parameters'
31
+
32
+ java_import Java::edu.stanford.cfuller.imageanalysistools.image.ImageFactory
33
+
34
+ module Cicada
35
+
36
+ class AberrationMap
37
+
38
+ def self.generate(c, bounds_x, bounds_y, params)
39
+
40
+ size_x = bounds_x[1] - bounds_x[0]
41
+ size_y = bounds_y[1] - bounds_y[0]
42
+
43
+ ab_map = ImageFactory.createWritable(ImageCoordinate[size_x, size_y, 3,1, 1], 0.0)
44
+
45
+ ab_map.setBoxOfInterest(ImageCoordinate[0,0,0,0,0], ImageCoordinate[size_x, size_y, 1, 1, 1])
46
+
47
+ ic2 = ImageCoordinate[0,0,0,0,0]
48
+
49
+ dist_conv = [params[:pixelsize_nm].to_f, params[:pixelsize_nm].to_f, params[:z_sectionsize_nm].to_f]
50
+
51
+ ab_map.each do |ic|
52
+
53
+ ic2.setCoord(ic)
54
+
55
+ corr = c.correct_position(ic[:x] + bounds_x[0], ic[:y] + bounds_y[0])
56
+
57
+ 0.upto(2) do |dim|
58
+
59
+ ic2[:z] = dim
60
+
61
+ ab_map[ic2] = corr[dim] * dist_conv[dim]
62
+
63
+ end
64
+
65
+ end
66
+
67
+ ab_map
68
+
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+
@@ -157,7 +157,15 @@ module Cicada
157
157
 
158
158
  @logger.debug { "Processing object #{obj.getLabel}" }
159
159
 
160
- obj.fitPosition(@parameters)
160
+ begin
161
+
162
+ obj.fitPosition(@parameters)
163
+
164
+ rescue => e
165
+
166
+ logger.error { "error while processing object #{obj.label}: #{e.message}" }
167
+
168
+ end
161
169
 
162
170
  end
163
171
 
@@ -503,6 +511,8 @@ module Cicada
503
511
 
504
512
  end
505
513
 
514
+ puts "number of image objects: #{image_objects.size}"
515
+
506
516
  image_objects
507
517
 
508
518
  end
@@ -526,6 +536,25 @@ module Cicada
526
536
  end
527
537
 
528
538
 
539
+ ##
540
+ # Fits all objects in an image or loads objects from disk if they have already
541
+ # been fit and refitting has not been requested.
542
+ #
543
+ # Saves fits to disk in the parameter-specified data directory.
544
+ #
545
+ # @return [List<ImageObject>] the fitted or loaded image objects
546
+ #
547
+ def do_and_save_fits
548
+
549
+ image_objects = load_or_fit_image_objects
550
+
551
+ FileInteraction.write_position_data(image_objects, @parameters)
552
+
553
+ image_objects
554
+
555
+ end
556
+
557
+
529
558
  ##
530
559
  # Runs the analysis.
531
560
  #
@@ -533,10 +562,8 @@ module Cicada
533
562
  #
534
563
  def go
535
564
 
536
- image_objects = load_or_fit_image_objects
565
+ image_objects = do_and_save_fits
537
566
 
538
- FileInteraction.write_position_data(image_objects, @parameters)
539
-
540
567
  pc = PositionCorrector.new(@parameters)
541
568
  pc.logger= @logger
542
569
 
@@ -632,20 +659,34 @@ module Cicada
632
659
 
633
660
  end
634
661
 
662
+
635
663
  ##
636
- # Runs analysis using a specified parameter file.
664
+ # Reads a parameters file and creates a parameter dictionary.
637
665
  #
638
- # @param [String] fn the filename of the parameter file
666
+ # @param [String] fn the filename of the parameter file
639
667
  #
640
- # @return [void]
668
+ # @return [ParameterDictionary] the parsed parameters
641
669
  #
642
- def self.run_from_parameter_file(fn)
670
+ def self.parse_parameter_file(fn)
643
671
 
644
672
  java_import Java::edu.stanford.cfuller.imageanalysistools.meta.AnalysisMetadataParserFactory
645
673
 
646
674
  parser = AnalysisMetadataParserFactory.createParserForFile(fn)
647
675
 
648
- p = parser.parseFileToParameterDictionary(fn)
676
+ parser.parseFileToParameterDictionary(fn)
677
+
678
+ end
679
+
680
+ ##
681
+ # Runs analysis using a specified parameter file.
682
+ #
683
+ # @param [String] fn the filename of the parameter file
684
+ #
685
+ # @return [void]
686
+ #
687
+ def self.run_from_parameter_file(fn)
688
+
689
+ p = parse_parameter_file(fn)
649
690
 
650
691
  c = new(p)
651
692
 
@@ -27,6 +27,7 @@
27
27
  require 'ostruct'
28
28
  require 'base64'
29
29
  require 'rexml/document'
30
+ require 'csv'
30
31
 
31
32
  require 'rimageanalysistools'
32
33
  require 'rimageanalysistools/get_image'
@@ -142,6 +143,9 @@ module Cicada
142
143
  # extension on position data (image object) files.
143
144
  POS_XML_EXTENSION = "_position_data.xml"
144
145
 
146
+ # extension on human-friendly position data (image object) files.
147
+ POS_HUMAN_EXTENSION = "_position_data.csv"
148
+
145
149
  # extension on the correction files
146
150
  CORR_XML_EXTENSION = "_correction.xml"
147
151
 
@@ -178,6 +182,20 @@ module Cicada
178
182
  File.expand_path(p[:basename_set].split(MULTI_NAME_SEP)[0] + POS_XML_EXTENSION, dir)
179
183
  end
180
184
 
185
+
186
+ ##
187
+ # Gets the filename to which human-friendly-formatted object positions will be written.
188
+ #
189
+ # @param [ParameterDictionary, Hash] p a hash-like object specifying the filename for the positions.
190
+ #
191
+ # @return [String] the absolute path to the position file.
192
+ #
193
+ def self.human_friendly_position_data_filename(p)
194
+ dir = p[:data_directory]
195
+ File.expand_path(p[:basename_set].split(MULTI_NAME_SEP)[0] + POS_HUMAN_EXTENSION, dir)
196
+ end
197
+
198
+
181
199
  ##
182
200
  # Gets the filename of data to use for in situ correction from a parameter dictionary.
183
201
  #
@@ -308,6 +326,10 @@ module Cicada
308
326
 
309
327
  write_position_data_file(image_objects,fn)
310
328
 
329
+ fn2 = human_friendly_position_data_filename(p)
330
+
331
+ write_human_friendly_position_data_file(image_objects, fn2)
332
+
311
333
  end
312
334
 
313
335
  ##
@@ -328,6 +350,46 @@ module Cicada
328
350
 
329
351
  end
330
352
 
353
+ ##
354
+ # Writes the provided image objects to a human-readable file
355
+ # at the location specified.
356
+ #
357
+ # @see write_position_data_file
358
+ #
359
+ def self.write_human_friendly_position_data_file(image_objects, fn)
360
+
361
+ CSV.open(fn, 'wb') do |csv|
362
+
363
+ obj = image_objects[0]
364
+
365
+ n_channels = obj.getFitParametersByChannel.size
366
+
367
+ headers = ["object_id"]
368
+ n_channels.times do |i|
369
+ headers.concat(["pos#{i}_x", "pos#{i}_y", "pos#{i}_z"])
370
+ end
371
+
372
+ csv << headers
373
+
374
+ image_objects.each do |im_obj|
375
+
376
+ row = [im_obj.getLabel]
377
+
378
+ n_channels.times do |i|
379
+
380
+ row.concat(im_obj.getPositionForChannel(i).toArray)
381
+
382
+ end
383
+
384
+ csv << row
385
+
386
+ end
387
+
388
+ end
389
+
390
+ end
391
+
392
+
331
393
  ##
332
394
  # Gets the filename for storing/reading the correction based upon the supplied parameter dictionary.
333
395
  #
@@ -26,7 +26,7 @@
26
26
 
27
27
  module Cicada
28
28
 
29
- VERSION = "0.9.2"
29
+ VERSION = "0.9.3"
30
30
 
31
31
  end
32
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cicada
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: java
7
7
  authors:
@@ -65,6 +65,24 @@ dependencies:
65
65
  none: false
66
66
  prerelease: false
67
67
  type: :runtime
68
+ - !ruby/object:Gem::Dependency
69
+ name: trollop
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: !binary |-
75
+ MA==
76
+ none: false
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: !binary |-
82
+ MA==
83
+ none: false
84
+ prerelease: false
85
+ type: :runtime
68
86
  - !ruby/object:Gem::Dependency
69
87
  name: rspec
70
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -87,11 +105,13 @@ description: CICADA (Colocalization and In-situ Correction of Aberration for Dis
87
105
  email: cjfuller@gmail.com
88
106
  executables:
89
107
  - cicada
108
+ - cicada_fit_only
90
109
  extensions: []
91
110
  extra_rdoc_files: []
92
111
  files:
93
112
  - lib/cicada.rb
94
113
  - lib/cicada/cicada_main.rb
114
+ - lib/cicada/aberration_map.rb
95
115
  - lib/cicada/file_interaction.rb
96
116
  - lib/cicada/mutable_matrix.rb
97
117
  - lib/cicada/version.rb
@@ -105,6 +125,8 @@ files:
105
125
  - spec/cicada/correction/correction_spec.rb
106
126
  - spec/cicada/fitting/p3d_fitter_spec.rb
107
127
  - bin/cicada
128
+ - bin/cicada_generate_map
129
+ - bin/cicada_fit_only
108
130
  homepage: http://github.com/cjfuller/cicada
109
131
  licenses:
110
132
  - MIT