Documentation for Common.py
¶
Common
¶
DummyFormula
¶
DummyFormula(mz)
A dummy wrapper to store an mz as a vimms.Common.Formula. This is convenient as it allows us to treat an m/z value like an (unknown) formula.
Create a DummyFormula object Args: mz: the m/z value to wrap
Source code in vimms/Common.py
272 273 274 275 276 277 278 |
|
Formula
¶
Formula(formula_string)
A class to represent a chemical formula
Creates a Formula object. Formulae can be sampled to generate vimms.Chemicals.Chemical objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formula_string
|
string
|
the chemical formula |
required |
Source code in vimms/Common.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
compute_exact_mass
¶
compute_exact_mass()
Computes the exact mass of this formula Returns: the exact mass
Source code in vimms/Common.py
247 248 249 250 251 252 253 254 255 256 257 |
|
Precursor
¶
Precursor(
precursor_mz, precursor_intensity, precursor_charge, precursor_scan_id
)
A class to store precursor peak information when writing an MS2 scan.
Create a Precursor object. Args: precursor_mz: the m/z value of this precursor peak. precursor_intensity: the intensity value of this precursor peak. precursor_charge: the charge of this precursor peak precursor_scan_id: the assocated MS1 scan ID that contains this precursor peak
Source code in vimms/Common.py
400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
ScanParameters
¶
ScanParameters()
A class to store parameters used to instruct the mass spec how to generate a scan. This object is usually created by the controller. It is used by the controller to instruct the mass spec what actions (scans) to perform next.
Create a scan parameter object
Source code in vimms/Common.py
331 332 333 334 335 |
|
compute_isolation_windows
¶
compute_isolation_windows()
Gets the full-width (DDA) isolation window around a precursor m/z
Source code in vimms/Common.py
370 371 372 373 374 375 376 377 |
|
get
¶
get(key)
Gets scan parameter value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
the key to look for |
required |
Returns: the corresponding value in this ScanParameter
Source code in vimms/Common.py
349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
get_all
¶
get_all()
Get all scan parameters Returns: all the scan parameters
Source code in vimms/Common.py
363 364 365 366 367 368 |
|
set
¶
set(key, value)
Set scan parameter value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
a scan parameter name |
required | |
value
|
a scan parameter value |
required |
Returns: None
Source code in vimms/Common.py
337 338 339 340 341 342 343 344 345 346 347 |
|
add_log_file
¶
add_log_file(log_path, level)
Add path to log file Args: log_path: filename to output the logging to level: the log level
Returns: None
Source code in vimms/Common.py
604 605 606 607 608 609 610 611 612 613 614 |
|
chromatogramDensityNormalisation
¶
chromatogramDensityNormalisation(rts, intensities)
Definition to standardise the area under a chromatogram to 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rts
|
the RT values of this chromatogram |
required | |
intensities
|
the intensity values of this chromatogram |
required |
Returns: updated intensities that have been standardised so the area is 1.
Source code in vimms/Common.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
create_if_not_exist
¶
create_if_not_exist(out_dir)
Creates a directory if it doesn't already exist Args: out_dir: the directory to create, if it doesn't exist
Returns: None.
Source code in vimms/Common.py
428 429 430 431 432 433 434 435 436 437 438 439 |
|
download_file
¶
download_file(url, out_file=None)
Download a file from the given URL Args: url: URL to download out_file: filename of output file to save to
Returns: filename of the out_file
Source code in vimms/Common.py
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
|
extract_zip_file
¶
extract_zip_file(in_file, delete=True)
Extract a zip file Args: in_file: the input zip file delete: whether to delete the input zip file after extracting
Returns: None
Source code in vimms/Common.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
|
find_nearest_index_in_array
¶
find_nearest_index_in_array(array, value)
Finds index in array where the value is the nearest
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array
|
the array to check |
required | |
value
|
the value to check |
required |
Returns: index in array where the value is the nearest
Source code in vimms/Common.py
633 634 635 636 637 638 639 640 641 642 643 644 645 |
|
get_dda_scan_param
¶
get_dda_scan_param(
mz,
intensity,
precursor_scan_id,
isolation_width,
mz_tol,
rt_tol,
agc_target=DEFAULT_MS2_AGC_TARGET,
max_it=DEFAULT_MS2_MAXIT,
collision_energy=DEFAULT_MS2_COLLISION_ENERGY,
source_cid_energy=DEFAULT_SOURCE_CID_ENERGY,
orbitrap_resolution=DEFAULT_MS2_ORBITRAP_RESOLUTION,
mass_analyser=DEFAULT_MS2_MASS_ANALYSER,
activation_type=DEFAULT_MS1_ACTIVATION_TYPE,
isolation_mode=DEFAULT_MS2_ISOLATION_MODE,
polarity=POSITIVE,
metadata=None,
scan_id=None,
)
Generate the default MS2 scan parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mz
|
m/z of precursor peak to fragment |
required | |
intensity
|
intensity of precursor peak to fragment |
required | |
precursor_scan_id
|
scan ID of the MS1 scan containing the precursor peak |
required | |
isolation_width
|
isolation width, in Dalton |
required | |
mz_tol
|
m/z tolerance for dynamic exclusion # FIXME: this shouldn't be here |
required | |
rt_tol
|
RT tolerance for dynamic exclusion # FIXME: this shouldn't be here |
required | |
agc_target
|
AGC (automatic gain control) target |
DEFAULT_MS2_AGC_TARGET
|
|
max_it
|
maximum time to collect ion |
DEFAULT_MS2_MAXIT
|
|
collision_energy
|
the collision energy to use |
DEFAULT_MS2_COLLISION_ENERGY
|
|
source_cid_energy
|
source CID energy |
DEFAULT_SOURCE_CID_ENERGY
|
|
orbitrap_resolution
|
resolution of the mass-spec (Orbitrap) instrument |
DEFAULT_MS2_ORBITRAP_RESOLUTION
|
|
mass_analyser
|
which mass analyser to use |
DEFAULT_MS2_MASS_ANALYSER
|
|
activation_type
|
activation type, either HCD or CID |
DEFAULT_MS1_ACTIVATION_TYPE
|
|
isolation_mode
|
isolation mode, either None, or Quadrupole or IonTrap |
DEFAULT_MS2_ISOLATION_MODE
|
|
polarity
|
the polarity value, either POSITIVE or NEGATIVE |
POSITIVE
|
|
metadata
|
additional metadata to include in this scan |
None
|
|
scan_id
|
the scan ID, if specified |
None
|
Returns: the parameters of the MS2 scan to create
Source code in vimms/Common.py
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
|
get_default_scan_params
¶
get_default_scan_params(
polarity=POSITIVE,
agc_target=DEFAULT_MS1_AGC_TARGET,
max_it=DEFAULT_MS1_MAXIT,
collision_energy=DEFAULT_MS1_COLLISION_ENERGY,
source_cid_energy=DEFAULT_SOURCE_CID_ENERGY,
orbitrap_resolution=DEFAULT_MS1_ORBITRAP_RESOLUTION,
default_ms1_scan_window=DEFAULT_MS1_SCAN_WINDOW,
mass_analyser=DEFAULT_MS1_MASS_ANALYSER,
activation_type=DEFAULT_MS1_ACTIVATION_TYPE,
isolation_mode=DEFAULT_MS1_ISOLATION_MODE,
metadata=None,
scan_id=None,
)
Generate the default MS1 scan parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polarity
|
the polarity value, either POSITIVE or NEGATIVE |
POSITIVE
|
|
agc_target
|
AGC (automatic gain control) target |
DEFAULT_MS1_AGC_TARGET
|
|
max_it
|
maximum time to collect ion |
DEFAULT_MS1_MAXIT
|
|
collision_energy
|
the collision energy to use |
DEFAULT_MS1_COLLISION_ENERGY
|
|
source_cid_energy
|
source CID energy |
DEFAULT_SOURCE_CID_ENERGY
|
|
orbitrap_resolution
|
resolution of the mass-spec (Orbitrap) instrument |
DEFAULT_MS1_ORBITRAP_RESOLUTION
|
|
default_ms1_scan_window
|
the default MS1 scan window |
DEFAULT_MS1_SCAN_WINDOW
|
|
mass_analyser
|
which mass analyser to use |
DEFAULT_MS1_MASS_ANALYSER
|
|
activation_type
|
activation type, either HCD or CID |
DEFAULT_MS1_ACTIVATION_TYPE
|
|
isolation_mode
|
isolation mode, either None, or Quadrupole or IonTrap |
DEFAULT_MS1_ISOLATION_MODE
|
|
metadata
|
additional metadata to include in this scan |
None
|
|
scan_id
|
the scan ID, if specified |
None
|
Returns: the parameters of the MS1 scan to create
Source code in vimms/Common.py
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 |
|
get_rt
¶
get_rt(spectrum)
Extracts RT value from a pymzml spectrum object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
a pymzml spectrum object |
required |
Returns: the retention time (in seconds)
Source code in vimms/Common.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
|
load_obj
¶
load_obj(filename)
Load saved object from file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
The filename to load. Should be saved using the |
required |
Returns: the loaded object
Source code in vimms/Common.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
save_obj
¶
save_obj(obj, filename)
Save object to file. This is useful for storing simulation results and other objects.
If the directory containing the specified filename doesn't exist, it will be created first. The object will be saved using gzip + pickle (highest protocol).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
the Python object to save |
required | |
filename
|
the output filename to use |
required |
Returns: None
Source code in vimms/Common.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
set_log_level
¶
set_log_level(level, remove_id=None)
Set the logging level of the default logger Args: level: the new level to set remove_id: ID of previous log handler to be removed
Returns: the new log handler after setting the log level
Source code in vimms/Common.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
|
set_log_level_debug
¶
set_log_level_debug(remove_id=None)
Set log level to DEBUG Args: remove_id: ID of previous log handler to be removed
Returns: None
Source code in vimms/Common.py
592 593 594 595 596 597 598 599 600 601 |
|
set_log_level_info
¶
set_log_level_info(remove_id=None)
Set log level to INFO Args: remove_id: ID of previous log handler to be removed
Returns: None
Source code in vimms/Common.py
580 581 582 583 584 585 586 587 588 589 |
|
set_log_level_warning
¶
set_log_level_warning(remove_id=None)
Set log level to WARNING Args: remove_id: ID of previous log handler to be removed
Returns: None
Source code in vimms/Common.py
568 569 570 571 572 573 574 575 576 577 |
|
uniform_list
¶
uniform_list(N, min_val, max_val)
Generates a list of N uniformly random values from min_val to max_val Args: N: the number of items to generate min_val: the minimum range max_val: the maximum range
Returns: a list of N values
Source code in vimms/Common.py
700 701 702 703 704 705 706 707 708 709 710 711 |
|