Neural Responses to Affective Sentences Reveal Signatures of Depression.
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 176 lines · 8.4 KB · no license
- import torch
- import json, os, sys, glob, pickle, csv, tqdm
- import numpy as np
- from sklearn.metrics import balanced_accuracy_score, f1_score, precision_score, recall_score, roc_auc_score, confusion_matrix, roc_curve
- from src.models.eegnet import eegnet, eegnet_late_fusion
- from src.models.rcnn import rcnn, rcnn_late_fusion, eegTransformer, eegTransformerLateFusion
- device = "cuda" if torch.cuda.is_available() else "cpu"
- label_map = {
- 0: "control",
- 1: "clinical"
- }
- def get_sensitivity_at_specificity(y_true, y_scores, target_specificity: float=0.7):
- fpr, tpr, thresholds = roc_curve(y_true, y_scores)
- specificity = 1 - fpr
- idx = np.argmin(np.abs(specificity - target_specificity))
- return tpr[idx]
- def load_model(model, checkpoint_path):
- checkpoint_dict = torch.load(checkpoint_path)
- model.load_state_dict(checkpoint_dict["model_state_dict"])
- model.to(device)
- model.eval()
- return model
- def inference_subjects(config_path,
- checkpoint_path,
- mode: str="test",
- custom_subject_path: str=None,
- test_all: bool=False):
- config = json.load(open(config_path, "r"))
- analytical_pipeline_list = list()
- conditions_list = []
- for condition in config["conditions"]:
- prefix = ""
- for k, values in condition.items():
- prefix += f"{k}-" + "-".join(values) + "_"
- prefix = prefix.strip("_")
- conditions_list.append(prefix)
- if config["model_type"] == "eegnet":
- if config["feature_type"] == "subtract":
- model = eegnet(**config["model_params"])
- elif config["feature_type"] == "late_fusion":
- model = eegnet_late_fusion(**config["model_params"])
- elif config["model_type"] == "rcnn":
- if config["feature_type"] == "subtract":
- model = rcnn(**config["model_params"])
- elif config["feature_type"] == "late_fusion":
- model = rcnn_late_fusion()
- elif config["model_type"] == "transformer":
- if config["feature_type"] == "subtract":
- model = eegTransformer(**config["model_params"])
- elif config["feature_type"] == "late_fusion":
- model = eegTransformerLateFusion(**config["model_params"])
- model = load_model(model, checkpoint_path)
- if mode == "test":
- if custom_subject_path is None:
- subjects_info_path = config["test_subjects_info_path"]
- else:
- subjects_info_path = custom_subject_path
- elif mode == "train":
- subjects_info_path = config["train_subjects_info_path"]
- subjects_info = json.load(open(subjects_info_path, "r"))
- labels_list, preds_list = list(), list()
- preds_conf_list = list()
- for subid, subject_info in subjects_info.items():
- if not test_all and str(subject_info["label"]) not in config["classification_groups"].keys():
- continue
- subject_files = []
- for condition in conditions_list:
- datadir_condition = os.path.join(config["datadir"], config["task"], f"{config['subdir']}-{config['percent_data_use']:.2f}", condition, subid)
- if "resample_rate" in config.keys():
- datadir_condition = os.path.join(config["datadir"], config["task"], f"{config['subdir']}-{config['percent_data_use']:.2f}-rate{config['resample_rate']}", condition, subid)
- if "n_trials_gen" in config.keys() and "n_trials_mean" in config.keys():
- datadir_condition = os.path.join(config["datadir"], config["task"], f"{config['subdir']}-{config['percent_data_use']:.2f}-ntrials-{config['n_trials_gen']}-nmean-{config['n_trials_mean']}-rate{config['resample_rate']}", condition, subid)
- condition_sub_files = glob.glob(datadir_condition + "/*.pkl")
- condition_sub_files.sort()
- subject_files.append(condition_sub_files)
- subject_files = list(zip(*subject_files))
- if len(subject_files) == 0:
- continue
- data_subject = []
- for subject_file in subject_files:
- if len(conditions_list) == 1:
- data_subject.append(pickle.load(open(subject_file[0], "rb"))["data"])
- elif len(conditions_list) == 2:
- if config["feature_type"] == "subtract":
- data_subject.append(pickle.load(open(subject_file[0], "rb"))["data"] - pickle.load(open(subject_file[1], "rb"))["data"])
- elif config["feature_type"] == "late_fusion":
- data_subject.append([pickle.load(open(subject_file[0], "rb"))["data"], pickle.load(open(subject_file[1], "rb"))["data"]])
- with torch.no_grad():
- if config["feature_type"] == "late_fusion":
- data_subject_tensor = list()
- data_subject_tensor.append(torch.tensor(np.array([d[0] for d in data_subject]), dtype=torch.float32).to(device))
- data_subject_tensor.append(torch.tensor(np.array([d[1] for d in data_subject]), dtype=torch.float32).to(device))
- outputs = model(data_subject_tensor)
- else:
- if "spatial_region" not in config.keys():
- data_subject = np.array(data_subject, dtype=np.float32)[:, :, :int((200 + config.get("max_time", 1000))/5)]
- else:
- channels_dict = json.load(open(config["spatial_info_path"], "r"))
- channel_picks = channels_dict[config["spatial_region"]]
- data_subject = np.array(data_subject, dtype=np.float32)[:, channel_picks, :int((200 + config.get("max_time", 1000))/5)]
- outputs = model(torch.tensor(data_subject).to(device))
- preds = torch.argmax(outputs, dim=-1).detach().cpu().numpy()
- outputs_conf = outputs.detach().cpu().numpy()
- outputs_conf = outputs_conf[np.where(np.abs(outputs_conf[:, 0] - outputs_conf[:, 1]) > 0.2)]
- labels_list.append(config["classification_groups"][str(subject_info["label"])] if str(subject_info["label"]) in config["classification_groups"].keys() else 1)
- preds_list.append(np.sum(preds)/len(data_subject))
- preds_conf_list.append(np.sum(np.argmax(outputs_conf, axis=-1))/outputs_conf.shape[0])
- analytical_pipeline_list.append({
- "subID": subid,
- "Task": "sen",
- "Probability": np.sum(preds)/len(data_subject),
- "Prediction": int(np.sum(preds)/len(data_subject)> 0.5),
- "label": str(subject_info["label"]),
- "Ground Truth": config["classification_groups"][str(subject_info["label"])] if str(subject_info["label"]) in config["classification_groups"].keys() else 1,
- "Score": int(np.sum(preds)/len(data_subject)> 0.5) == int(config["classification_groups"][str(subject_info["label"])] if str(subject_info["label"]) in config["classification_groups"].keys() else 1)
- })
- rocauc = roc_auc_score(np.array(labels_list), np.array(preds_list))
- tn, fp, fn, tp = confusion_matrix(np.array(labels_list), np.array(preds_list)>0.5).ravel()
- sensitivity_05 = tp / (tp + fn)
- specificity = tn / (tn + fp)
- bac = balanced_accuracy_score(np.array(labels_list), np.array(preds_list)>0.5)
- f1 = f1_score(np.array(labels_list), np.array(preds_list)>0.5)
- sensitivity = get_sensitivity_at_specificity(np.array(labels_list), np.array(preds_list), 0.7)
- results_dict = {
- "BAC": bac,
- "AUC": rocauc,
- "sensitivity": sensitivity_05,
- "specificity": specificity,
- "f1": f1
- }
- if not test_all:
- json.dump(results_dict, open(os.path.join(os.path.dirname(checkpoint_path), "results.json"), "w"), indent=4)
- if test_all:
- csv_file_path = os.path.join(os.path.dirname(checkpoint_path), "analytical_pipeline_all.csv")
- else:
- csv_file_path = os.path.join(os.path.dirname(checkpoint_path), "analytical_pipeline.csv")
- header = analytical_pipeline_list[0].keys()
- with open(csv_file_path, mode='w', newline='') as file:
- writer = csv.DictWriter(file, fieldnames=header)
- writer.writeheader()
- writer.writerows(analytical_pipeline_list)
- if __name__ == "__main__":
- checkpoint_dir = sys.argv[1]
- checkpoint_paths = glob.glob(checkpoint_dir + "/*/*/best.pt")
- checkpoint_paths.sort()
- for checkpoint_path in tqdm.tqdm(checkpoint_paths):
- config_path = os.path.join(os.path.dirname(checkpoint_path), "config.json")
- # get the inference on the test subjects
- inference_subjects(config_path, checkpoint_path, test_all=False)
get_inference_subjects.py at commit 680c06b, no license · at the source
Overview
- Ming Hsieh Department of Electrical and Computer Engineering, University of Southern California,Los Angeles, USA
- Alfred E. Mann Department of Biomedical Engineering, University of Southern California,Los Angeles, USA
- Thomas Lord Department of Computer Science, University of Southern California,Los Angeles, USA
- Brain and Creativity Institute, University of Southern California,Los Angeles, USA
- Department of Psychology, University of California Los Angeles,Los Angeles, USA
- Department of Linguistics, University of Southern California,Los Angeles, USA
- Department of Psychiatry and Behavioral Sciences, University of Southern California,Los Angeles, USA
- Department of Psychology, University of Southern California,Los Angeles, USA
Abstract
The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.
Repository
Its files are read in the Code ↔ Paper reader above.
Uncertain-Quark/eeg_depression_classification_tpsych
680c06bf3ea8190044b8c8b31faef0abdcfd84e1, 24 November 2025Availability: 1 check, the latest on 28 September 2026: the link answers
- 28 September 2026: the link answers
17 files
- get_inference_subjects.p
y , Python, 176 lines - get_results.py, Python, 186 lines
- main_multiseed_parallel.
py , Python, 168 lines - make_attributes.py, Python, 42 lines
- make_data.py, Python, 101 lines
- preprocess.sh, Shell, 39 lines
- src/
data/ , Python, 401 linesmake_data.py - src/
data/ , Python, 220 linesprecog.py - src/
models/ , Python, 95 lineseegnet.py - src/
models/ , Python, 48 lineslayers.py - src/
models/ , Python, 260 linesrcnn.py - src/
trainer/ , Python, 163 linestrainer.py - src/
utils/ , Python, 143 linesmake_attributes.py - src/
utils/ , Python, 45 linesmake_subjects_json.py - src/
utils/ , Python, 75 linesmake_subjects_labels.py - src/
utils/ , Python, 80 linesmat2pkl.py - README.md, Text, 17 lines
Code availability statement
The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to the authors' code: Uncertain-Quark/
eeg_depression_classific ation_tpsych
Read it in the paper: doi.org/10.1038/s41398-026-04079-2.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 16 scripts, each with its path and the digest of its content;
- no match between paragraphs and code yet;
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data availability statement
The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it says that the data are available on request
Read it in the paper: doi.org/10.1038/s41398-026-04079-2.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 28 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 16 authors, 2 keywords, 13 MeSH terms, 1 funder, 50 references.
Cite
This paper
Kommineni, A., Jeong, W., Avramidis, K., McDaniel, C., Hughes, M., McGee, T., Kaiser, E., Lerman, K., Blank, I. A., Byrd, D., Habibi, A., Cahn, B. R., Kadiri, S., Medani, T., Leahy, R. M., & Narayanan, S. (2026). Neural Responses to Affective Sentences Reveal Signatures of Depression. Translational psychiatry, 16(1), 347. https://
BibTeX
@article{kommineni2026ne
author = {Kommineni, Aditya and Jeong, Woojae and Avramidis, Kleanthis and McDaniel, Colin and Hughes, Myzelle and McGee, Thomas and Kaiser, Elsi and Lerman, Kristina and Blank, Idan A. and Byrd, Dani and Habibi, Assal and Cahn, B. Rael and Kadiri, Sudarsana and Medani, Takfarinas and Leahy, Richard M. and Narayanan, Shrikanth},
title = {{Neural Responses to Affective Sentences Reveal Signatures of Depression}},
journal = {Translational psychiatry},
year = {2026},
month = may,
volume = {16},
number = {1},
pages = {347},
publisher = {Nature Publishing Group},
issn = {2158-3188},
doi = {10.1038/
url = {https://
pmid = {42140957},
pmcid = {PMC13346668}
}
RIS
TY - JOUR
AU - Kommineni, Aditya
AU - Jeong, Woojae
AU - Avramidis, Kleanthis
AU - McDaniel, Colin
AU - Hughes, Myzelle
AU - McGee, Thomas
AU - Kaiser, Elsi
AU - Lerman, Kristina
AU - Blank, Idan A.
AU - Byrd, Dani
AU - Habibi, Assal
AU - Cahn, B. Rael
AU - Kadiri, Sudarsana
AU - Medani, Takfarinas
AU - Leahy, Richard M.
AU - Narayanan, Shrikanth
TI - Neural Responses to Affective Sentences Reveal Signatures of Depression
T2 - Translational psychiatry
J2 - Transl Psychiatry
PY - 2026
DA - 2026/
VL - 16
IS - 1
SP - 347
SN - 2158-3188
PB - Nature Publishing Group
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"type": "article-journal",
"title": "Neural Responses to Affective Sentences Reveal Signatures of Depression",
"container-title": "Translational psychiatry",
"author": [
{
"family": "Kommineni",
"given": "Aditya"
},
{
"family": "Jeong",
"given": "Woojae"
},
{
"family": "Avramidis",
"given": "Kleanthis"
},
{
"family": "McDaniel",
"given": "Colin"
},
{
"family": "Hughes",
"given": "Myzelle"
},
{
"family": "McGee",
"given": "Thomas"
},
{
"family": "Kaiser",
"given": "Elsi"
},
{
"family": "Lerman",
"given": "Kristina"
},
{
"family": "Blank",
"given": "Idan A."
},
{
"family": "Byrd",
"given": "Dani"
},
{
"family": "Habibi",
"given": "Assal"
},
{
"family": "Cahn",
"given": "B. Rael"
},
{
"family": "Kadiri",
"given": "Sudarsana"
},
{
"family": "Medani",
"given": "Takfarinas"
},
{
"family": "Leahy",
"given": "Richard M."
},
{
"family": "Narayanan",
"given": "Shrikanth"
}
],
"container-title-short":
"volume": "16",
"issue": "1",
"page": "347",
"DOI": "10.1038/
"PMID": "42140957",
"PMCID": "PMC13346668",
"ISSN": "2158-3188",
"publisher": "Nature Publishing Group",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
15
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1038/s42003-026-10108-z [code]
- Time-resolved EEG decoding reveals altered neural dynamics of affective semantic evaluation in depression and suicidality.Journal: Communications biologyIn common: statsmodels, seaborn, scikit-learn, 4 other tools, depression, EEG, 23 references, 4 authors
- [2] doi:10.1038/s41467-026-72253-7 [code]
- Spurious alignment between large language models and brains can emerge from non-robust methods and overlooked confounds.Journal: Nature communicationsIn common: PyTorch, seaborn, scikit-learn, 4 other tools, author Idan Blank
- [3] doi:10.1038/s41597-025-05174-7 [code]
- A large-scale MEG and EEG dataset for object recognition in naturalistic scenesJournal: n/aIn common: PyTorch, seaborn, scikit-learn, 4 other tools, EEG, 2 references
- [4] doi:10.1038/s41380-026-03691-4 [code]
- Breaking the norm: population-scale deviations of brain structure in depression and anxiety.Journal: Molecular psychiatryIn common: statsmodels, PyTorch, seaborn, 5 other tools, depression, 1 reference
- [5] doi:10.1523/eneuro.0254-25.2026 [code]
- Spatiotemporal Dynamics in Prespeech Semantic Category Decoding: An Intracranial EEG Study.Journal: eNeuroIn common: statsmodels, seaborn, scikit-learn, 4 other tools, 2 references
- [6] doi:10.1038/s41598-026-56688-y [code]
- On the value of radiomics in addition to clinical measures in emotional conflict fMRI for predicting sertraline response in major depressive disorder.Journal: Scientific reportsIn common: statsmodels, seaborn, scikit-learn, 4 other tools, depression, 1 reference
- [7] doi:10.7554/elife.107933 [code]
- Modality-agnostic decoding of vision and language from fMRI.Journal: eLifeIn common: statsmodels, PyTorch, seaborn, 5 other tools, 1 reference
- [8] doi:10.1038/s43856-026-01395-y [code]
- Enhancing depression diagnosis with augmented brain signal driven decorrelated graph neural networks.Journal: Communications medicineIn common: PyTorch, scikit-learn, pandas, 2 other tools, depression, 2 references
- [9] doi:10.1016/j.isci.2026.116825 [code]
- Social hierarchy shapes behavioral and transcriptional responses to chronic stress and ketamine in male mice.Journal: iScienceIn common: statsmodels, PyTorch, seaborn, 5 other tools, depression
- [10] doi:10.3390/s26103065 [code]
- Subject-Wise Depression Screening from Eight-Channel Resting-State EEG Using Asymmetry-Aware Spectral Features and Connectivity Ablation.Journal: Sensors (Basel, Switzerland)In common: PyTorch, scikit-learn, pandas, 3 other tools, depression, EEG, 1 reference
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 16 scripts, and 0 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:180ff98363778267…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
