lib

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2025 License: AGPL-3.0, AGPL-3.0-or-later Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Male   = 0
	Female = 1
)

Variables

View Source
var InitializeIcd10AnalysisMaps = initializeIcd10AnalysisMaps
View Source
var InitializeIcd10AnalysisMapsFromXML = initializeIcd10AnalysisMapsFromXML
View Source
var InitializeIcd10NameMap = initializeIcd10NameMap
View Source
var ParseIcd10HierarchyFromXml = parseIcd10HierarchyFromXml
View Source
var ParseIcd9ToIcd10Mapping = parseIcd9ToIcd10Mapping
View Source
var ParseTriNetXPatientData = parseTriNetXPatientData
View Source
var ParseTrinetXPatientDiagnoses = parseTrinetXPatientDiagnoses
View Source
var PrintIcd10Hierarchy = printIcd10Hierarchy
View Source
var PrintIcd10NameMap = printIcd10NameMap

Functions

func AgeAtDiagnosis

func AgeAtDiagnosis(p *Patient, DID int) int

AgeAtDiagnosis calculates the age of a patient at a specific diagnosis

func AgeAtEOI

func AgeAtEOI(p *Patient) int

AgeAtEOI calculates the age of a patient at the event of interest (e.g. cancer diagnosis)

func ClusterTrajectories

func ClusterTrajectories(exp *Experiment, granularities []int, path string) error

ClusterTrajectories performs clustering of the trajectories that have been calculated for a given experiment. It does a pairwise comparison of all trajectories by calculating the jaccard similarity coefficients. Subsequently, MCL clustering is used to group the trajectories by jaccard similarity into clusters.

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 LogTrajectory

func LogTrajectory(t *Trajectory, exp *Experiment)

LogTrajectory prints a trajectory to standard output.

func MakeDxDPatients

func MakeDxDPatients(size int) [][][]*Patient

MakeDxDPatients makes a diagnosis by diagnosis-sized matrix for storing the list of patients for each possible diagnosis pair.

func MakeDxDRR

func MakeDxDRR(size int) [][]float64

MakeDxDRR makes a diagnosis by diagnosis-sized matrix for storing the relative risk score for each possible diagnosis pair.

func Mcl

func Mcl(mciFilePath string, granularity int) error

Mcl calls the mcl binary.

func McxDump

func McxDump(clusterFileName string, tabFileName string, outFileName string, granularity int) error

McxDump calls the mcxdump binary.

func McxLoadAbc

func McxLoadAbc(abcFilePath string, tabFilePath string, mciFilePath string) error

McxLoadAbc calls the mcxload binary for an abc-file.

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 ParseTriNetXData

func ParseTriNetXData(name, patientFile, diagnosisFile, diagnosisInfoFile, treatmentInfoFile string, nofCohortAges,
	level int, minYears, maxYears float64, icd9ToIcd10File string, filters []PatientFilter) (*Experiment, *PatientMap)

func ParsetTriNetXTumorData

func ParsetTriNetXTumorData(fileName string) map[string][]*TumorInfo

ParsetTriNetXTumorData parses the tumor data from a csv file and returns a map PIDString -> []*TumorInfo.

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 Run

func Run(args *ExperimentParams) (err error)

Run runs a TriNetX experiment with the given parameters.

func SorensenDiceTrajectory

func SorensenDiceTrajectory(t1, t2 *Trajectory) float64

SorensenDiceTrajectory computes the SorensenDice similarity coefficient for two given trajectories.

func SortDiagnoses

func SortDiagnoses(p *Patient)

SortDiagnoses modifies a given patient's list of diagnoses to be ordered by date.

func SzymkiewiczSimpsonTrajectory

func SzymkiewiczSimpsonTrajectory(t1, t2 *Trajectory) float64

SzymkiewiczSimpsonTrajectory computes the Szymkiewicz-Simpson similarity coefficient for two given trajectories.

func TriNetXEventOfInterest

func TriNetXEventOfInterest(icd10ID string) bool

