mspire-molecular_formula 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8aa1b3d4118e17b3ca2c9092e9c355f6e376a46c
4
- data.tar.gz: 14d52e1251c536369476ec68bab41f903a366a11
3
+ metadata.gz: 61ab058e6c8b53fa54ff7c743e322e52ca866ea8
4
+ data.tar.gz: 2fb66783ec477d4d4f87df12e98b7dc7ae4ed597
5
5
  SHA512:
6
- metadata.gz: ee4729ebc0ff0276ffbd299bdec26a3eea81a05603895c1061b333031c8c22b53c1bac56789734a7e071dd776df728041f1dd67f0ca2ae4f61be6192aca87a77
7
- data.tar.gz: d6301ed9ef9b458c80b80ea92615c059f6a49bbedc15ed76c1a5f089aac3766cb2d52d7063858bbb4704080fff8ade679bc18049f0d223e44e945c33d8f4ea65
6
+ metadata.gz: 1da09fe7a26f3cf3a069bb7762aba72fe62667ab9cdf30f46ee7f1b480bbed61ebb5274d9472fff88d1b660e0b7f6a4a0d7aedee5caf6f8faf4efa88100a78e7
7
+ data.tar.gz: 41c96037b3e850df81caf5405adcdc2fe5b96105efb6db7fa4a4424bfbb9af30ecac16e272297a832f47f35412b77a69993950e794c03a2746ec66de3dd23c86
data/README.md CHANGED
@@ -21,7 +21,7 @@ mf = Mspire::MolecularFormula.new( C:3, H:4, O:2 )
21
21
  mf = Mspire::MolecularFormula.new( {C:3, H:4, O:2}, 2)
22
22
  ```
23
23
 
24
- ### Create with a string formula
24
+ ### Create with a string formula or AA seq
25
25
 
26
26
  ```ruby
27
27
  mf = Mspire::MolecularFormula[ 'C3H4O2' ]
@@ -30,11 +30,25 @@ mf = Mspire::MolecularFormula[ 'C3H4O2' ]
30
30
  mf = Mspire::MolecularFormula[ 'C3H4O2', 2 ]
31
31
  mf = Mspire::MolecularFormula[ 'C3H4O2+2' ] # alternatively
32
32
  mf = Mspire::MolecularFormula[ 'C3H4O2++' ] # alternatively
33
+
34
+ # from amino acid sequence
35
+ Mspire::MolecularFormula.from_aaseq('APEPTIDE') # .to_s => "C37H58N8O16"
36
+ Mspire::MolecularFormula.from_aaseq('APEPTIDE', -2) # w/ -2 charge .to_s => "C37H58N8O16-2"
37
+ ```
38
+
39
+ ### Output string or hash formula
40
+
41
+ ```ruby
42
+ mf = Mspire::MolecularFormula[ 'C3H4O2', 2 ]
43
+ mf.inspect # => {MolecularFormula :C=>3, :H=>4, :O=>2, @charge=2}
44
+ mf.to_s # => 'C3H4O2+2'
45
+ mf.to_s(false) # (hide charge) => 'C3H4O2'
46
+ mf.to_h # => {:C=>3, :H=>4, :O=>2}
33
47
  ```
34
48
 
35
49
  ### Arithmetic
36
50
 
37
- Walk through the arithmetic of combustion of ethene using this equation:
51
+ Walk through the arithmetic of combustion of ethene:
38
52
 
39
53
  CH2=CH2 + 3 O2 -> 2 CO2 + 2 H2O
40
54
 
@@ -48,11 +62,58 @@ two_carbon_dioxide = combustion - (water*2)
48
62
  carbon_dioxide = two_carbon_dioxide / 2
49
63
  ```
50
64
 
51
- Note that there are no methods defined on fixnum to deal with MolecularFormula
52
- objects, so fixnums need to follow the MolecularFormula (i.e., "3 * oxygen"
65
+ Note: there are no methods defined on fixnum to deal with MolecularFormula
66
+ objects, so fixnums need to go after the MolecularFormula (i.e., "3 * oxygen"
53
67
  will throw an error but "oxygen * 3" is fine)
54
68
 
69
+ ### Isotope Distribution
70
+
71
+ [Note, currently requires the fftw3 gem to be installed and accessible.]
72
+
73
+ #### isotope\_intensity\_distribution
55
74
 
56
- require 'mspire/isotope/distribution' # requires fftw gem
57
- puts butane.isotope_distribution # :total, :max, :first as arg to normalize
75
+ ```ruby
76
+ # by default normalizes by total intensity with no peak or percent cuttoff
77
+ ethene.isotope_intensity_distribution
78
+ # => [0.9777084818979036, 0.02215911350461325, 0.0001323273147371948, 7.726507349638125e-08,
79
+ # 1.7670756693524035e-11, 1.81473621216667e-15, 2.6146991408856273e-17]
80
+
81
+ # return/use only first 4 peaks and normalize by max peak
82
+ ethene.isotope_intensity_distribution(normalize: :max, peak_cutoff: 4)
83
+ # => [1.0, 0.022664335959936163, 0.00013534434566868467, 7.902669857828807e-08]
84
+
85
+ # cut at less than 0.01% total intensity and normalize by max peak
86
+ ethene.isotope_intensity_distribution(normalize: :first, percent_cutoff: 0.01)
87
+ # => [1.0, 0.022664335959936163, 0.00013534434566868467]
88
+ ```
89
+
90
+ #### isotope\_distribution
91
+
92
+ Returns an array of masses (mz's if charged) and intensities. Although the
93
+ monoisotopic mass will be, the other peaks are not quite as accurate as those
94
+ from [emass](https://github.com/princelab/emass) or
95
+ [BRAIN](https://code.google.com/p/brain-isotopic-distribution/); however, they
96
+ should be accurate enough for many purposes.
97
+
98
+ ```ruby
99
+ # zero charge, so returns masses and intensities
100
+ ethene.isotope_distribution
101
+ # => [[28.03130012828, 29.039965043880002, 30.048629959480003, ...],
102
+ # [0.9777084818979036, 0.02215911350461325, 0.0001323273147371948, ...]]
103
+
104
+ # if charged, will return m/z's and intensities
105
+ ethene.charge = 2
106
+ # => [[14.01510146414, 14.519433921940001, 15.023766379740001, 15.528098837540002...],
107
+ # [0.9777084818979036, 0.02215911350461325, 0.0001323273147371948, ...]]
108
+ ```
109
+
110
+ ## Convenience method to get at formulas fast
111
+
112
+ ```
113
+ require 'mspire/mf'
114
+ ethene = Mspire::MF['C2H4']
115
+ ```
58
116
 
117
+ This is just like calling 'mspire/molecular_formula' but it sets the MF
118
+ constant equal to MolecularFormula. Include Mspire or set your own constant
119
+ if you want something even shorter.
@@ -45,6 +45,7 @@ module Mspire
45
45
  end
46
46
  end
47
47
 
48
+
48
49
  require "mspire/molecular_formula/version"
49
50
 
50
51
  # class methods for reading from different string input
@@ -53,7 +54,23 @@ require 'mspire/molecular_formula/reader'
53
54
  # the modules for these 3 are included at the bottom
54
55
  require 'mspire/molecular_formula/arithmetic'
55
56
  require 'mspire/molecular_formula/mass'
56
- require 'mspire/molecular_formula/isotope_distribution'
57
+
58
+ # currently can't execute isotope dist code without this gem
59
+ # TODO: remove dep.
60
+ def have_fftw3?
61
+ begin
62
+ response = require('fftw3')
63
+ true
64
+ rescue
65
+ begin
66
+ Kernel.const_get('FFTW3')
67
+ rescue
68
+ false
69
+ end
70
+ end
71
+ end
72
+
73
+ require 'mspire/molecular_formula/isotope_distribution' if have_fftw3?
57
74
 
58
75
  module Mspire
59
76
  class MolecularFormula
@@ -64,6 +81,8 @@ module Mspire
64
81
  ####################################################
65
82
  include Arithmetic
66
83
  include Mass
67
- include IsotopeDistribution
84
+ if have_fftw3?
85
+ include IsotopeDistribution
86
+ end
68
87
  end
69
88
  end
@@ -1,7 +1,7 @@
1
1
  require 'mspire/mass'
2
2
  require 'mspire/isotope'
3
3
 
4
- require 'fftw3'
4
+ # depends on FFTW3 from mspire/molecular_formula right which does the: require 'fftw3'
5
5
 
6
6
  module Mspire
7
7
  class MolecularFormula
@@ -1,5 +1,5 @@
1
1
  module Mspire
2
2
  class MolecularFormula < Hash
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspire-molecular_formula
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John T. Prince
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-02 00:00:00.000000000 Z
11
+ date: 2014-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mspire-mass