flex-station-data 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/flex-station +16 -0
- data/bin/flex-station-linear-regression +57 -0
- data/bin/flex-station-sample-data +48 -0
- data/flex-station-data.gemspec +40 -0
- data/lib/flex_station_data/concerns/service.rb +19 -0
- data/lib/flex_station_data/linear_regression.rb +39 -0
- data/lib/flex_station_data/plate.rb +11 -0
- data/lib/flex_station_data/readings.rb +16 -0
- data/lib/flex_station_data/sample.rb +16 -0
- data/lib/flex_station_data/services/compute_mean.rb +21 -0
- data/lib/flex_station_data/services/load_plates.rb +28 -0
- data/lib/flex_station_data/services/parse_plate.rb +27 -0
- data/lib/flex_station_data/services/parse_plate_readings.rb +91 -0
- data/lib/flex_station_data/services/parse_plate_samples.rb +49 -0
- data/lib/flex_station_data/version.rb +3 -0
- data/lib/flex_station_data/wells.rb +29 -0
- data/lib/flex_station_data.rb +5 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3d76fd5097e3546360a3a8b231430542da6e5d8102347f463ca864bc28819190
|
4
|
+
data.tar.gz: 9569b8003f47b21e5607bfcf2c77c9ae6c5069ffc89a66b9765a38bf8262d2de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: deb5310fcc6d650fe47840d49ac56db82689024dad4d8b932d2ccacf92277802d4e77fad03b5f0541cbab1f396f852f8fb53c7442cc9e8f6c08519826f74183b
|
7
|
+
data.tar.gz: d4e54265444e5866f0b58a5bce251e8f739eeea7d3bc6cd738919b8197231566f1924b738f3aa95f041e33a0aa28ebcc0f5fefcb3b1b9d749dacd51b3142ce55
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at john@carney.id.au. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flex-station-data (0.1.0)
|
5
|
+
activesupport
|
6
|
+
linefit
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.0)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
17
|
+
coderay (1.1.2)
|
18
|
+
concurrent-ruby (1.1.5)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
i18n (1.6.0)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
linefit (0.3.4)
|
23
|
+
method_source (0.9.2)
|
24
|
+
minitest (5.11.3)
|
25
|
+
pry (0.12.2)
|
26
|
+
coderay (~> 1.1.0)
|
27
|
+
method_source (~> 0.9.0)
|
28
|
+
rake (10.5.0)
|
29
|
+
rspec (3.8.0)
|
30
|
+
rspec-core (~> 3.8.0)
|
31
|
+
rspec-expectations (~> 3.8.0)
|
32
|
+
rspec-mocks (~> 3.8.0)
|
33
|
+
rspec-core (3.8.2)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-expectations (3.8.4)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-mocks (3.8.1)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.8.0)
|
41
|
+
rspec-support (3.8.2)
|
42
|
+
thread_safe (0.3.6)
|
43
|
+
tzinfo (1.2.5)
|
44
|
+
thread_safe (~> 0.1)
|
45
|
+
zeitwerk (2.1.9)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bundler (~> 2.0)
|
52
|
+
flex-station-data!
|
53
|
+
pry
|
54
|
+
rake (~> 10.0)
|
55
|
+
rspec (~> 3.8)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 John Carney
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# FlexStationData
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flex_station_data`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'flex-station-data'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install flex-station-data
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/johncarney/flex-station-data. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the FlexStationData project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/johncarney/flex-station-data/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/flex-station
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
case command = ARGV.first
|
6
|
+
when "sample-data"
|
7
|
+
system(Pathname(__dir__).join("flex-station-sample-data").to_path, *ARGV.drop(1))
|
8
|
+
when "linear-regression"
|
9
|
+
system(Pathname(__dir__).join("flex-station-linear-regression").to_path, *ARGV.drop(1))
|
10
|
+
when nil
|
11
|
+
$stderr.puts "USAGE: flex-station <command>"
|
12
|
+
exit(1)
|
13
|
+
else
|
14
|
+
$stderr.puts "Unrecognised command: #{command}"
|
15
|
+
exit(1)
|
16
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
|
5
|
+
require "flex_station_data/services/load_plates"
|
6
|
+
require "flex_station_data/linear_regression"
|
7
|
+
|
8
|
+
module FlexStationData
|
9
|
+
class LinearRegressionApp
|
10
|
+
include Concerns::Service
|
11
|
+
|
12
|
+
attr_reader :args
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
@args = args
|
16
|
+
end
|
17
|
+
|
18
|
+
def files
|
19
|
+
@files ||= args.map { |arg| Pathname(arg) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def plates
|
23
|
+
@plates ||= files.map do |file|
|
24
|
+
[ file, LoadPlates.call(file) ]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def call
|
29
|
+
plates.each do |file, file_plates|
|
30
|
+
puts "File: #{file.to_path}"
|
31
|
+
file_plates.each_with_index.map do |plate, plate_index|
|
32
|
+
puts "Plate: #{plate_index + 1}"
|
33
|
+
plate.samples.each do |sample|
|
34
|
+
readings_labels = sample.readings.map(&:label)
|
35
|
+
puts "Sample #{sample.label}"
|
36
|
+
CSV do |out|
|
37
|
+
readings = [*sample.readings, sample.mean]
|
38
|
+
out << ["time", *readings.map(&:label)]
|
39
|
+
plate.times.zip(*readings.map(&:values)).each do |row|
|
40
|
+
out << row
|
41
|
+
end
|
42
|
+
|
43
|
+
regression_factory = LinearRegression.method(:new).curry(2)[plate.times]
|
44
|
+
regressions = readings.map(&:values).map(®ression_factory)
|
45
|
+
out << ["slope", *regressions.map(&:slope)]
|
46
|
+
out << ["R²", *regressions.map(&:r_squared)]
|
47
|
+
|
48
|
+
out << []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
FlexStationData::LinearRegressionApp.call(*ARGV)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "flex_station_data/services/load_plates"
|
4
|
+
|
5
|
+
module FlexStationData
|
6
|
+
class SampleDataApp
|
7
|
+
include Concerns::Service
|
8
|
+
|
9
|
+
attr_reader :args
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
@args = args
|
13
|
+
end
|
14
|
+
|
15
|
+
def files
|
16
|
+
@files ||= args.map { |arg| Pathname(arg) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def plates
|
20
|
+
@plates ||= files.map do |file|
|
21
|
+
[ file, LoadPlates.call(file) ]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def call
|
26
|
+
plates.each do |file, file_plates|
|
27
|
+
puts "File: #{file.to_path}"
|
28
|
+
file_plates.each_with_index.map do |plate, plate_index|
|
29
|
+
puts "Plate: #{plate_index + 1}"
|
30
|
+
plate.samples.each do |sample|
|
31
|
+
readings_labels = sample.readings.map(&:label)
|
32
|
+
puts "Sample #{sample.label}"
|
33
|
+
CSV do |out|
|
34
|
+
mean = sample.mean
|
35
|
+
out << ["time", *sample.readings.map(&:label), mean.label]
|
36
|
+
plate.times.zip(*sample.readings.map(&:values), mean.values).each do |row|
|
37
|
+
out << row
|
38
|
+
end
|
39
|
+
out << []
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
FlexStationData::SampleDataApp.call(*ARGV)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "flex_station_data/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "flex-station-data"
|
7
|
+
spec.version = FlexStationData::VERSION
|
8
|
+
spec.authors = ["John Carney"]
|
9
|
+
spec.email = ["john@carney.id.au"]
|
10
|
+
|
11
|
+
spec.summary = %q{Data analysis tool for FlexStation microplate reader}
|
12
|
+
spec.description = %q{Data analysis tool for FlexStation microplate reader}
|
13
|
+
spec.homepage = "https://github.com/johncarney/flex-station-data"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = "https://github.com/johncarney/flex-station-data"
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/johncarney/flex-station-data"
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "bin"
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.required_ruby_version = "~> 2.3"
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
36
|
+
spec.add_development_dependency "pry"
|
37
|
+
|
38
|
+
spec.add_runtime_dependency "activesupport"
|
39
|
+
spec.add_runtime_dependency "linefit"
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module FlexStationData
|
4
|
+
module Concerns
|
5
|
+
module Service
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
def call(*args, &block)
|
10
|
+
new(*args).call(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_proc
|
14
|
+
Proc.new(&method(:call))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "active_support/core_ext"
|
2
|
+
require "linefit"
|
3
|
+
|
4
|
+
module FlexStationData
|
5
|
+
class LinearRegression
|
6
|
+
attr_reader :x, :y
|
7
|
+
|
8
|
+
def initialize(x, y)
|
9
|
+
@x = x
|
10
|
+
@y = y
|
11
|
+
end
|
12
|
+
|
13
|
+
def slope
|
14
|
+
coefficients[1]
|
15
|
+
end
|
16
|
+
|
17
|
+
def intercept
|
18
|
+
coefficients[0]
|
19
|
+
end
|
20
|
+
|
21
|
+
def r_squared
|
22
|
+
@r_squared ||= line_fit.rSquared
|
23
|
+
rescue TypeError
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def coefficients
|
30
|
+
@coefficients ||= line_fit.coefficients
|
31
|
+
rescue TypeError
|
32
|
+
[ nil, nil ]
|
33
|
+
end
|
34
|
+
|
35
|
+
def line_fit
|
36
|
+
@line_fit ||= LineFit.new.tap { |lf| lf.setData(x, y) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "flex_station_data/services/compute_mean"
|
2
|
+
|
3
|
+
module FlexStationData
|
4
|
+
class Readings
|
5
|
+
attr_reader :label, :values
|
6
|
+
|
7
|
+
def initialize(label, values)
|
8
|
+
@label = label
|
9
|
+
@values = values
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.mean(*readings, label: "mean")
|
13
|
+
new(label, readings.map(&:values).transpose.map(&ComputeMean))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "flex_station_data/readings"
|
2
|
+
|
3
|
+
module FlexStationData
|
4
|
+
class Sample
|
5
|
+
attr_reader :label, :readings
|
6
|
+
|
7
|
+
def initialize(label, readings)
|
8
|
+
@label = label
|
9
|
+
@readings = readings
|
10
|
+
end
|
11
|
+
|
12
|
+
def mean
|
13
|
+
@mean ||= Readings.mean(*readings)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "active_support/core_ext"
|
2
|
+
|
3
|
+
require "flex_station_data/concerns/service"
|
4
|
+
|
5
|
+
module FlexStationData
|
6
|
+
class ComputeMean
|
7
|
+
include Concerns::Service
|
8
|
+
|
9
|
+
attr_reader :values
|
10
|
+
|
11
|
+
def initialize(values)
|
12
|
+
@values = values
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
Float(values.sum) / values.size
|
17
|
+
rescue ArgumentError, TypeError, NoMethodError
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "csv"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
|
4
|
+
require "flex_station_data/services/parse_plate"
|
5
|
+
|
6
|
+
module FlexStationData
|
7
|
+
class LoadPlates
|
8
|
+
include Concerns::Service
|
9
|
+
|
10
|
+
attr_reader :file
|
11
|
+
|
12
|
+
def initialize(file)
|
13
|
+
@file = file
|
14
|
+
end
|
15
|
+
|
16
|
+
def data
|
17
|
+
CSV.read(file, headers: false).to_a
|
18
|
+
end
|
19
|
+
|
20
|
+
def data_blocks
|
21
|
+
@data_blocks ||= data.split { |row| row[0] == "Plate:" }.drop(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
def call
|
25
|
+
data_blocks.map(&FlexStationData::ParsePlate)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "active_support/core_ext"
|
2
|
+
|
3
|
+
require "flex_station_data/services/parse_plate_readings"
|
4
|
+
require "flex_station_data/services/parse_plate_samples"
|
5
|
+
require "flex_station_data/plate"
|
6
|
+
|
7
|
+
module FlexStationData
|
8
|
+
class ParsePlate
|
9
|
+
include Concerns::Service
|
10
|
+
|
11
|
+
attr_reader :plate_data
|
12
|
+
|
13
|
+
def initialize(plate_data)
|
14
|
+
@plate_data = plate_data
|
15
|
+
end
|
16
|
+
|
17
|
+
def data_blocks
|
18
|
+
plate_data.split { |row| row[0] == "~End" }
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
times, temperatures, wells = ParsePlateReadings.call(data_blocks[0])
|
23
|
+
samples = ParsePlateSamples.call(data_blocks[1], wells)
|
24
|
+
Plate.new(times, temperatures, samples)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require "active_support/core_ext"
|
2
|
+
|
3
|
+
require "flex_station_data/wells"
|
4
|
+
require "flex_station_data/concerns/service"
|
5
|
+
|
6
|
+
module FlexStationData
|
7
|
+
class ParsePlateReadings
|
8
|
+
include Concerns::Service
|
9
|
+
|
10
|
+
delegate :parse_time, :parse_value, :parse_row, to: :class
|
11
|
+
|
12
|
+
def initialize(plate_readings_block)
|
13
|
+
@plate_readings_block = plate_readings_block
|
14
|
+
end
|
15
|
+
|
16
|
+
def column_count
|
17
|
+
@column_count ||= headers.reverse.drop_while(&:blank?).size
|
18
|
+
end
|
19
|
+
|
20
|
+
def parsed_rows
|
21
|
+
@parsed_rows ||= begin
|
22
|
+
rows = plate_readings_data.map { |row| parse_row(row[0...column_count]) }
|
23
|
+
rows.select { |row| row.any?(&:present?) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def parsed_columns
|
28
|
+
@parsed_columns ||= parsed_rows.transpose
|
29
|
+
end
|
30
|
+
|
31
|
+
def times
|
32
|
+
@times ||= parsed_columns[0].compact
|
33
|
+
end
|
34
|
+
|
35
|
+
def temperatures
|
36
|
+
@temperatures ||= parsed_columns[1].compact
|
37
|
+
end
|
38
|
+
|
39
|
+
def values
|
40
|
+
@values ||= parsed_columns.drop(2)
|
41
|
+
end
|
42
|
+
|
43
|
+
def wells_row_count
|
44
|
+
parsed_rows.size / times.size
|
45
|
+
end
|
46
|
+
|
47
|
+
def plate_readings_matrix
|
48
|
+
values.map do |values_column|
|
49
|
+
values_column.each_slice(wells_row_count).to_a.transpose
|
50
|
+
end.transpose
|
51
|
+
end
|
52
|
+
|
53
|
+
def wells
|
54
|
+
Wells.new(plate_readings_matrix)
|
55
|
+
end
|
56
|
+
|
57
|
+
def call
|
58
|
+
[ times, temperatures, wells ]
|
59
|
+
end
|
60
|
+
|
61
|
+
class << self
|
62
|
+
def parse_time(t)
|
63
|
+
return if t.blank?
|
64
|
+
|
65
|
+
h, m, s = t.split(":").map(&:to_i)
|
66
|
+
h * 60.0 + m + s / 60.0
|
67
|
+
end
|
68
|
+
|
69
|
+
def parse_value(v)
|
70
|
+
return Float(v) rescue v.presence
|
71
|
+
end
|
72
|
+
|
73
|
+
def parse_row(row)
|
74
|
+
time, temperature, *values = row
|
75
|
+
[ parse_time(time), parse_value(temperature), *values.map(&method(:parse_value)) ]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def headers
|
82
|
+
plate_readings_block.first
|
83
|
+
end
|
84
|
+
|
85
|
+
def plate_readings_data
|
86
|
+
@plate_readings_data ||= plate_readings_block.drop(1)
|
87
|
+
end
|
88
|
+
|
89
|
+
attr_reader :plate_readings_block
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "flex_station_data/readings"
|
2
|
+
require "flex_station_data/concerns/service"
|
3
|
+
|
4
|
+
require "flex_station_data/sample"
|
5
|
+
|
6
|
+
module FlexStationData
|
7
|
+
class ParsePlateSamples
|
8
|
+
include Concerns::Service
|
9
|
+
|
10
|
+
def initialize(sample_map_block, wells)
|
11
|
+
@sample_map_block = sample_map_block
|
12
|
+
@wells = wells
|
13
|
+
end
|
14
|
+
|
15
|
+
def map_rows
|
16
|
+
@map_rows ||= begin
|
17
|
+
rows = sample_map_block.drop_while { |row| row[0] != "Sample" }.drop(1)
|
18
|
+
rows = rows.map { |row| row.map(&:presence) }
|
19
|
+
rows.take_while { |row| row.any?(&:present?) }.to_a
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def map_columns
|
24
|
+
@map_columns ||= map_rows.transpose
|
25
|
+
end
|
26
|
+
|
27
|
+
def labels
|
28
|
+
@labels ||= map_columns[0].compact
|
29
|
+
end
|
30
|
+
|
31
|
+
def wells_per_sample
|
32
|
+
map_rows.size / labels.size
|
33
|
+
end
|
34
|
+
|
35
|
+
def sample_map
|
36
|
+
@sample_map ||= map_columns[1].each_slice(wells_per_sample).to_a
|
37
|
+
end
|
38
|
+
|
39
|
+
def call
|
40
|
+
labels.zip(sample_map).map do |label, well_labels|
|
41
|
+
Sample.new(label, well_labels.map(&wells.method(:readings)))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
attr_reader :sample_map_block, :wells
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "flex_station_data/readings"
|
2
|
+
|
3
|
+
module FlexStationData
|
4
|
+
class Wells
|
5
|
+
def initialize(plate_readings_matrix)
|
6
|
+
@plate_readings_matrix = plate_readings_matrix
|
7
|
+
end
|
8
|
+
|
9
|
+
def readings(well_label)
|
10
|
+
well_index[well_label] ||= begin
|
11
|
+
row, column = parse_well_label(well_label)
|
12
|
+
Readings.new(well_label, plate_readings_matrix[row][column])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_well_label(well_label)
|
17
|
+
row, column = well_label.scan(/\A([A-Z])(\d+)\z/).first
|
18
|
+
[ row.ord - "A".ord, column.to_i - 1 ]
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def well_index
|
24
|
+
@well_index ||= {}
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :plate_readings_matrix
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flex-station-data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Carney
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: linefit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Data analysis tool for FlexStation microplate reader
|
98
|
+
email:
|
99
|
+
- john@carney.id.au
|
100
|
+
executables:
|
101
|
+
- flex-station
|
102
|
+
- flex-station-linear-regression
|
103
|
+
- flex-station-sample-data
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- ".gitignore"
|
108
|
+
- ".rspec"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/flex-station
|
116
|
+
- bin/flex-station-linear-regression
|
117
|
+
- bin/flex-station-sample-data
|
118
|
+
- flex-station-data.gemspec
|
119
|
+
- lib/flex_station_data.rb
|
120
|
+
- lib/flex_station_data/concerns/service.rb
|
121
|
+
- lib/flex_station_data/linear_regression.rb
|
122
|
+
- lib/flex_station_data/plate.rb
|
123
|
+
- lib/flex_station_data/readings.rb
|
124
|
+
- lib/flex_station_data/sample.rb
|
125
|
+
- lib/flex_station_data/services/compute_mean.rb
|
126
|
+
- lib/flex_station_data/services/load_plates.rb
|
127
|
+
- lib/flex_station_data/services/parse_plate.rb
|
128
|
+
- lib/flex_station_data/services/parse_plate_readings.rb
|
129
|
+
- lib/flex_station_data/services/parse_plate_samples.rb
|
130
|
+
- lib/flex_station_data/version.rb
|
131
|
+
- lib/flex_station_data/wells.rb
|
132
|
+
homepage: https://github.com/johncarney/flex-station-data
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata:
|
136
|
+
homepage_uri: https://github.com/johncarney/flex-station-data
|
137
|
+
source_code_uri: https://github.com/johncarney/flex-station-data
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '2.3'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.7.6
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Data analysis tool for FlexStation microplate reader
|
158
|
+
test_files: []
|