Module: MutationsCLI
- Defined in:
- lib/bio-sam-mutation/mutationscli.rb
Class Attribute Summary collapse
-
.default_species ⇒ Object
Returns the value of attribute default_species.
-
.tag_to_add ⇒ Object
Returns the value of attribute tag_to_add.
Class Method Summary collapse
-
.call_mutations(sam, config) ⇒ Object
Returns a MutationArray.
- .call_mutations_given_product(sam, config) ⇒ Object
-
.construct_products(config_hash) ⇒ Object
Allows multiple amplicons to be considered Organises the configuration data by sequence start.
- .not_included_file?(config, input) ⇒ Boolean
- .set_defaults(config_hash) ⇒ Object
- .tag(sam, config, species = MutationsCLI.default_species) ⇒ Object
Class Attribute Details
.default_species ⇒ Object
Returns the value of attribute default_species.
5 6 7 |
# File 'lib/bio-sam-mutation/mutationscli.rb', line 5 def default_species @default_species end |
.tag_to_add ⇒ Object
Returns the value of attribute tag_to_add.
5 6 7 |
# File 'lib/bio-sam-mutation/mutationscli.rb', line 5 def tag_to_add @tag_to_add end |
Class Method Details
.call_mutations(sam, config) ⇒ Object
Returns a MutationArray
39 40 41 42 43 44 45 |
# File 'lib/bio-sam-mutation/mutationscli.rb', line 39 def self.call_mutations sam, config unless config[:single_product] first_bases = sam.seq[0..config[:start_length]-1].upcase config[first_bases] ? config = config[first_bases] : return end MutationsCLI.call_mutations_given_product sam, config end |
.call_mutations_given_product(sam, config) ⇒ Object
47 48 49 50 51 |
# File 'lib/bio-sam-mutation/mutationscli.rb', line 47 def self.call_mutations_given_product sam, config # Stop if a search file is specified, and this isn't it. return if MutationsCLI.not_included_file?(config, ARGF) sam.mutations(config[:offset],config[:length],config[:translation_start]) end |
.construct_products(config_hash) ⇒ Object
Allows multiple amplicons to be considered Organises the configuration data by sequence start
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bio-sam-mutation/mutationscli.rb', line 68 def self.construct_products config_hash new_hash = {} config_hash[:products].each do |product_name, config| new_hash[config[:start]] = config new_hash[config[:start]][:output] ||= product_name + ".sam" new_hash[config[:start]][:outfile] = File.open(new_hash[config[:start]][:output],'w') end lengths = new_hash.keys.map!(&:length).uniq new_hash[:start_length] = lengths[0] warn "Start sequences given must be same length" if lengths.size > 1 new_hash end |
.not_included_file?(config, input) ⇒ Boolean
53 54 55 |
# File 'lib/bio-sam-mutation/mutationscli.rb', line 53 def self.not_included_file? config, input config[:file] && input.filename !~ config[:file] end |
.set_defaults(config_hash) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/bio-sam-mutation/mutationscli.rb', line 57 def self.set_defaults config_hash config_hash[:start] ||= "." # i.e. regexp will match anything config_hash[:offset] ||= 1 config_hash[:length] ||= 100 config_hash[:translation_start] ||= 1 config_hash[:file] = Regexp.new(config_hash[:file]) if config_hash[:file] config_hash end |
.tag(sam, config, species = MutationsCLI.default_species) ⇒ Object
8 9 10 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 |
# File 'lib/bio-sam-mutation/mutationscli.rb', line 8 def self.tag (sam, config, species=MutationsCLI.default_species) # With multiple files, could end up with duplicate headers... if sam.match(/^@/) if config[:single_product] config[:outfile].puts sam return else # If we have multiple products, output sam headers to each output file config.each do |key, config_hash| next if [:start_length].include? key config_hash[:outfile].puts sam end return end end sam = Bio::DB::Alignment.new(sam) # DRY up: unless config[:single_product] first_bases = sam.seq[0..config[:start_length]-1].upcase config[first_bases] ? config = config[first_bases] : return end # Stop if a search file is specified, and this isn't it. return if MutationsCLI.not_included_file?(config, ARGF) mut_array = sam.mutations(config[:offset],config[:length],config[:translation_start]) if mut_array new_tag = Bio::DB::Tag.new(MutationsCLI.tag_to_add + ":" + mut_array.to_hgvs) config[:outfile].puts sam.add_tag(new_tag) end end |