glasgowcompbio / FrAnK

A Fragment Annotation Kit for Mass Spectral Peaks
GNU General Public License v3.0
0 stars 0 forks source link

Remove excessive 'if' statements from views.py #11

Open sjgreig27 opened 5 years ago

sjgreig27 commented 5 years ago

In the views.py we have a number of instances where we are doing something like the following:

        if annotation_tool.name == 'MassBank':
            annotation_query_form = MassBankQueryForm(experiment_object=experiment)
        elif annotation_tool.name == 'SIRIUS':
            annotation_query_form = SIRIUSQueryForm(experiment_object=experiment)
        elif annotation_tool.name == 'MAGMa':
            annotation_query_form = MAGMAQueryForm(experiment_object=experiment)
        elif annotation_tool.name == 'MSPepSearch':
            annotation_query_form = NISTQueryForm(experiment_object=experiment)
        elif annotation_tool.name == 'LCMS DDA Network Sampler':
            annotation_query_form = NetworkSamplerForm()
        elif annotation_tool.name == 'Precursor Mass Filter':
            annotation_query_form = PrecursorMassFilterForm(fragmentation_set_id)
        elif annotation_tool.name == 'Clean Annotations':
            annotation_query_form = CleanFilterForm(fragmentation_set_id)
        elif annotation_tool.name == 'Network Sampler':
            annotation_query_form = NetworkSamplerForm(fragmentation_set_id)

This is another hangover from my project, when I didn't know that you can use getattr( ) to grab a class from it's name as a string.

Making this change will reduce the complexity of the views.py dramatically and will make it easier to add in new tools as the views will just work when a new class and form are added.

joewandy commented 5 years ago

Nice! Let's do it!!

On Sat, 2 Mar 2019, 12:53 sjgreig27, notifications@github.com wrote:

In the views.py we have a number of instances where we are doing something like the following:

    if annotation_tool.name == 'MassBank':
        annotation_query_form = MassBankQueryForm(experiment_object=experiment)
    elif annotation_tool.name == 'SIRIUS':
        annotation_query_form = SIRIUSQueryForm(experiment_object=experiment)
    elif annotation_tool.name == 'MAGMa':
        annotation_query_form = MAGMAQueryForm(experiment_object=experiment)
    elif annotation_tool.name == 'MSPepSearch':
        annotation_query_form = NISTQueryForm(experiment_object=experiment)
    elif annotation_tool.name == 'LCMS DDA Network Sampler':
        annotation_query_form = NetworkSamplerForm()
    elif annotation_tool.name == 'Precursor Mass Filter':
        annotation_query_form = PrecursorMassFilterForm(fragmentation_set_id)
    elif annotation_tool.name == 'Clean Annotations':
        annotation_query_form = CleanFilterForm(fragmentation_set_id)
    elif annotation_tool.name == 'Network Sampler':
        annotation_query_form = NetworkSamplerForm(fragmentation_set_id)

This is another hangover from my project, when I didn't know that you can use getattr( ) to grab a class from it's name as a string.

Making this change will reduce the complexity of the views.py dramatically and will make it easier to add in new tools as the views will just work when a new class and form are added.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/glasgowcompbio/FrAnK/issues/11, or mute the thread https://github.com/notifications/unsubscribe-auth/ACaA_3TK-1y2Ilj17dK1r-zhSFQiPkddks5vSnRIgaJpZM4baXez .