TriNetXEventOfInterest checks if the ICD10 code is related to bladder cancer

Types

type AnalysisMaps

type AnalysisMaps interface {
	GetICDCode(did int) string
	// contains filtered or unexported methods
}

AnalysisMaps represent maps extracted from the input that map analysis IDs onto medical terms and vice versa. This is an interface that defines several methods. getICDCode returns for a did the original id in the input for the diagnostic event. fillInPatientDiagnoses creates for a given diagnosis identifier from the input a Diagnosis object and adds it to a patient's list of diagnoses.

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 InitCohorts

func InitCohorts(patients *PatientMap, nofAgegroups, nofRegions, nofDiagnosisCodes int) []*Cohort

InitCohorts creates cohorts + initializes them with the counts for each diagnosis + patients per diagnosis

func MergeCohorts

func MergeCohorts(cohorts []*Cohort) *Cohort

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.

func (Cohort) Log

func (cohort Cohort) Log(max int)

Log prints a cohort to standard output.

type Diagnosis

type Diagnosis struct {
	PID, DID int
	Date     DiagnosisDate
	Icd10    Icd10Entry
}

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
	Icd10Map                                           map[int]Icd10Entry // maps diagnosis ID to Icd10Entry
	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.

func (*Experiment) BuildTrajectories

