Last active
December 17, 2015 04:19
-
-
Save grondilu/5549739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use v6; | |
| my %mass-table = <A 71.03711 C 103.00919 D 115.02694 E 129.04259 F | |
| 147.06841 G 57.02146 H 137.05891 I 113.08406 K 128.09496 L 113.08406 | |
| M 131.04049 N 114.04293 P 97.05276 Q 128.05858 R 156.10111 S | |
| 87.03203 T 101.04768 V 99.06841 W 186.07931 Y 163.06333 >; | |
| my @L = sort <4454.90309546 4525.94020546 4622.99296546 4685.42633528 | |
| 4809.07227546 4828.61559907 4906.86132096 4937.16723546 5068.20772546 | |
| 5080.83276633 5196.26630546 5202.17174106 5310.30923546 5411.35691546 | |
| 5514.36610546 5604.87077433 5627.45016546 5688.51728114 5758.49065546 | |
| 5812.88802964 5837.39751572 5845.52268546 5870.39698119 5883.85020521 | |
| 5885.43268521 5932.55471546 5940.65758589 6003.59182546 6166.65515546 | |
| 6228.17138651 6313.72356546 6391.45837162 6410.77632546 6509.84473546 | |
| 6540.53129197 6610.89241546 6622.92879546 6667.91387546 6736.01285546 | |
| 6781.95680546 6814.18804068 6884.96599546 6892.11396546 6917.82247352 | |
| 6956.00310546 6988.43829448 6991.18237546 7014.13288759 7081.61184648 | |
| 7092.23005546 7142.08241546 7149.25151546 7263.29444546 7274.23922747 | |
| 7296.48982435 7305.14574546 7376.37850546 7433.39996546 7491.04251301 | |
| 7491.22505546 7562.26216546 7564.44045546 7640.91676275 7655.6200045 | |
| 7659.31492546 7701.49936546 7714.57406764 7756.36768546 7768.43873972 | |
| 7773.94506346 7800.56777546 7869.45174546 7900.82812576 7914.61070546 | |
| 7984.47868546 8038.14646912 8051.66961546 8085.52636546 8136.66603907 | |
| 8185.25371266 8207.77072546 8222.58527546 8306.83913546 8343.34009817 | |
| 8350.64385546 8360.3581395 8421.86607546 8536.72316546 8552.90656546 | |
| 8564.53357537 8633.77592546 8709.00767546 8741.01676012 8761.87088546 | |
| 8822.09173546 8862.91856546 8914.51167354 8953.13222546 9009.98697546 | |
| 9123.07103546>; | |
| # <3524.8542 3623.5245 3710.9335 3841.974 3929.00603 3970.0326 4026.05879 4057.0646 4083.08025>; | |
| my %precision = @L Z=> map { $^x / $x.subst(/\./, '') }, @L; | |
| sub spectrum-graph(@L) { | |
| my %edges; | |
| for ^@L -> $i { | |
| for $i+1 ..^ @L -> $j { | |
| my ($u, $v) = @L[$i, $j]; | |
| my $precision = min %precision{$u, $v}; | |
| sub diff($pair) { abs($pair.value - ($v - $u)) } | |
| my $spread = diff | |
| my $min = min :by(&diff), %mass-table; | |
| if $spread < $precision { | |
| %edges{$u}.push: { next-mass => $v, amino-acid => $min.key }; | |
| } | |
| } | |
| } | |
| return %edges; | |
| } | |
| my %graph = spectrum-graph(@L); | |
| sub find-protein($initial-mass) { | |
| return '' unless %graph{$initial-mass} :exists; | |
| gather for %graph{$initial-mass}[] { | |
| take .<amino-acid> «~« find-protein(.<next-mass>); | |
| } | |
| } | |
| say max :by(*.chars), map &find-protein, @L; | |
| # vim: ft=perl6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment