Skip to content

Commit

Permalink
Merge pull request #312 from AdityaSavara/changing-defaults
Browse files Browse the repository at this point in the history
Changing defaults
  • Loading branch information
AdityaSavara authored Jul 28, 2022
2 parents b0b3108 + 6788da2 commit e98ff76
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 35 deletions.
12 changes: 6 additions & 6 deletions DefaultUserInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
UserChoices['grapher'] = {} #initialize grapher container
#option allowing you to view a graph of determined concentrations
UserChoices['grapher']['on'] = 'yes' #yes will graph function no will not
UserChoices['grapher']['stopAtGraphs'] = True #True will cause stopping at graphs.
UserChoices['grapher']['stopAtGraphs'] = False #True will cause stopping at graphs.

#//Time Range//
UserChoices['timeRangeLimit'] = {} #initialize the timeRangeLimit container
Expand Down Expand Up @@ -188,17 +188,17 @@
#//Reference Mass Fragmentation Threshold//
UserChoices['applyReferenceMassFragmentsThresholds'] = {} #initialize the applyReferenceMassFragmentsThresholds container
# if you want to exclude tiny fragmentation peaks
UserChoices['applyReferenceMassFragmentsThresholds']['on'] = 'no'
UserChoices['applyReferenceMassFragmentsThresholds']['on'] = 'yes'
UserChoices['applyReferenceMassFragmentsThresholds']['referenceMassFragmentFilterThreshold'] = [5.0] #typical values are between 1 and 5. Can be a list (one value for each molecule) or a single value across all molecules. The list case has not been tested with all features. This approximates smaller fragmentation peaks as '0', though implicitSLS will correct for the approximation.
UserChoices['applyReferenceMassFragmentsThresholds']['referenceSignificantFragmentThresholds'] = [6.0] #typical values are between 5 and 50. Can be a list (one value for each molecule) or a single value across all molecules. The list case has not been tested with all features. This setting causes MSRESOLVE to favor larger intensity reference peaks (above the number provided) during solving.

#//Data Threshold Filter//
UserChoices['lowerBoundThresholdChooser'] = {} #initialize the lowerBoundThresholdChooser container
#To change the lower bound below which data is eliminated, change below; lowerBoundThresholdChooser ='yes' or 'no'
#The idea is that below an absolute (or percent based) threshold the intensity will be set to 0.
UserChoices['lowerBoundThresholdChooser']['on'] = 'no'
UserChoices['lowerBoundThresholdChooser']['on'] = 'yes'
UserChoices['lowerBoundThresholdChooser']['massesToLowerBoundThresholdFilter'] = [] # leave as [ ] to apply identical percentages or absolute thresholds to all masses.
UserChoices['lowerBoundThresholdChooser']['lowerBoundThresholdPercentage'] = [0.25] # 1.0 is max value. leave as [ ] to only use the absolute threshold. Always include a decimal.
UserChoices['lowerBoundThresholdChooser']['lowerBoundThresholdPercentage'] = [0.02] # 1.0 is max value. leave as [ ] to only use the absolute threshold. Always include a decimal.
UserChoices['lowerBoundThresholdChooser']['lowerBoundThresholdAbsolute'] = [] # leave as [ ] to only use the percentage threshold. Always include a decimal.

#TODO change the name option from point/timerange to
Expand All @@ -208,10 +208,10 @@
#This section is for the data smoother function which, by default, is enabled.
#Data smoothing can be conducted by a time basis or by a data point basis
UserChoices['dataSmootherYorN']['on'] = 'yes'
UserChoices['dataSmootherYorN']['dataSmootherChoice'] = 'timerange' #options are 'pointrange' or 'timerange'
UserChoices['dataSmootherYorN']['dataSmootherChoice'] = 'pointrange' #options are 'pointrange' or 'timerange'
# abscissaPointRadius and absc
UserChoices['dataSmootherYorN']['dataSmootherTimeRadius'] = 7
UserChoices['dataSmootherYorN']['dataSmootherPointRadius'] = 5
UserChoices['dataSmootherYorN']['dataSmootherPointRadius'] = 2
UserChoices['dataSmootherYorN']['dataSmootherHeadersToConfineTo'] = [] #Masses on which to perform smoothing.
#Should be a subset of 'choosenMassFragments' above.
# leave array empty [], to smooth all masses
Expand Down
9 changes: 5 additions & 4 deletions MSRESOLVE.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import export_import as ei
#G stands for Global, and is used to draw data from the UserInput File, and to store data during processing.
import UserInput as G; importlib.reload(G) #import the user input and reload the module to get rid of any unwanted variables in the namespace
debuggingExportIndividualItem = False #setting the default value for this global variable.

############################################################################################################################################
#########################################################Best Mass Fragment Chooser#########################################################
Expand Down Expand Up @@ -4603,21 +4604,21 @@ def get_remaining_referenceSignificantFragmentThresholds(referenceSignificantFra

Filename = " " + str(chosenMolecule)
Prefix = " solvedSignals4Sub " #solvedSignals4Sub stands for solved signals for subtraction.
debuggingExportIndividualItem (Prefix, ObjectforExport1, Filename)
debuggingExportIndividualItemFunction(Prefix, ObjectforExport1, Filename)
combinedString = combinedString + Prefix + Filename + ' \n' + str(ObjectforExport1) + ' \n'

ObjectforExport2= str(remaining_reciprocal_correction_factors_SLS[massFragmentIndex_jj,moleculeIndexForThisSLS]) + " " + str(chosenMolecule) + str(moleculeIndexForThisSLS) + " " + str(original_list_of_mass_fragments[massFragmentIndexForThisSLS])

Filename = " " + str(chosenMolecule)
Prefix = " RRCF " #RRCF stands for Reciprocal Remaining Correction factor
debuggingExportIndividualItem (Prefix, ObjectforExport2, Filename)
debuggingExportIndividualItemFunction(Prefix, ObjectforExport2, Filename)
combinedString = combinedString + Prefix + Filename + ' \n' + str(ObjectforExport2) + ' \n'

ObjectforExport3= str(concentrationOfMoleculeForThisSLS) + " " + str(chosenMolecule) + str(moleculeIndexForThisSLS) + " " + str(original_list_of_mass_fragments[massFragmentIndexForThisSLS])

Filename = " " + str(chosenMolecule)
Prefix = " ConcentrationSLS " #ConcentrationSLS stands for solved concetrations for SLS
debuggingExportIndividualItem (Prefix, ObjectforExport3, Filename)
debuggingExportIndividualItemFunction(Prefix, ObjectforExport3, Filename)
combinedString = combinedString + Prefix + Filename + ' \n' + str(ObjectforExport3) + ' \n'

if len(uncertainties_dict) > 0: #Just propagating the error to make the concentration uncertainties, including the signal associated with massFragmentIndexForThisSLS.
Expand Down Expand Up @@ -6088,7 +6089,7 @@ def PopulateLogFile():
return None


def debuggingExportIndividualItem (prefix, objectToExport, objectName = ""):
def debuggingExportIndividualItemFunction(prefix, objectToExport, objectName = ""):

prefix = str(prefix)
objectName = str(objectName)
Expand Down
8 changes: 6 additions & 2 deletions UnitTests/BestMassFragmentChooser/README.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
This directory test the Best Mass Fragment Chooser.



NOTE: Now, by default, it uses ExtentOfSLSUniqueSolvable.py and does not do on the fly SLS, nor does it do the significance checks etc.

The Best Mass Fragment Chooser selects mass fragment combinaitons that have unique fragments and can therefore pass the SLS Unique Fragments solution method. It ranks the mass fragment combination in terms the sum of the significance factors across the reference data for the selected masss fragments and returns the fragment combinations having the largest significance sum. It also returns a reference file containing refernce data for only the specified mass fragments and molecules.
Expand All @@ -22,5 +24,7 @@ There are 4 unit tests:
5) moleculesToMonitor=['Ethylene (Ethene)', 'Ethanol', 'Crotyl Alcohol' , 'Acetaldehyde' ] and 6 fragments. Without pre-check.

The unit tests above "10" have useExtentOfSLSUniqueSolvable = True, and add progressively more molecules to check.





WARNING: If a pytest is done to run all tests at once, the following tests may fail: test_2.py,test_3.py,test_4.py,test_5.py,test_8.py,test_9.py. However, when running them individually, these tests pass. These tets are presently turned off for convenience by having their extensions changed from ".py" to ".turnedOff". To run these tests, either use commands like "python test_2.turnedOff" or change the file extensions back to ".py" and run them individually (such as "python test_2.py"). Test_5.py takes around 15 minutes. Test_8.py takes around 1-2 hours. Test_9.py takes around 15 minutes. (those longer tests have progress bars when run directly /individually).
8 changes: 6 additions & 2 deletions UnitTests/BestMassFragmentChooser/bestMassFragChooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def bestMassFragChooser(chosenMolecules,
keep_N_ValuesInSignificanceFactorCheck=1000,
finalNumberOfCombinationsToKeep=10,
exportToFile=True,
useExtentOfSLSUniqueSolvable=True, printProgress=False,
useExtentOfSLSUniqueSolvable=True, printProgress=True,
minimizeDependencies = False):

#The below code is to allow replacing MSRESOLVE with the "standalone" dependencies file.
Expand All @@ -60,6 +60,7 @@ def bestMassFragChooser(chosenMolecules,
#The below options are only relevant if SLS is going to be used. So they do not matter if the person is using useExtentOfSLSUniqueSolvable.
if useExtentOfSLSUniqueSolvable == False:
import UserInput as G
G.applyReferenceMassFragmentsThresholds = 'no' #The applyReferenceMassFragmentsThresholds must be turned off for BestMassFragChooser to work in some cases. significantPeakThreshold should be used instead.
G.uncertainties_dict = {} #FIXME: This is only a temporary solution.
#The 4th "theoretical" case of having no limits post-loop SLS does not make sense, because there is a risk of too many combinations (which is why we make limits).
#So if someone tries to choose that, we force it into on the fly SLS (without limits).
Expand Down Expand Up @@ -227,11 +228,14 @@ def bestMassFragChooser(chosenMolecules,
printProgress=True
if printProgress==True:
try:
from tqdm import tqdm #this is a module for a progress bar. It's a bit weird that you import the function with same name as module.
from tqdm import tqdm #this is a module for a progress bar. It's a bit weird that one imports the function with same name as module.
t = tqdm(total=combinationsToConsider, position = 0) #position = 0 shouldn't be required, but helps prevent buggy bar behaviour.
tqdm_Failed = False
except:
tqdm_Failed = True
print("Warning: tqdm import or initialization failed. Progress will be printed in lines instead of a progress bar. Use pip tqdm to install the dependency required for the progress bar.")



if useExtentOfSLSUniqueSolvable:

Expand Down
28 changes: 16 additions & 12 deletions UnitTests/BestMassFragmentChooser/bestMassFragReference.csv
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#ComentsLine,,,
Molecules,Ethylene (Ethene),Ethanol,Crotyl Alcohol
Electron Numbers,16,26,40
moleculeIonizationType,unknown,unknown,unknown
relativeIonizationEfficiencies,1.0857142857142859,1.5142857142857142,2.1142857142857143
SourceOfFragmentationPatterns,NIST,NIST,NIST
sourceOfIonizationData,MadixAndKo,MadixAndKo,MadixAndKo
Molecular Mass,28.0532,46.0684,72.1057
27.0,63.32545620828447,23.784859078083752,54.22191680627966
28.0,100.0,0.0,18.46172080544184
29.0,0.0,30.73673009667451,93.41620158582646
57.0,0.0,0.0,100.00000000000001
#ComentsLine,,,,,
Molecules,Acetaldehyde,CO,Ethylene (Ethene),Ethanol,Crotyl Alcohol
Electron Numbers,24,14,16,26,40
moleculeIonizationType,unknown,unknown,unknown,unknown,unknown
relativeIonizationEfficiencies,1.4285714285714284,1.0,1.0857142857142859,1.5142857142857142,2.1142857142857143
SourceOfFragmentationPatterns,Measured,NIST,NIST,NIST,NIST
sourceOfIonizationData,MadixAndKo,MadixAndKo,MadixAndKo,MadixAndKo,MadixAndKo
Molecular Mass,44.0526,28.01,28.0532,46.0684,72.1057
26.0,10.701070107010702,0.0,54.61005634242505,10.617674226490585,14.63576885506878
27.0,7.740774077407742,0.0,63.32545620828447,23.784859078083752,54.22191680627966
28.0,61.03610361036104,100.0,100.0,0.0,18.46172080544184
29.0,100.0,0.0,0.0,30.73673009667451,93.41620158582646
41.0,5.4605460546054605,0.0,0.0,0.0,34.386683769881714
43.0,0.0,0.0,0.0,9.89855002990601,44.44178520315631
44.0,99.9899989999,0.0,0.0,0.0,11.544121843243628
57.0,0.0,0.0,0.0,0.0,100.00000000000001
Binary file modified UnitTests/BestMassFragmentChooser/calculated_resultObj13.p
Binary file not shown.
Binary file modified UnitTests/BestMassFragmentChooser/calculated_resultObj14.p
Binary file not shown.
Binary file modified UnitTests/BestMassFragmentChooser/calculated_resultObj2.p
Binary file not shown.
Binary file modified UnitTests/BestMassFragmentChooser/calculated_resultObj3.p
Binary file not shown.
Binary file modified UnitTests/BestMassFragmentChooser/calculated_resultObj4.p
Binary file not shown.
Binary file not shown.
Binary file modified UnitTests/BestMassFragmentChooser/calculated_resultObj8.p
Binary file not shown.
Binary file modified UnitTests/BestMassFragmentChooser/calculated_resultObj9.p
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[(26.0, 27.0, 28.0, 29.0, 44.0, 57.0), (26.0, 27.0, 28.0, 29.0, 39.0, 44.0), (26.0, 27.0, 28.0, 29.0, 44.0, 72.0), (26.0, 27.0, 28.0, 29.0, 38.0, 44.0), (26.0, 27.0, 28.0, 29.0, 44.0, 53.0), (26.0, 27.0, 28.0, 29.0, 44.0, 54.0), (26.0, 27.0, 28.0, 29.0, 42.0, 44.0), (26.0, 27.0, 28.0, 29.0, 44.0, 55.0), (26.0, 27.0, 28.0, 29.0, 40.0, 44.0), (26.0, 27.0, 28.0, 29.0, 37.0, 44.0)]
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions UnitTests/BestMassFragmentChooser/expected_resultStr5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[(26.0, 27.0, 28.0, 29.0, 44.0, 57.0), (26.0, 27.0, 28.0, 29.0, 39.0, 44.0), (26.0, 27.0, 28.0, 29.0, 44.0, 72.0), (26.0, 27.0, 28.0, 29.0, 38.0, 44.0), (26.0, 27.0, 28.0, 29.0, 44.0, 53.0), (26.0, 27.0, 28.0, 29.0, 44.0, 54.0), (26.0, 27.0, 28.0, 29.0, 42.0, 44.0), (26.0, 27.0, 28.0, 29.0, 44.0, 55.0), (26.0, 27.0, 28.0, 29.0, 40.0, 44.0), (26.0, 27.0, 28.0, 29.0, 37.0, 44.0)]
1 change: 1 addition & 0 deletions UnitTests/BestMassFragmentChooser/expected_resultStr9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[(12.0, 25.0, 30.0, 38.0, 39.0, 44.0, 57.0, 72.0), (12.0, 25.0, 30.0, 38.0, 39.0, 44.0, 45.0, 57.0), (12.0, 25.0, 30.0, 37.0, 39.0, 44.0, 57.0, 72.0), (12.0, 25.0, 30.0, 37.0, 39.0, 44.0, 45.0, 57.0), (12.0, 25.0, 30.0, 38.0, 39.0, 44.0, 53.0, 57.0), (12.0, 25.0, 30.0, 38.0, 39.0, 44.0, 54.0, 57.0), (12.0, 25.0, 30.0, 38.0, 39.0, 44.0, 46.0, 57.0), (12.0, 25.0, 30.0, 38.0, 39.0, 42.0, 44.0, 57.0), (12.0, 25.0, 30.0, 38.0, 39.0, 44.0, 55.0, 57.0), (12.0, 25.0, 30.0, 38.0, 39.0, 40.0, 44.0, 57.0)]
2 changes: 1 addition & 1 deletion UnitTests/BestMassFragmentChooser/test_5.turnedOff
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ numberOfMassFragsToMonitor=6

#4) get the output of the function, which is what will typically be checked.

topBestMassFragments= bmfc.bestMassFragChooser(moleculesToMonitor, moleculesLikelihood, numberOfMassFragsToMonitor,'AcetaldehydeNISTRefMixed2.csv','xyyy', onTheFlySLS=True, keep_N_ValuesInRoughUniquenessCheck=False, keep_N_ValuesInSignificanceFactorCheck=False, useExtentOfSLSUniqueSolvable = False )[0] #, output[1], output[2]] #You can alternatively populate resultObj with whatever you want, such as a list.
topBestMassFragments= bmfc.bestMassFragChooser(moleculesToMonitor, moleculesLikelihood, numberOfMassFragsToMonitor,'AcetaldehydeNISTRefMixed2.csv','xyyy', onTheFlySLS=True, keep_N_ValuesInRoughUniquenessCheck=False, keep_N_ValuesInSignificanceFactorCheck=False, useExtentOfSLSUniqueSolvable = False , printProgress=True)[0] #, output[1], output[2]] #You can alternatively populate resultObj with whatever you want, such as a list.
resultObj=topBestMassFragments

#5) A string is also typically provided, but is an optional argument. You can provide whatever string you want.
Expand Down
12 changes: 6 additions & 6 deletions UserInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
UserChoices['grapher'] = {} #initialize grapher container
#option allowing you to view a graph of determined concentrations
UserChoices['grapher']['on'] = 'yes' #yes will graph function no will not
UserChoices['grapher']['stopAtGraphs'] = True #True will cause stopping at graphs.
UserChoices['grapher']['stopAtGraphs'] = False #True will cause stopping at graphs.

#//Time Range//
UserChoices['timeRangeLimit'] = {} #initialize the timeRangeLimit container
Expand Down Expand Up @@ -188,17 +188,17 @@
#//Reference Mass Fragmentation Threshold//
UserChoices['applyReferenceMassFragmentsThresholds'] = {} #initialize the applyReferenceMassFragmentsThresholds container
# if you want to exclude tiny fragmentation peaks
UserChoices['applyReferenceMassFragmentsThresholds']['on'] = 'no'
UserChoices['applyReferenceMassFragmentsThresholds']['on'] = 'yes'
UserChoices['applyReferenceMassFragmentsThresholds']['referenceMassFragmentFilterThreshold'] = [5.0] #typical values are between 1 and 5. Can be a list (one value for each molecule) or a single value across all molecules. The list case has not been tested with all features. This approximates smaller fragmentation peaks as '0', though implicitSLS will correct for the approximation.
UserChoices['applyReferenceMassFragmentsThresholds']['referenceSignificantFragmentThresholds'] = [6.0] #typical values are between 5 and 50. Can be a list (one value for each molecule) or a single value across all molecules. The list case has not been tested with all features. This setting causes MSRESOLVE to favor larger intensity reference peaks (above the number provided) during solving.

#//Data Threshold Filter//
UserChoices['lowerBoundThresholdChooser'] = {} #initialize the lowerBoundThresholdChooser container
#To change the lower bound below which data is eliminated, change below; lowerBoundThresholdChooser ='yes' or 'no'
#The idea is that below an absolute (or percent based) threshold the intensity will be set to 0.
UserChoices['lowerBoundThresholdChooser']['on'] = 'no'
UserChoices['lowerBoundThresholdChooser']['on'] = 'yes'
UserChoices['lowerBoundThresholdChooser']['massesToLowerBoundThresholdFilter'] = [] # leave as [ ] to apply identical percentages or absolute thresholds to all masses.
UserChoices['lowerBoundThresholdChooser']['lowerBoundThresholdPercentage'] = [0.25] # 1.0 is max value. leave as [ ] to only use the absolute threshold. Always include a decimal.
UserChoices['lowerBoundThresholdChooser']['lowerBoundThresholdPercentage'] = [0.02] # 1.0 is max value. leave as [ ] to only use the absolute threshold. Always include a decimal.
UserChoices['lowerBoundThresholdChooser']['lowerBoundThresholdAbsolute'] = [] # leave as [ ] to only use the percentage threshold. Always include a decimal.

#TODO change the name option from point/timerange to
Expand All @@ -208,10 +208,10 @@
#This section is for the data smoother function which, by default, is enabled.
#Data smoothing can be conducted by a time basis or by a data point basis
UserChoices['dataSmootherYorN']['on'] = 'yes'
UserChoices['dataSmootherYorN']['dataSmootherChoice'] = 'timerange' #options are 'pointrange' or 'timerange'
UserChoices['dataSmootherYorN']['dataSmootherChoice'] = 'pointrange' #options are 'pointrange' or 'timerange'
# abscissaPointRadius and absc
UserChoices['dataSmootherYorN']['dataSmootherTimeRadius'] = 7
UserChoices['dataSmootherYorN']['dataSmootherPointRadius'] = 5
UserChoices['dataSmootherYorN']['dataSmootherPointRadius'] = 2
UserChoices['dataSmootherYorN']['dataSmootherHeadersToConfineTo'] = [] #Masses on which to perform smoothing.
#Should be a subset of 'choosenMassFragments' above.
# leave array empty [], to smooth all masses
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
EMAIL = '[email protected]'
AUTHOR = 'Aditya Savara'
REQUIRES_PYTHON = '>=3.5.0'
VERSION = '44.7.2'
VERSION = '44.8.0'
LICENSE = 'BSD-3-Clause'

# What packages are required for this module to be executed?
Expand All @@ -32,7 +32,7 @@

# What packages are optional?
EXTRAS = {
'COMPLETE': ['matplotlib', 'scipy', 'pandas']# 'uncertainties': ['uncertainties'], #pymc...
'COMPLETE': ['matplotlib', 'scipy', 'pandas', 'tqdm']# 'uncertainties': ['uncertainties'], #pymc...
}

# The rest you shouldn't have to touch too much :)
Expand Down

0 comments on commit e98ff76

Please sign in to comment.