| 1 | package MS::Mass; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Storable; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use File::ShareDir qw/dist_file/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Exporter qw/import/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | our @EXPORT_OK = qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | aa_mass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | atoms | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | atoms_mass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | brick_mass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | db_version | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | elem_mass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | formula_mass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | list_bricks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | mod_data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | mod_id_to_name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | mod_mass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | /; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | all => \@EXPORT_OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | my $unimod; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | my $fn_unimod = dist_file('MS' => 'unimod.stor'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | $unimod = retrieve $fn_unimod | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | or croak "failed to read Unimod database from storage: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } #end BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | sub _check_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2265 | ▶ | my ($type) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_type: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2265 | ▶ | return 'mono_mass' if (! defined $type); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2233 | ▶ | return ($type eq 'mono' || $type eq 'mono_mass') ? 'mono_mass' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$type eq "mono" or $type eq "mono_mass"
$type eq "average" or $type eq "avge_mass"
MC/DC100%2/2
$type eq "mono" or $type eq "mono_mass"
$type eq "mono"
$type eq "mono_mass"
MC/DC100%2/2
$type eq "average" or $type eq "avge_mass"
$type eq "average"
$type eq "avge_mass"
Truth table100%3/3
A or B
A= $type eq "mono"B= $type eq "mono_mass"
Truth table100%3/3
A or B
A= $type eq "average"B= $type eq "avge_mass"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | : ($type eq 'average' || $type eq 'avge_mass') ? 'avge_mass' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | : croak "Unexpected mass type (allowed: 'mono','average')\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sub db_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | return $unimod->{db_version} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
db_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | sub _mass { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2173 | ▶ | my ($group, $name, $type) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mass: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2173 | ▶ | if (! defined $unimod->{$group}->{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | carp "Undefined $group $name"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2171 | $type = _check_type( $type ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2170 | return $unimod->{$group}->{$name}->{$type}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1802 | ▶ | sub aa_mass { return _mass( 'aa', @_ ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aa_mass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | sub mod_mass { return _mass( 'mod', @_ ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mod_mass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 15 | ▶ | sub elem_mass { return _mass( 'elem', @_ ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
elem_mass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | sub brick_mass { return _mass( 'brick', @_ ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
brick_mass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | sub mod_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | my ($mod) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mod_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | return { %{$unimod->{mod}->{$mod}->{hashref}} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | sub formula_mass { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 12 | ▶ | my ($formula, $type) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
formula_mass: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 12 | $type = _check_type( $type ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 12 | ▶ | croak "unsupported characters in formula $formula" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | if ($formula =~ /[^0-9A-Za-z]/); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 11 | my $mass; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 11 | ▶ | while ($formula =~ /([A-Z][a-z]?)(\d*)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 21 | my $single_mass = _mass('elem', $1, $type); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 21 | ▶ | croak "mass not found for element $1" if (! defined $single_mass); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 20 | ▶ | my $multiplier = $2 ? $2 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 20 | $mass += $single_mass * $multiplier; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 10 | return $mass; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | sub atoms_mass { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 82 | ▶ | my ($ref, $type) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
atoms_mass: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 82 | $type = _check_type( $type ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 82 | my $mass; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 82 | for (keys %$ref) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 332 | my $single_mass = _mass('elem', $_, $type); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 332 | ▶ | croak "mass not found for element $_" if (! defined $single_mass); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 331 | $mass += $single_mass * $ref->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 81 | return $mass; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | sub atoms { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 5321 | ▶ | my ($type,$name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
atoms: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 5321 | ▶ | if (! defined $unimod->{$type}->{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | carp "Undefined $type $name"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 5319 | return { %{$unimod->{$type}->{$name}->{atoms}} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | sub mod_id_to_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | my ($id) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mod_id_to_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | return $unimod->{mod_index}->{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | sub list_bricks { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | my $str = "name\tfull_name\tmono_mass\tavg_mass\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_bricks: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | my @names = sort {$a cmp $b} keys %{ $unimod->{brick} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | for (@names) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 55 | my $ref = $unimod->{brick}->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | $str .= join( "\t", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | $_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | $ref->{full_name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | $ref->{mono_mass}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | $ref->{avge_mass}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 55 | ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||