Documentation ¶
Index ¶
- Constants
- func AddDiagnosis(p *Patient, d *Diagnosis)
- func AgeAtDiagnosis(p *Patient, DID int) int
- func AgeAtEOI(p *Patient) int
- func CompactDiagnoses(p *Patient)
- func DiagnosisDateSmallerThan(d1, d2 DiagnosisDate) bool
- func DiagnosisDateToFloat(d DiagnosisDate) float64
- func InitializeExperimentRelativeRiskRatios(exp *Experiment, minTime, maxTime float64, iter int)
- func LoadDxDPatients(exp *Experiment, pMap *PatientMap, path string)
- func LoadRRMatrix(exp *Experiment, path string)
- func MakeDxDPatients(size int) [][][]*Patient
- func MakeDxDRR(size int) [][]float64
- func MetricsFromTrajectories(trajectories []*Trajectory) (float64, float64, float64, float64, int, int)
- func PrintClusteredTrajectoriesToFile(exp *Experiment, name string)
- func PrintClustersToCSVFiles(exp *Experiment, pName, cName string)
- func PrintCohort(cohort *Cohort, max int)
- func PrintTrajectoriesToFile(exp *Experiment, path string)
- func PrintTrajectory(t *Trajectory, exp *Experiment)
- func SaveDxDPatients(exp *Experiment, path string)
- func SaveRRMatrix(exp *Experiment, path string)
- func SortDiagnoses(p *Patient)
- type Cohort
- type Diagnosis
- type DiagnosisDate
- type Experiment
- type Pair
- type Patient
- type PatientFilter
- func AboveSeventyAggregator() PatientFilter
- func EOIAfterFilter() PatientFilter
- func EOIBeforeFilter() PatientFilter
- func EOIFilter(test func(d1, d2 DiagnosisDate) bool) PatientFilter
- func FemaleFilter() PatientFilter
- func LessThanSeventyAggregator() PatientFilter
- func MaleFilter() PatientFilter
- func SexFilter(sex int) PatientFilter
- type PatientMap
- type Trajectory
- type TrajectoryFilter
Constants ¶
const ( Male = 0 Female = 1 )
Variables ¶
This section is empty.
Functions ¶
func AddDiagnosis ¶
AddDiagnosis apptents a diagnosis to a patient's list of diagnoses.
func AgeAtDiagnosis ¶
AgeAtDiagnosis calculates the age of a patient at a specific diagnosis
func AgeAtEOI ¶
AgeAtEOI calculates the age of a patient at the event of interest (e.g. cancer diagnosis)
func CompactDiagnoses ¶
func CompactDiagnoses(p *Patient)
CompactDiagnoses makes a sorted diagnosis list contain unique diagnoses for a patient. Want to avoid over counting diagnoses.
func DiagnosisDateSmallerThan ¶
func DiagnosisDateSmallerThan(d1, d2 DiagnosisDate) bool
func DiagnosisDateToFloat ¶
func DiagnosisDateToFloat(d DiagnosisDate) float64
DiagnosisDateToFloat converts a diagnosis date to a floating point number.
func InitializeExperimentRelativeRiskRatios ¶
func InitializeExperimentRelativeRiskRatios(exp *Experiment, minTime, maxTime float64, iter int)
InitializeExperimentRelativeRiskRatios computes the relative risk ratios for each possible diagnosis pair in an experiment. It takes into account the minimum and maximum time between diagnoses (minTime and maxTime). It is an iterative algorithm that runs for a given number of iterations (iter). With iter = 400, the calculated p-values are within 0.05 of the true p-values and with iter = 10000 they are within 0.01 of the true p-values. The relative risk ratios are calculated in parallel for all possible diagnosis pairs.
func LoadDxDPatients ¶
func LoadDxDPatients(exp *Experiment, pMap *PatientMap, path string)
LoadDxDPatients loads the DxD patients from a file created during a previous run. It takes as parameters the experiment (exp), the patient map where to look up patient objects parsed from the input (pMap), and the file name (path). The function side effects the experiment's DxDPatients slice. It uses the pMap to match concrete patient objects with IDs stored in the file to be able to fill the patients for each pair of diagnoses.
func LoadRRMatrix ¶
func LoadRRMatrix(exp *Experiment, path string)
LoadRRMatrix loads an RR matrix from file and stores it in the given experiment. This file was created from a previous run. This can be used instead of initializeRelativeRiskRatiosParallel
func MakeDxDPatients ¶
MakeDxDPatients makes a diagnosis by diagnosis-sized matrix for storing the list of patients for each possible diagnosis pair.
func MakeDxDRR ¶
MakeDxDRR makes a diagnosis by diagnosis-sized matrix for storing the relative risk score for each possible diagnosis pair.
func MetricsFromTrajectories ¶
func MetricsFromTrajectories(trajectories []*Trajectory) (float64, float64, float64, float64, int, int)
MetricsFromTrajectories computes: * mean age + standard deviation + median age for patients in the trajectories. Patients can occur in different trajectories. For mean age + sd + median, they will be counted as separate instances. * #patients per age category (normalized in percentages, not absolute numbers). Patients that occr in different trajectories will be counted as separate instances for these age categories. * #males, #females * mean survival time after event of interest
func PrintClusteredTrajectoriesToFile ¶
func PrintClusteredTrajectoriesToFile(exp *Experiment, name string)
PrintClusteredTrajectoriesToFile plots the trajectories of an experiment to a tab file, including for each trajectory information about the cluster a trajectory belongs to. For each trajectory it prints 3 lines: - A line with the cluster ID and the trajectory ID: CID: \tab nr \tab TID: \tab nr. - A list of medical terms for the diagnoses: term1 \tab term2 ...\tab termn. - A list of patient numbers for the transitions between diagnosis pairs: nr1->2 \tab nr2->3 ...\tab nrn-1->n.
func PrintClustersToCSVFiles ¶
func PrintClustersToCSVFiles(exp *Experiment, pName, cName string)
PrintClustersToCSVFiles prints the experiment clusters to a CSV file. It creates two output files: - A CSV file with patient information. The header is: PID,AgeEOI,Sex,PIDString. This represents: patient analysis id, age at which the event of interest occurred, sex, and the TriNetX patient id. - A CSV file with cluster information. The header is: PID,CID,TID,Age. This represents: patient id, cluster id, trajectory id, and age of the patient when matching the trajectory.
func PrintCohort ¶
PrintCohort prints a cohort to standard output.
func PrintTrajectoriesToFile ¶
func PrintTrajectoriesToFile(exp *Experiment, path string)
PrintTrajectoriesToFile outputs an experiment's calculated trajectories to file in multiple formats: - A tab file containing trajectories as lists of medical terms and lists of numbers of patients for each transition - A tab file containing all disease pairs and their relative risk scores (medical terms + float for RR) - A GML file with one graph representing all trajectories - A GML file where each trajectory is represented as an individual subgraph
func PrintTrajectory ¶
func PrintTrajectory(t *Trajectory, exp *Experiment)
PrintTrajectory prints a trajectory to standard output.
func SaveDxDPatients ¶
func SaveDxDPatients(exp *Experiment, path string)
SaveDPatients saves per disease the PIDs that are diagnosed with this disease
func SaveRRMatrix ¶
func SaveRRMatrix(exp *Experiment, path string)
SaveRRMatrix stores the RR matrix calculated for the given experiment. The diagnosis pairs from the matrix are stored line per line as follows: medical name 1, medical name 2, RR.
func SortDiagnoses ¶
func SortDiagnoses(p *Patient)
sortDiagnosis modifies a given patient's list of diagnoses to be ordered by date.
Types ¶
type Cohort ¶
type Cohort struct {
AgeGroup, Sex, Region, NofPatients, NofDiagnoses int
DCtr []int //counts nr of patients per DID
DPatients [][]*Patient //contains a list of patients per DID
Patients []*Patient //the patients in this cohort
}
Cohort represents a specific group of patients from the population stratified by age, sex, and region. The population is divided into male and female cohorts. Those cohorts are in turn split into cohorts depending on an age range, e.g. this could be one for each possible age range apart by 10 years: [0-10], [10-20],[20-30]...[100-120].
func InitializeCohorts ¶
func InitializeCohorts(patients *PatientMap, nofAgegroups, nofRegions, nofDiagnosisCodes int) []*Cohort
InitializeCohorts creates cohorts + initializes them with the counts for each diagnosis + patients per diagnosis
func MergeCohorts ¶
MergeCohorts returns a single cohort that merges a list of input cohorts. The goal is to obtain a merged list of patients, a merged patient total, and a merged disease total.
type Diagnosis ¶
type Diagnosis struct {
PID, DID int
Date DiagnosisDate
}
Diagnosis represents a diagnosis for a patient.
type DiagnosisDate ¶
type DiagnosisDate struct {
Year, Month, Day int
}
DiagnosisDate represents the date of a diagnosis, with fields for representing the year, month, and day of diagnosis.
type Experiment ¶
type Experiment struct {
NofAgeGroups, NofRegions, Level, NofDiagnosisCodes int
DxDRR [][]float64 //per disease pair, relative risk score (RR)
DxDPatients [][][]*Patient //per disease pair, all patients diagnosed
DPatients [][]*Patient //per disease, all patients diagnosed
Cohorts []*Cohort //cohorts in the experiment
Name string //name of the experiment, for printing
NameMap map[int]string // maps diagnosis ID to medical name
Trajectories []*Trajectory // a list of computed trajectories
Pairs []*Pair // a list of all selected pairs that are used to compute trajectories
IdMap map[int]string // maps the analysis DID to the original diagnostic ID used in the input data
MCtr, FCtr int //counters for counting nr of males,females,patients
}
Experiment contains the inputs and outputs for calculating diagnosis trajectories for a specific patient population.
type Pair ¶
type Pair struct {
First, Second int
}
Pair is a struct for representing a diagnosis pair. It simply stores two diagnosis codes.
type Patient ¶
type Patient struct { PID int //analysis ID PIDString string //ID from TriNetX YOB int //year of birth CohortAge int //age range a patient belongs to Sex int //0 = male, 1 = female Diagnoses []*Diagnosis //list of patient's diagnoses, sorted by date <, unique diagnosis per date EOIDate *DiagnosisDate //Event of interest date, e.g. day of cancer diagnosis DeathDate *DiagnosisDate //Date of death Region int //Region where the patient lives }
Patient represents patient information.
func AppendPatient ¶
AppendPatient appends a patient to a slice of patients, unless that patient is already a member of that slice.
func GetPatient ¶
func GetPatient(pidString string, patients *PatientMap) (*Patient, bool)
GetPatient retrieves from a patient map the patient object associated with a given patient ID. The patient ID is passed as a string and refers to the PID that occurs in the input.
type PatientFilter ¶
PatientFilter prescribes a function type for implementing filters on TriNetX patients, to be able to calculate trajectories for specific cohorts. E.g. male patients, patients <70 years, patients with specific cancer stage, etc.
func AboveSeventyAggregator ¶
func AboveSeventyAggregator() PatientFilter
AboveSeventyAggregator collects all patients above a specific age.
func EOIAfterFilter ¶
func EOIAfterFilter() PatientFilter
EOIAfterFilter removes all diagnoses after the event of interest date
func EOIBeforeFilter ¶
func EOIBeforeFilter() PatientFilter
EOIBeforeFilter removes all diagnoses before the event of interest date
func EOIFilter ¶
func EOIFilter(test func(d1, d2 DiagnosisDate) bool) PatientFilter
EOIFilter removes all diagnoses for patients that satisfy a given predicate
func LessThanSeventyAggregator ¶
func LessThanSeventyAggregator() PatientFilter
LessThanSeventyAggregator collects all patients below a specific age.
func SexFilter ¶
func SexFilter(sex int) PatientFilter
SexFilter removes all patients of the given sex.
type PatientMap ¶
type PatientMap struct { PIDStringMap map[string]int //maps patient string id onto an int PID Ctr int //total nr of patients parsed, also used for creating PIDs PIDMap map[int]*Patient //maps PID onto a patient object that contain YOB, sex, age group, etc // optional info for logging MaleCtr int FemaleCtr int }
PatientMap contains all patient information parsed from the input.
func ApplyPatientFilter ¶
func ApplyPatientFilter(filter PatientFilter, pMap *PatientMap) *PatientMap
func ApplyPatientFilters ¶
func ApplyPatientFilters(filters []PatientFilter, pMap *PatientMap) *PatientMap
type Trajectory ¶
type Trajectory struct { Diagnoses []int // A list of diagnosis codes that represent the trajectory PatientNumbers []int // A list with nr of patients for each transition in the trajectory Patients [][]*Patient // A list of patients with the given trajectory TrajMap map[*Patient]int //Maps patient IDs onto a diagnosis index for trajectory tracking ID int // An analysis id Cluster int //A cluster ID to which this trajectory is assigned to }
Trajectory holds all data relevant to a disease trajectory.
func BuildTrajectories ¶
func BuildTrajectories(exp *Experiment, minPatients, maxLength, minLength int, minTime, maxTime, minRR float64, filters []TrajectoryFilter) []*Trajectory
BuildTrajectories calculates the trajectories for an experiment. The trajectories are constrained by: a minimum number of patients in the trajectory (minPatients), a maximum number of diagnoses in the trajectory (maxLength), a minumum number of diagnoses in the trajectory (minLength), a minimum RR for each diagnosis transition (minRR), and a list of filters.
type TrajectoryFilter ¶
type TrajectoryFilter func(t *Trajectory) bool
TrajectoryFilter is a type to define a trajectory filter function. Such filters take as input a trajectory and must return a bool as output that determines if a trajectory passes a filter or not.