Skip to content

The qpcr Module

NoahHenrikKleinschmidt edited this page Aug 21, 2021 · 2 revisions

Using the qpcr Module

The qpcr package contains a set of functions tailored to open raw data, pre-process these into accessible data-formats, and eventually generating meaningful results which can be exported and visualised. In the following page all the functions of the qpcr package are listed in their natural order of usage (i.e. opening an input file comes before Delta_DeltaCt).

import qpcr
import qpcr.Analysis as qA
Open input files: qpcr.open_csv_file

qpcr.open_csv_file takes in a filepath to the input file and returns a dictionary of the data. Optionally, the data may be returned as a list of lines using the parameter export="list" but this is not suitable for further analysis using the qpcr package!

data_file = "mydata.csv"
data = qpcr.open_csv_file(data_file)
Organise data in groups of replicates: qpcr.group_samples

qpcr.group_samples takes in a data dictionary (from qpcr.open_csv_file) as well as a replicates argument which may either be an int (if all groups have the same number of replicates) or a list, in which case each group of replicates must be given its own number of replicates.

grouped_data = qpcr.group_samples(data, replicates = 3) # all groups are triplicates

# or 

grouped_data = qpcr.group_samples(data, replicates = (3, 3, 2, 3)) # the dataset contains 4 groups, three of which are triplicates but one is a duplicate. 
Rename Groups: qpcr.rename_groups

By default groups of replicates are assigned Group1,Group2,... automatically. To change this to meaningful group names qpcr.rename_groups takes in a grouped dictionary and a list of strings containing the new name of each group of replicates. It is important that any dictionaries that shall be used for the same analysis have the same group names!

group_names = ["ctrl", "0.01M", "0.1M", "0.3M"]
renamed_groups = qpcr.rename_groups(grouped_data, group_names = group_names]
Delta-CT: qpcr.Delta_Ct

qpcr.Delta_Ct takes in one grouped dictionary (one that has been processed using qpcr.group_samples) and an anchor argument which may be: "grouped" (or None, this is the default) in which case the first entry of each group is taken as reference, "first" in which case the very first line of the dataset is taken as reference for all groups, or any float in which case a specific reference may be given which will be used for the entire dataset. Optionally, it is possible to choose wether or not to compute the Delta-CT exponentially as 2^(Delta-Ct) (default) or not using the argument exp = False.

sample_deltaCt = qpcr.Delta_Ct(renamed_groups, anchor = "first")
Delta-Delta-CT: qpcr.normalise

qpcr.normalise is used to take the second Delta-CT in Delta-Delta CT analysis to normalise against a normaliser. It takes in one pre-processed dictionary for the normaliserargument and one pre-processed dictionary for the sampleargument. For this to work it is necessary to that both normaliser and sample have the same group names! Optionally a line containing "Legend" : "DDCT" may be added to the resulting dictionary using the argument no_head=False.

result = qpcr.normalise(sample = sample_deltaCt, normaliser = normaliser_deltaCt) # normaliser_deltaCt must have been processed exactly the same way as sample_deltaCt (including group names!)
Combining Normalisers: qpcr.preprocess_normalisers and qpcr.combine_normalisers

Sometimes it is desirable to use not one single normaliser but instead a combined (= averaged) version of multiple normalisers (e.g. Actin + 28S rRNA). This package also provides In this case the normalisers must first be preprocessed using qpcr.preprocess_normalisers which takes in a list of input files, as well as parameters replicates, run_names (to define the names, default is None and uses the filenames), group_names (which must be the same as those used in the target datasets!), and anchor. Once the normalisers are preprocessed they can be combined using qpcr.combine_normalisers which will take in the list of preprocessed normalisers that is returned by qpcr.preprocess_normalisers.

normalisers = ["norm1.csv", "norm2.csv", "norm3.csv"]
group_names = ["ctrl", "0.01M", "0.1M", "0.3M"]
preprocessed_norms = qpcr.preprocess_normalisers(normalisers, replicates = 3, anchor = "first", group_names = group_names) # note that replicates, anchor, and group_names must be the same as for the samples that shall be analysed with the normalisers
combined_normalisers = qpcr.combine_normalisers(preprocessed_norms)
Summarising Results: qpcr.get_stats

After Delta-CT or Delta-Delta CT results were generated they still contain all the individual grouped replicates. To collapse each group into a Mean+StDev format you may use qpcr.get_stats which takes in a results dictionary. Using the optional parameter export you may specify which statistics you which to export. Available are: "avg", "stdv", and "med" which can be combined in a list. Default is ["avg", "stdv"].

statistics = qpcr.get_stats(result)
Saving Results: qpcr.export_to_csv

qpcr.export_to_csv takes in a results dictionary and a filename and stores the results into a new csv file. Optionally you can transpose columns and rows using the argument transpose=True.

qpcr.export_to_csv(result, "my_results.csv")
Saving Raw CTs: qpcr.export_raw_data

In case you wish to also get a processed representation of your raw CT values you may use qpcr.export_raw_data which takes in an input file, as well as parameters replicates, group_names, as well as an optional export_location in case you wish to specify a directory to save the file in (by default the same folder is used where the input file is located).

Loading Results: qpcr.load_results

This function opens pre-computed results csv files. It supports two modes: "individual" (default) where filename specifies the file to be opened. It returns a dictionary containing the grouped computed values (replciates, or avg, stdev) or "pairs"which allows users to load an entire set of samples and normalisers that were previously computed to then be used by qpcr.Analysis.normalise_pairs. It returns two separate dictionaries each containing the set of sample files it was given by kwargs parameters samples and normalisers. Optionally, names may be additionally assigned to samples and normalisers using sample_names and norm_names To facilitate working with replicate assays (i.e. same qPCR assay normalised against different normalisers separately), samples / normalisers support only partial naming and need no full filepath to function. Like this multiple analysis result with e.g. "HNRNPL NMD" in their name will all be loaded.