bng_analysis_example.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. """
  2. This is free and unencumbered software released into the public domain.
  3. Anyone is free to copy, modify, publish, use, compile, sell, or
  4. distribute this software, either in source code form or as a compiled
  5. binary, for any purpose, commercial or non-commercial, and by any
  6. means.
  7. In jurisdictions that recognize copyright laws, the author or authors
  8. of this software dedicate any and all copyright interest in the
  9. software to the public domain. We make this dedication for the benefit
  10. of the public at large and to the detriment of our heirs and
  11. successors. We intend this dedication to be an overt act of
  12. relinquishment in perpetuity of all present and future rights to this
  13. software under copyright law.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. For more information, please refer to [http://unlicense.org]
  22. """
  23. import sys
  24. import os
  25. import pandas as pd
  26. MCELL_PATH = os.environ.get('MCELL_PATH', '')
  27. if MCELL_PATH:
  28. sys.path.append(os.path.join(MCELL_PATH, 'lib'))
  29. else:
  30. print("Error: variable MCELL_PATH that is used to find the mcell library was not set.")
  31. sys.exit(1)
  32. import mcell as m
  33. # utility module to load ASCII viz_output .dat file from
  34. import viz_reader
  35. # arbitrary values are used here
  36. WEIGHTS = {
  37. 'ampar_tarp': 1.5,
  38. 'psd95': 2.5,
  39. 'syngap': 3.5,
  40. }
  41. def analyze_dat_file(file_name):
  42. # read the .dat file and parse complexes to the internal MCell
  43. # representation
  44. complex_counts = viz_reader.read_dat_file(file_name)
  45. #print(complex_counts[0][0])
  46. #print(complex_counts[0][1])
  47. # process the read data
  48. for (complex, count) in complex_counts:
  49. weight = 0.0
  50. # iterate over elementary molecules from which the
  51. # complex is composed
  52. for mi in complex.elementary_molecules:
  53. name = mi.elementary_molecule_type.name
  54. if name not in WEIGHTS:
  55. print("Error: unknown molecular weight of " + name)
  56. sys.exit(1)
  57. weight += WEIGHTS[name]
  58. print("----------------------------------")
  59. print(complex.to_bngl_str())
  60. print("")
  61. print("weight: " + str(weight) + ", copy nr.: " + str(count))
  62. if __name__ == '__main__':
  63. if len(sys.argv) != 2:
  64. print("Expected .dat file name as argument")
  65. sys.exit(1)
  66. analyze_dat_file(sys.argv[1])