### CFG Parser Driver Module Example Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/doc/developer_guide.md Illustrative example of a driver module for the CFG parser. Applications should adapt this structure for their specific needs. ```go package main import ( "fmt" "os" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/cfg" ) func main() { if len(os.Args) < 3 { fmt.Fprintf(os.Stderr, "usage: %s \n", os.Args[0]) os.Exit(1) } cfg.Parse(os.Args[1], os.Args[2]) } ``` -------------------------------- ### Install PyText NLP Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/doc/developer_guide.md Install the PyText NLP library using pip within an Anaconda environment. This is a prerequisite for the IE parser. ```shell pip install pytext-nlp ``` -------------------------------- ### Ingest Clinical Trials Data Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/doc/developer_guide.md Example script for ingesting clinical trial data. This script samples a limited number of trials and uses a PostgreSQL database. Modifications to 'where' clauses are often necessary. ```shell ./script/ingest.sh ``` -------------------------------- ### Represent Parsed Criteria Structures Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Example JSON output for numerical and ordinal relations extracted by the CFG parser. ```json // CFG Parser Output - Numerical/Ordinal Relations { "id": "200", "name": "age", "unit": "year", "lower": {"incl": true, "value": "18"}, "upper": {"incl": true, "value": "65"}, "variableType": "numerical", "score": 1.0 } { "id": "100", "name": "ecog", "value": ["0", "1"], "variableType": "ordinal", "score": 1.0 } { "id": "203", "name": "bmi", "unit": "kg/m2", "lower": {"incl": true, "value": "18.5"}, "upper": {"incl": false, "value": "25"}, "variableType": "numerical", "score": 1.0 } // IE Parser Output - Nominal Relations with MeSH Concepts // TSV columns: nct_id, eligibility_type, criterion, label, term, ner_score, concepts, tree_numbers, nel_score // NCT04346355 exclusion Diverticulitis or intestinal perforation word_scores:chronic_disease diverticulitis 0.996 Diverticulitis C06.405.205.282.500 1.000 // Variable types: // - nominal: disease presence (yes/no), e.g., "must have COVID-19" // - ordinal: discrete values, e.g., "ECOG 0 or 1" // - numerical: continuous ranges, e.g., "age 18-65 years" ``` -------------------------------- ### Download Clinical Trials Data Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/doc/developer_guide.md Example script for downloading clinical trial data from AACT. Applications may need to modify this script or use alternative methods for data ingestion. ```shell ./script/aact.sh ``` -------------------------------- ### Load and Use Variables Dictionary (Go) Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Demonstrates how to load a variables dictionary from a CSV file, set it globally, and then look up variables by ID, alias, or retrieve their associated questions. Ensure the CSV file path is correct. ```go package main import ( "fmt" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/variables" ) func main() { // Load variable definitions dict, _ := variables.Load("src/resources/variables/variables.csv") variables.Set(dict) catalog := variables.Get() // Look up variable by ID ageVar := catalog.Variable("200") fmt.Printf("Name: %s, Display: %s, Unit: %s\n", ageVar.Name, ageVar.Display, ageVar.UnitName) // Look up variable ID by alias id, found := catalog.ID("hemoglobin a1c") if found { fmt.Printf("Found variable ID: %s\n", id) // Output: 400 } // Get the question for a variable question := catalog.Question("203") fmt.Println(question) // Output: What is your BMI? } ``` -------------------------------- ### Manage Machine-Readable Relations in Go Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Demonstrates creating, serializing, parsing, and negating eligibility relations. ```go package main import ( "fmt" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/relation" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/variables" ) func main() { // Create a numerical relation (age requirement) ageRelation := &relation.Relation{ ID: "200", Name: "age", Unit: "year", Lower: &relation.Limit{Incl: true, Value: "18"}, Upper: &relation.Limit{Incl: true, Value: "65"}, VariableType: variables.Numerical, Score: 1.0, } // Output: {"id":"200","name":"age","unit":"year","lower":{"incl":true,"value":"18"},"upper":{"incl":true,"value":"65"},"variableType":"numerical","score":1} fmt.Println(ageRelation.JSON()) // Create an ordinal relation (ECOG score) ecogRelation := &relation.Relation{ ID: "100", Name: "ecog", Value: []string{"0", "1"}, VariableType: variables.Ordinal, Score: 1.0, } // Output: {"id":"100","name":"ecog","value":["0","1"],"variableType":"ordinal","score":1} fmt.Println(ecogRelation.JSON()) // Parse relation from JSON string jsonStr := `{"id":"203","name":"bmi","unit":"kg/m2","lower":{"incl":true,"value":"18.5"},"upper":{"incl":false,"value":"25"},"variableType":"numerical","score":1}` parsedRelation := relation.Parse(jsonStr) fmt.Printf("Variable: %s, Lower: %s, Upper: %s\n", parsedRelation.Name, parsedRelation.Lower.Value, parsedRelation.Upper.Value) // Negate a relation (for exclusion criteria) exclusionRelation := &relation.Relation{ ID: "405", Name: "platelet_count", Unit: "cells/ul", Upper: &relation.Limit{Incl: false, Value: "50000"}, VariableType: variables.Numerical, Score: 1.0, } exclusionRelation.Negate(nil) // Negates: <50000 becomes >=50000 fmt.Println(exclusionRelation.JSON()) } ``` -------------------------------- ### Build and test the CFG parser Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/README.md Commands to compile and verify the CFG parser module. ```bash go build ./... go test ./... ``` -------------------------------- ### Create and Parse Clinical Studies in Go Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Initializes a study with raw eligibility text, loads required dictionaries, and extracts machine-readable relations. ```go package main import ( "fmt" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/studies" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/units" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/variables" ) func main() { // Load variable and unit dictionaries (required before parsing) variableDictionary, _ := variables.Load("src/resources/variables/variables.csv") variables.Set(variableDictionary) unitDictionary, _ := units.Load("src/resources/units/units.csv") units.Set(unitDictionary) // Create a study with eligibility criteria eligibilityCriteria := ` Inclusion Criteria: - Age 18 to 65 years - BMI between 18.5 and 30.0 kg/m2 - ECOG performance status 0 or 1 Exclusion Criteria: - Platelets <50,000 /mmc - Pregnant or breastfeeding ` study := studies.NewStudy( "NCT12345678", // NCT ID "Example Clinical Trial", // Title []string{"COVID-19", "Diabetes"}, // Conditions eligibilityCriteria, // Raw eligibility text ) // Parse the eligibility criteria study.Parse() // Get parsed relations as TSV string relations := study.Relations() fmt.Println(relations) // Access parsed criteria directly inclusions, exclusions := study.Criteria() fmt.Printf("Inclusion criteria: %d\n", len(inclusions)) fmt.Printf("Exclusion criteria: %d\n", len(exclusions)) // Get statistics fmt.Printf("Total criteria: %d\n", study.CriteriaCount()) fmt.Printf("Parsed criteria: %d\n", study.ParsedCriteriaCount()) fmt.Printf("Relations extracted: %d\n", study.RelationCount()) } ``` -------------------------------- ### Parse Clinical Trial Criteria with Go Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Initializes dictionaries and uses the Parser and Interpreter to extract relations from criterion text. ```go package main import ( "fmt" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/parser" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/units" "github.com/facebookresearch/Clinical-Trial-Parser/src/ct/variables" ) func main() { // Initialize dictionaries variableDictionary, _ := variables.Load("src/resources/variables/variables.csv") variables.Set(variableDictionary) unitDictionary, _ := units.Load("src/resources/units/units.csv") units.Set(unitDictionary) // Create parser and parse a criterion p := parser.NewParser() // Parse individual criterion text criteria := p.Parse("age between 18 and 65 years") fmt.Printf("Parsed %d criterion segments\n", len(criteria)) // Use the interpreter for full relation extraction interpreter := parser.Get() orRelations, andRelations := interpreter.Interpret("bmi >= 18.5 and < 25 kg/m2") orRelations.Process() andRelations.Process() fmt.Printf("OR relations: %d\n", len(orRelations)) fmt.Printf("AND relations: %d\n", len(andRelations)) for _, r := range andRelations { fmt.Printf("Variable: %s, JSON: %s\n", r.Name, r.JSON()) } } ``` -------------------------------- ### Train and test the NER model Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/README.md Commands to train and evaluate the NER model using PyText configuration files. ```bash pytext train < src/resources/config/ner.json ``` ```bash pytext test < src/resources/config/ner.json ``` -------------------------------- ### Execute clinical trial parsing scripts Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/README.md Scripts to run the CFG and IE parsers on clinical trial data. ```bash ./script/cfg_parse.sh ``` ```bash ./script/ie_parse.sh ``` -------------------------------- ### Run CFG Parser for Eligibility Criteria Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Executes the CFG parser to extract numerical and ordinal requirements from clinical trial data. ```bash # Run the CFG parser on clinical trial data ./script/cfg_parse.sh # Or run directly with Go go run src/cmd/cfg/main.go \ -conf src/resources/config/cfg.conf \ -i data/input/clinical_trials.csv \ -o data/output/cfg_parsed_clinical_trials.tsv \ -logtostderr # Input CSV format (clinical_trials.csv): # nct_id,title,has_us_facility,conditions,eligibility_criteria # NCT04346355,Study Title,false,COVID-19," # Inclusion Criteria: # - age > 18 years # - BMI between 18.5 and 30.0 # Exclusion Criteria: # - Neutrophils <500 /mmc # " # Output TSV format (cfg_parsed_clinical_trials.tsv): # nct_id eligibility_type variable_type criterion_index criterion question relation # NCT04346355 inclusion numerical 0 age > 18 years How old are you? {"id":"200","name":"age","unit":"year","lower":{"incl":false,"value":"18"},"variableType":"numerical","score":1} ``` -------------------------------- ### NEL Configuration Settings Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Configuration file for Named Entity Linking (NEL) settings. Adjust vocabulary sources, NER thresholds, matching parameters, and valid NER labels to tune precision and recall for specific clinical domains. LSH parameters are used for vocabulary search optimization. ```ini # src/resources/config/nel.conf # Vocabulary source files vocabulary_file = data/mesh/descriptor.xml custom_vocabulary_file = data/mesh/custom_mesh_concepts_p1.tsv;custom_mesh_concepts_p2.tsv vocabulary_source = mesh # NER confidence threshold (entities below this are ignored) ner_threshold = 0.7 # NEL matching thresholds match_threshold = 0.75 # Minimum similarity score to accept a match match_margin = 0.02 # Margin for considering near-matches # Valid NER labels to process valid_labels = word_scores:treatment,word_scores:chronic_disease,word_scores:clinical_variable,word_scores:cancer,word_scores:gender,word_scores:pregnancy,word_scores:allergy_name,word_scores:contraception_consent,word_scores:language_fluency,word_scores:technology_access,word_scores:ethnicity # Locality-sensitive hashing parameters for vocabulary search lsh_rows = 3 lsh_bands = 16 ``` -------------------------------- ### Upgrade ONNX and Torch with Conda Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/doc/developer_guide.md Upgrade ONNX and PyTorch using Conda. These commands ensure compatibility with PyText. ```shell conda install onnx -c conda-forge ``` ```shell conda install pytorch torchvision -c pytorch ``` -------------------------------- ### Run CFG Parser Script Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/doc/developer_guide.md Execute the CFG parser using the provided shell script. This script parses clinical trial eligibility criteria and outputs relations to a TSV file. Configuration can be adjusted via command-line arguments or a config file. ```shell ./script/cfg_parse.sh ``` -------------------------------- ### Train Custom NER Model (Bash) Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Commands to train and test a custom Named Entity Recognition (NER) model using PyText. The model extracts 13 entity types, including demographics, diseases, treatments, and clinical variables. Training data should be in TSV format with entity spans and normalized text. ```bash # Train a new NER model pytext train < src/resources/config/ner.json # Test the NER model pytext test < src/resources/config/ner.json # The NER model extracts 13 entity types: # - age, bmi: demographic measurements # - cancer: cancer/tumor mentions # - chronic_disease: disease conditions # - clinical_variable: lab values, vitals # - treatment: medications, procedures # - pregnancy: pregnancy status # - gender: male/female mentions # - allergy_name: allergy mentions # - contraception_consent: contraception requirements # - language_fluency: language requirements # - technology_access: technology requirements # - ethnicity: ethnicity mentions # - lower_bound, upper_bound: numerical constraints # Training data format (data/ner/train_processed_medical_ner.tsv): # column1: entity spans (start:end:label,...) # column2: normalized text # Example: # 1:13:chronic_disease,17:30:treatment major trauma or major surgery within @NUMBER days ``` -------------------------------- ### Run IE Pipeline for Medical Entity Extraction Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Executes the three-stage IE pipeline to extract criteria, perform NER, and link entities to MeSH concepts. ```bash # Run the complete IE pipeline ./script/ie_parse.sh # The pipeline executes three stages: # Stage 1: Extract inclusion/exclusion criteria go run src/cmd/extract/main.go \ -i data/input/clinical_trials.csv \ -o data/output/ie_extracted_clinical_trials.tsv \ -logtostderr # Stage 2: Run NER to detect medical entities export PYTHONPATH="$(pwd)/src" python src/ie/ner.py \ -m bin/ner.c2 \ -i data/output/ie_extracted_clinical_trials.tsv \ -o data/output/ie_ner_clinical_trials.tsv # Stage 3: Link entities to MeSH concepts (NEL) go run src/cmd/nel/main.go \ -conf src/resources/config/nel.conf \ -i data/output/ie_ner_clinical_trials.tsv \ -o data/output/ie_parsed_clinical_trials.tsv \ -logtostderr # Output includes matched MeSH concepts: # nct_id eligibility_type criterion label term ner_score concepts tree_numbers nel_score # NCT04346355 exclusion Diverticulitis or intestinal perforation word_scores:chronic_disease diverticulitis 0.996 Diverticulitis C06.405.205.282.500 1.000 ``` -------------------------------- ### Run IE Parser Script Source: https://github.com/facebookresearch/clinical-trial-parser/blob/main/doc/developer_guide.md Execute the IE parser using the provided shell script. This script identifies medical terms and matched concepts, writing them to a TSV file. Ensure word embeddings are unzipped and MeSH vocabulary is downloaded. ```shell ./script/ie_parse.sh ``` -------------------------------- ### Ingest Clinical Trial Data from AACT Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Scripts for downloading and ingesting clinical trial data, including the underlying SQL query used for extraction. ```bash # Prerequisites: PostgreSQL 11+ installed # Download and restore AACT database snapshot ./script/aact.sh # Ingest clinical trials from AACT to CSV ./script/ingest.sh # The ingest script executes SQL queries like: # SELECT # s.nct_id, # s.brief_title, # CASE WHEN f.nct_id IS NOT NULL THEN true ELSE false END AS has_us_facility, # string_agg(DISTINCT c.name, '|') AS conditions, # e.criteria AS eligibility_criteria # FROM studies s # LEFT JOIN facilities f ON s.nct_id = f.nct_id AND f.country = 'United States' # LEFT JOIN conditions c ON s.nct_id = c.nct_id # LEFT JOIN eligibilities e ON s.nct_id = e.nct_id # WHERE s.overall_status = 'Recruiting' # GROUP BY s.nct_id, s.brief_title, e.criteria # ORDER BY s.nct_id; # Output format matches clinical_trials.csv: # nct_id,title,has_us_facility,conditions,eligibility_criteria ``` -------------------------------- ### Custom MeSH Vocabulary (TSV) Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Format for extending the MeSH vocabulary with custom medical concepts. Each line represents a concept with its name, synonyms, and MeSH tree number. This improves entity linking for domain-specific terms. ```tsv # data/mesh/custom_mesh_concepts_p1.tsv # Format: Concept NameSynonymsTree Number COVID-19 sars-cov2 infection|coronavirus disease 2019|covid C01.925 Smartphone Access smartphone|iphone|android phone|mobile phone TA01.01 Email Access email|e-mail|electronic mail TA01.02 # data/mesh/custom_mesh_concepts_p2.tsv # Additional custom concepts for contraception, language fluency, etc. Intrauterine Devices, Consent intrauterine device|iud CC01.03.01 Language Fluency, English fluent english|english fluency|speak english LF01.01 ``` -------------------------------- ### Variables Dictionary CSV Format Source: https://context7.com/facebookresearch/clinical-trial-parser/llms.txt Header definition for the medical variables CSV file. ```csv # src/resources/variables/variables.csv # variable_id,variable_type,variable_name,display_name,aliases,bounds,default_unit_name,question ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.