The function analyze_workloop() in workloopR allows users to evaluate the mechanical work and power output of a muscle they have investigated through work loop experiments.

To demonstrate analyze_workloop(), we will first load workloopR and use example data provided with the package. We’ll also load a couple packages within the tidyverse to help with data wrangling and plotting.

Visualize

We’ll now import the workloop.ddf file included with workloopR. Because this experiment involved using a gear ratio of 2, we’ll use fix_GR() to also implement this correction.

Ultimately, an object of classes workloop, muscle_stim, and data.frame is produced. muscle_stim objects are used throughout workloopR to help with data formatting and error checking across functions. Additionally setting the class to workloop allows our functions to understand that the data have properties that other experiment types (twitch, tetanus) do not.

Running summary() on a `muscle_stim shows a handy summary of file properties, data, and experimental parameters.

Let’s plot Time against Force, Position, and Stimulus (Stim) to visualize the time course of the work loop experiment.

To get them all plotted in the same figure, we’ll transform the data as they are being plotted. Please note that this is for aesthetic purposes only - the underlying data will not be changed after the plotting is complete.

There’s a lot to digest here. The blue trace shows the change in length of the muscle via cyclical, sinusoidal changes to Position. The dark gray Stim dots show stimulation on a off vs. on basis. Stimulus onset is close to when the muscle is at L0 and the stimulator zapped the muscle four times in pulses of 0.2 ms width at 300 Hz. The resulting force development is shown in red. These cycles of length change and stimulation occurred a total of 6 times (measuring L0-to-L0).

Select cycles

We are now ready to run the select_cycles() function. This function subsets the data and labels each cycle in prep for our analyze_workloop() function.

In many cases, researchers are interested in using the final 3 cycles for analyses. Accordingly, we’ll set the keep_cycles parameter to 4:6.

One thing to pay heed to is the cycle definition, encoded as cycle_def within the arguments of select_cycles(). There are three options for how cycles can be defined and are named based on the starting (and ending) points of the cycle. We’ll use the L0-to-L0 option, which is encoded as lo.

The function internally performs butterworth filtering of the Position data via signal::butter(). This is because Position data are often noisy, which makes assessing true peak values difficult. The default values of bworth_order = 2 and bworth_freq = 0.05 work well in most cases, but we recommend you please plot your data and assess this yourself.

We will keep things straightforward for now so that we can proceed to the analytical stage. Please see the final section of this vignette for more details on using select_cycles().

The summary() function now reflects that 3 cycles of the original 6 have been retained, and getting the "retained_cycles" attribute shows that these cycles are 4, 5, and 6 from the original data.

To avoid confusion in numbering schemes between the original data and the new object, once select_cycles() has been used we label cycles by letter. So, cycle 4 is now “a”, 5 is “b” and 6 is “c”.

Basics of analyze_workloop()

Now we’re ready to use analyze_workloop().

Again, running select_cycles() beforehand was necessary, so we will switch to using workloop_selected as our data object.

Within analyze_workloop(), the GR = option allows for the gear ratio to be corrected if it hasn’t been already. But because we already ran fix_GR() to correct the gear ratio to 2, we will not need to use it here again. So, this for this argument, we will use GR = 1, which keeps the data as they are. Please take care to ensure that you do not overcorrect for gear ratio by setting it multiple times. Doing so induces multiplicative changes. E.g. setting GR = 3 on an object and then setting GR = 3 again produces a gear ratio correction of 9.

Using the default simplify = FALSE version

The argument simplify = affects the output of the analyze_workloop() function. We’ll first take a look at the organization of the “full” version, i.e. keeping the default simplify = FALSE.

This produces an analyzed_workloop object that is essentially a list that is organized by cycle. Within each of these, time-course data are stored as a data.frame and important metadata are stored as attributes.

Users may typically want work and net power from each cycle. Within the analyzed_workloop object, these two values are stored as attributes: "work" (in J) and "net_power" (in W). To get them for a specific cycle:

To see how e.g. the first cycle is organized:

str(workloop_analyzed$cycle_a)
#> Classes 'workloop', 'muscle_stim' and 'data.frame':  357 obs. of  9 variables:
#>  $ Time            : num  0.119 0.119 0.119 0.12 0.12 ...
#>  $ Position        : num  0.33 0.359 0.389 0.414 0.441 ...
#>  $ Force           : num  1708 1718 1725 1734 1744 ...
#>  $ Stim            : int  1 1 0 0 0 0 0 0 0 0 ...
#>  $ Cycle           : chr  "a" "a" "a" "a" ...
#>  $ Inst_Velocity   : num  NA -0.292 -0.292 -0.252 -0.271 ...
#>  $ Filt_Velocity   : num  NA -0.143 -0.158 -0.172 -0.185 ...
#>  $ Inst_Power      : num  NA -0.246 -0.272 -0.298 -0.322 ...
#>  $ Percent_of_Cycle: num  0 0.281 0.562 0.843 1.124 ...
#>  - attr(*, "stimulus_frequency")= int 300
#>  - attr(*, "cycle_frequency")= int 28
#>  - attr(*, "total_cycles")= num 6
#>  - attr(*, "cycle_def")= chr "lo"
#>  - attr(*, "amplitude")= num 1.57
#>  - attr(*, "phase")= num -24.9
#>  - attr(*, "position_inverted")= logi FALSE
#>  - attr(*, "units")= chr  "s" "mm" "mN" "TTL" ...
#>  - attr(*, "sample_frequency")= num 10000
#>  - attr(*, "header")= chr  "Sample Frequency (Hz): 10000" "Reference Area: NaN sq. mm" "Reference Force: NaN mN" "Reference Length: NaN mm"
#>  - attr(*, "units_table")='data.frame':  10 obs. of  5 variables:
#>   ..$ Channel: chr  "AI0" "AI1" "AI2" "AI3" ...
#>   ..$ Units  : chr  "mm" "mN" "TTL" "" ...
#>   ..$ Scale  : num  1 500 0.2 0 0 0 0 0 1 500
#>   ..$ Offset : num  0 0 0 0 0 0 0 0 0 0
#>   ..$ TADs   : num  0 0 0 0 0 0 0 0 0 0
#>  - attr(*, "protocol_table")='data.frame':   4 obs. of  5 variables:
#>   ..$ Wait.s     : num  0 0.01 0 0.1
#>   ..$ Then.action: chr  "Stimulus-Train" "Sine Wave" "Stimulus-Train" "Stop"
#>   ..$ On.port    : chr  "Stimulator" "Length Out" "Stimulator" ""
#>   ..$ Units      : chr  ".012, 300, 0.2, 4, 28" "28,3.15,6" "0,0,0,0,0" ""
#>   ..$ Parameters : logi  NA NA NA NA
#>  - attr(*, "stim_table")='data.frame':   2 obs. of  5 variables:
#>   ..$ offset         : num  0.012 0
#>   ..$ frequency      : int  300 0
#>   ..$ width          : num  0.2 0
#>   ..$ pulses         : int  4 0
#>   ..$ cycle_frequency: int  28 0
#>  - attr(*, "stimulus_pulses")= int 4
#>  - attr(*, "stimulus_offset")= num 0.012
#>  - attr(*, "stimulus_width")= num 0.2
#>  - attr(*, "gear_ratio")= num 2
#>  - attr(*, "file_id")= chr "workloop.ddf"
#>  - attr(*, "mtime")= POSIXct, format: "2019-12-11 23:26:53"
#>  - attr(*, "retained_cycles")= int  4 5 6
#>  - attr(*, "work")= num 0.00301
#>  - attr(*, "net_power")= num 0.0909

Within each cycle’s data.frame, the usual Time, Position, Force, and Stim are stored. Cycle, added via select_cycles(), denotes cycle identity and Percent_of_Cycle displays time as a percentage of that particular cycle.

analyze_workloop() also computes instantaneous velocity (Inst_Velocity) which can sometimes be noisy, leading us to also apply a butterworth filter to this velocity (Filt_Velocity). See the function’s help file for more details on how to tweak filtering. The time course of power (instantaneous power) is also provided as Inst_Power.

Each of these variables can be plot against Time to see the time-course of that variable’s change over the cycle. For example, we will plot instantaneous force in cycle b:

Setting simpilfy = TRUE in the analyze_workloop() function

If you simply want work and net power for each cycle without retaining any of the time-course data, set simplify = TRUE within analyze_workloop().

Here, work (in J) and net power (in W) are simply returned in a data.frame that is organized by cycle. No other attributes are stored.

More on cycle definitions in select_cycles()

As noted above, there are three options for cycle definitions within select_cycles(), encoded as cycle_def. The three options for how cycles can be defined are named based on the starting (and ending) points of the cycle: L0-to-L0 (lo), peak-to-peak (p2p), and trough-to-trough (t2t).

We highly recommend that you plot your Position data after using select_cycles(). The pracma::findpeaks() function work for most data (especially sine waves), but it is conceivable that small, local ‘peaks’ may be misinterpreted as a cycle’s true minimum or maximum.

We also note that edge cases (i.e. the first cycle or the final cycle) may also be subject to issues in which the cycles are not super well defined via an automated algorithm.

Below, we will plot a couple case examples to show what we generally expect. We recommend plotting your data in a similar fashion to verify that select_cycles() is behaving in the way you expect.