Class: Transrate::Transrater
- Inherits:
-
Object
- Object
- Transrate::Transrater
- Defined in:
- lib/transrate/transrater.rb
Overview
A transrater runs all types of metrics on an assembly.
Instance Attribute Summary collapse
-
#assembly ⇒ Assembly, String
readonly
An Assembly or the path to an assembly.
-
#comparative_metrics ⇒ hash
readonly
The comparative metrics if they have been calculated.
-
#read_metrics(left, right) ⇒ Hash
readonly
The read metrics if they have been calculated.
Instance Method Summary collapse
- #all_metrics(left, right) ⇒ Object
- #assembly_metrics ⇒ Object
- #assembly_optimal_score(prefix) ⇒ Object
-
#assembly_score ⇒ Integer
Reduce all metrics for the assembly to a single quality score by taking the geometric mean of the scores for all contigs and multiplying it by the proportion of fragments whose most likely mapping is consistent with the assembly.
- #good_contigs ⇒ Object
-
#initialize(assembly, reference, threads: 1) ⇒ Transrater
constructor
A new Transrater.
-
#run(left = nil, right = nil) ⇒ Object
Run all analyses.
Constructor Details
#initialize(assembly, reference, threads: 1) ⇒ Transrater
A new Transrater
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/transrate/transrater.rb', line 23 def initialize(assembly, reference, threads: 1) if assembly if assembly.is_a?(Assembly) @assembly = assembly else @assembly = Assembly.new(assembly) end @read_metrics = ReadMetrics.new @assembly else raise TransrateError.new("assembly is nil") end if reference if reference.is_a?(Assembly) @reference = reference else @reference = Assembly.new(reference) end @comparative_metrics = ComparativeMetrics.new(@assembly, @reference, threads) end @threads = threads end |
Instance Attribute Details
#assembly ⇒ Assembly, String (readonly)
Returns an Assembly or the path to an assembly.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/transrate/transrater.rb', line 11 class Transrater attr_reader :assembly attr_reader :read_metrics # A new Transrater # # @param assembly [Assembly, String] the Assembly or path to the FASTA # @param reference [Assembly, String] the reference Assembly or # path to the FASTA # @param left [String] path to the left reads # @param right [String] path to the right reads def initialize(assembly, reference, threads: 1) if assembly if assembly.is_a?(Assembly) @assembly = assembly else @assembly = Assembly.new(assembly) end @read_metrics = ReadMetrics.new @assembly else raise TransrateError.new("assembly is nil") end if reference if reference.is_a?(Assembly) @reference = reference else @reference = Assembly.new(reference) end @comparative_metrics = ComparativeMetrics.new(@assembly, @reference, threads) end @threads = threads end # Run all analyses # # @param left [String] path to the left reads # @param right [String] path to the right reads def run left=nil, right=nil assembly_metrics if left && right read_metrics left, right end comparative_metrics end # Reduce all metrics for the assembly to a single quality score # by taking the geometric mean of the scores for all contigs # and multiplying it by the proportion of fragments whose most likely # mapping is consistent with the assembly # @return [Integer] the assembly score def assembly_score if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end return @score_optimiser.raw_score end def assembly_optimal_score prefix if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end return @score_optimiser.optimal_score prefix end def assembly_metrics @assembly.run unless @assembly.has_run @assembly end def read_metrics(left, right) unless @read_metrics.has_run @read_metrics.run(left, right, threads: @threads) end if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end score, cutoff = @score_optimiser.optimal_score @assembly.classify_contigs cutoff @read_metrics end def good_contigs { :good_contigs => @assembly.good_contigs, :p_good_contigs => @assembly.good_contigs/@assembly.size.to_f } end def comparative_metrics @comparative_metrics.run unless @comparative_metrics.has_run @comparative_metrics end def all_metrics left, right self.run(left, right) all = @assembly.basic_stats all.merge!(@read_metrics.read_stats) all.merge!(@comparative_metrics.comp_stats) all[:score] = @score all end end |
#comparative_metrics ⇒ hash (readonly)
Returns the comparative metrics if they have been calculated.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/transrate/transrater.rb', line 11 class Transrater attr_reader :assembly attr_reader :read_metrics # A new Transrater # # @param assembly [Assembly, String] the Assembly or path to the FASTA # @param reference [Assembly, String] the reference Assembly or # path to the FASTA # @param left [String] path to the left reads # @param right [String] path to the right reads def initialize(assembly, reference, threads: 1) if assembly if assembly.is_a?(Assembly) @assembly = assembly else @assembly = Assembly.new(assembly) end @read_metrics = ReadMetrics.new @assembly else raise TransrateError.new("assembly is nil") end if reference if reference.is_a?(Assembly) @reference = reference else @reference = Assembly.new(reference) end @comparative_metrics = ComparativeMetrics.new(@assembly, @reference, threads) end @threads = threads end # Run all analyses # # @param left [String] path to the left reads # @param right [String] path to the right reads def run left=nil, right=nil assembly_metrics if left && right read_metrics left, right end comparative_metrics end # Reduce all metrics for the assembly to a single quality score # by taking the geometric mean of the scores for all contigs # and multiplying it by the proportion of fragments whose most likely # mapping is consistent with the assembly # @return [Integer] the assembly score def assembly_score if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end return @score_optimiser.raw_score end def assembly_optimal_score prefix if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end return @score_optimiser.optimal_score prefix end def assembly_metrics @assembly.run unless @assembly.has_run @assembly end def read_metrics(left, right) unless @read_metrics.has_run @read_metrics.run(left, right, threads: @threads) end if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end score, cutoff = @score_optimiser.optimal_score @assembly.classify_contigs cutoff @read_metrics end def good_contigs { :good_contigs => @assembly.good_contigs, :p_good_contigs => @assembly.good_contigs/@assembly.size.to_f } end def comparative_metrics @comparative_metrics.run unless @comparative_metrics.has_run @comparative_metrics end def all_metrics left, right self.run(left, right) all = @assembly.basic_stats all.merge!(@read_metrics.read_stats) all.merge!(@comparative_metrics.comp_stats) all[:score] = @score all end end |
#read_metrics(left, right) ⇒ Hash (readonly)
Returns the read metrics if they have been calculated.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/transrate/transrater.rb', line 11 class Transrater attr_reader :assembly attr_reader :read_metrics # A new Transrater # # @param assembly [Assembly, String] the Assembly or path to the FASTA # @param reference [Assembly, String] the reference Assembly or # path to the FASTA # @param left [String] path to the left reads # @param right [String] path to the right reads def initialize(assembly, reference, threads: 1) if assembly if assembly.is_a?(Assembly) @assembly = assembly else @assembly = Assembly.new(assembly) end @read_metrics = ReadMetrics.new @assembly else raise TransrateError.new("assembly is nil") end if reference if reference.is_a?(Assembly) @reference = reference else @reference = Assembly.new(reference) end @comparative_metrics = ComparativeMetrics.new(@assembly, @reference, threads) end @threads = threads end # Run all analyses # # @param left [String] path to the left reads # @param right [String] path to the right reads def run left=nil, right=nil assembly_metrics if left && right read_metrics left, right end comparative_metrics end # Reduce all metrics for the assembly to a single quality score # by taking the geometric mean of the scores for all contigs # and multiplying it by the proportion of fragments whose most likely # mapping is consistent with the assembly # @return [Integer] the assembly score def assembly_score if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end return @score_optimiser.raw_score end def assembly_optimal_score prefix if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end return @score_optimiser.optimal_score prefix end def assembly_metrics @assembly.run unless @assembly.has_run @assembly end def read_metrics(left, right) unless @read_metrics.has_run @read_metrics.run(left, right, threads: @threads) end if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end score, cutoff = @score_optimiser.optimal_score @assembly.classify_contigs cutoff @read_metrics end def good_contigs { :good_contigs => @assembly.good_contigs, :p_good_contigs => @assembly.good_contigs/@assembly.size.to_f } end def comparative_metrics @comparative_metrics.run unless @comparative_metrics.has_run @comparative_metrics end def all_metrics left, right self.run(left, right) all = @assembly.basic_stats all.merge!(@read_metrics.read_stats) all.merge!(@comparative_metrics.comp_stats) all[:score] = @score all end end |
Instance Method Details
#all_metrics(left, right) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/transrate/transrater.rb', line 108 def all_metrics left, right self.run(left, right) all = @assembly.basic_stats all.merge!(@read_metrics.read_stats) all.merge!(@comparative_metrics.comp_stats) all[:score] = @score all end |
#assembly_metrics ⇒ Object
79 80 81 82 |
# File 'lib/transrate/transrater.rb', line 79 def assembly_metrics @assembly.run unless @assembly.has_run @assembly end |
#assembly_optimal_score(prefix) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/transrate/transrater.rb', line 72 def assembly_optimal_score prefix if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end return @score_optimiser.optimal_score prefix end |
#assembly_score ⇒ Integer
Reduce all metrics for the assembly to a single quality score by taking the geometric mean of the scores for all contigs and multiplying it by the proportion of fragments whose most likely mapping is consistent with the assembly
65 66 67 68 69 70 |
# File 'lib/transrate/transrater.rb', line 65 def assembly_score if !@score_optimiser @score_optimiser = ScoreOptimiser.new(@assembly, @read_metrics) end return @score_optimiser.raw_score end |
#good_contigs ⇒ Object
96 97 98 99 100 101 |
# File 'lib/transrate/transrater.rb', line 96 def good_contigs { :good_contigs => @assembly.good_contigs, :p_good_contigs => @assembly.good_contigs/@assembly.size.to_f } end |
#run(left = nil, right = nil) ⇒ Object
Run all analyses
52 53 54 55 56 57 58 |
# File 'lib/transrate/transrater.rb', line 52 def run left=nil, right=nil assembly_metrics if left && right read_metrics left, right end comparative_metrics end |