func (exp *Experiment) BuildTrajectories(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 minimum number of diagnoses in the trajectory (minLength), a minimum RR for each diagnosis transition (minRR), and a list of filters.

func (*Experiment) InitRR

func (exp *Experiment) InitRR(minTime, maxTime float64, iter int)

InitRR 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 (*Experiment) LoadDxDPatients

func (exp *Experiment) LoadDxDPatients(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 (*Experiment) LoadRRMatrix

func (exp *Experiment) LoadRRMatrix(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 (*Experiment) PrintTrajectoriesToFile

func (exp *Experiment) PrintTrajectoriesToFile(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 (*Experiment) SaveDxDPatients

func (exp *Experiment) SaveDxDPatients(path string)

SaveDxDPatients saves per disease the PIDs that are diagnosed with this disease

func (*Experiment) SaveRRMatrix

func (exp *Experiment) SaveRRMatrix(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.

type ExperimentParams

type ExperimentParams struct {
	// required parameters
	Name             string
	PatientInfo      string // path to the file with patient information (ID, gender," + birthyear, etc)
	DiagnosisInfo    string // path to the file with diagnosis information (ID,descriptor, hierarchy, etc)
	PatientDiagnoses string // path to the file with patient diagnoses.
	OutputPath       string // path where output files are written to.

	// optional parameters
	NofAgeGroups         int
	Lvl                  int
	MaxYears             float64
	MinYears             float64
	MinPatients          int
	MaxTrajectoryLength  int
	MinTrajectoryLength  int
	ICD9ToICD10File      string
	Cluster              bool
	ClusterGranularities string
	Iter                 int
	RR                   float64
	SaveRR               string
	LoadRR               string
	PFilters             string
	TFilters             string
	TumorInfo            string
	TreatmentInfo        string
	NrOfThreads          int
}

type Icd10Entry

type Icd10Entry struct {
	Name       string    // medical Name for a DID in ICD10 encoding
	Categories [6]string // the names of the ICD10 encoding higher and lower in the hierarchy.
	Level      int       // the ICD10 hierarchy Level of this Name.
}

Icd10Entry is a struct for containing a medical Name + Level + the Categories of a DID in ICD10 encoding.

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

func AppendPatient(plist []*Patient, p *Patient) []*Patient

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.

func (*Patient) AddDiagnosis

func (p *Patient) AddDiagnosis(d *Diagnosis)

AddDiagnosis appends a diagnosis to a patient's list of diagnoses.

type PatientFilter

type PatientFilter func(patient *Patient) bool

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 FemaleFilter

func FemaleFilter() PatientFilter

FemaleFilter removes all female patients.

func GetPatientFilter

func GetPatientFilter(s string, tinfo map[string][]*TumorInfo) PatientFilter

func GetPatientFilters

func GetPatientFilters(filters string, tinfo map[string][]*TumorInfo) []PatientFilter

func LessThanSeventyAggregator

func LessThanSeventyAggregator() PatientFilter

LessThanSeventyAggregator collects all patients below a specific age.

func M0StageAggregator

func M0StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

M0StageAggregator collects patients with stage M0 bladder cancer.

func M1StageAggregator

func M1StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

M1StageAggregator collects patients with stage M1 bladder cancer.

func MIBCAggregator

func MIBCAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

MIBCAggregator checks all patients if they match the cancer criteria to be defined as muscle invasive bladder cancer patients.

func MUCAggregator

func MUCAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

MUCAggregator checks all patients if they match the cancer criteria to be defined as metastisized bladder cancer patients.

func MaleFilter

func MaleFilter() PatientFilter

MaleFilter removes all male patients.

func N0StageAggregator

func N0StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

N0StageAggregator collects patients with stage N0 bladder cancer.

func N1StageAggregator

func N1StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

N1StageAggregator collects patients with stage N1 bladder cancer.

func N2StageAggregator

func N2StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

N2StageAggregator collects patients with stage N2 bladder cancer.

func N3StageAggregator

func N3StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

N3StageAggregator collects patients with stage N0 bladder cancer.

func NMIBCAggregator

func NMIBCAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

NMIBCAggregator checks all patients if they match the cancer criteria to be defined as non muscle invasive bladder cancer patients.

func SexFilter

func SexFilter(sex int) PatientFilter

SexFilter removes all patients of the given sex.

func T1StageAggregator

func T1StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

T1StageAggregator collects patients with stage T1 bladder cancer.

func T2StageAggregator

func T2StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

T2StageAggregator collects patients with stage T2 bladder cancer.

func T3StageAggregator

func T3StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

T3StageAggregator collects patients with stage T3 bladder cancer.

func T4StageAggregator

func T4StageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

T4StageAggregator collects patients with stage T4 bladder cancer.

func TaStageAggregator

func TaStageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

TaStageAggregator collects patients with stage Ta bladder cancer.

func TisStageAggregator

func TisStageAggregator(tinfoMap map[string][]*TumorInfo) PatientFilter

TisStageAggregator collects patients with stage Tis bladder cancer.

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.

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.

func BladderCancerTrajectoryFilter

func BladderCancerTrajectoryFilter(exp *Experiment) TrajectoryFilter

BladderCancerTrajectoryFilter filters trajectories down to trajectories with at least one diagnosis that is related to bladder cancer specifically, cf. ICD10 Categories C67,C77,C78,C79 or procedures such as MVAC chemo, IVT treatment, or radical cystectomy.

func CancerTrajectoryFilter

func CancerTrajectoryFilter(exp *Experiment) TrajectoryFilter

CancerTrajectoryFilter filters trajectories down to trajectories that contain at least one diagnosis code that is considered to be cancer-related, e.g. containing the word "neoplasm".

func GetTrajectoryFilter

func GetTrajectoryFilter(filter string, exp *Experiment) TrajectoryFilter

func GetTrajectoryFilters

func GetTrajectoryFilters(filters string, exp *Experiment) []TrajectoryFilter

type TreatmentInfo

type TreatmentInfo struct {
	RCDate   *DiagnosisDate //Date of radical cystectomy
	MVACDate *DiagnosisDate //Date of MVAC chemotherapy
	IVTDate  *DiagnosisDate //Date of intravesical therapy
}

TreatmentInfo implements a structure for storing the dates of certain bladder cancer treatments.

type TumorInfo

type TumorInfo struct {
	TStage, NStage, MStage, Stage string
	Date                          DiagnosisDate
}

TumorInfo is a struct for storing bladder cancer tumor information concerning: tumor size, tumor lymph nodes, tumor metastasis

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL