Last active
November 21, 2022 19:41
-
-
Save Spebby/60ed2d2d98f2aa2c296f01ca9b20f34a to your computer and use it in GitHub Desktop.
protein weight calculator
This file contains 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
#!/usr/bin/env python3 | |
""" | |
Uses three sources of input and produces two forms of output regarding proteins and | |
their expected molecular weights for the purpose of mass spectrometry. | |
""" | |
import sys | |
try: | |
with open(sys.argv[1], mode="w") as file: | |
aminoMono = {} | |
totalLength, totalWeight, length = 0, 0, 0 | |
with open("/srv/datasets/amino-monoisotopic-mass") as input_file: | |
for line in input_file: | |
line = line.split() | |
aminoMono[line[0]] = float(line[1]) | |
for line in sys.stdin: | |
line = line.strip() | |
weight = 0 | |
for char in line: | |
weight += aminoMono[char] | |
totalLength += len(line) | |
totalWeight += weight | |
length += 1 | |
print(f"{line} {len(line)} {weight:.3f}", file=file) | |
print(f"{length} {totalLength} {totalWeight:.3f}") | |
except IndexError: | |
print("Why are you wasting electricity?") | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment