BackgroundIdiopathic pulmonary fibrosis (IPF) is a fatal disease of unknown etiology with a poor prognosis, characterized by a lack of effective diagnostic and therapeutic interventions. The role of immunity in the pathogenesis of IPF is significant, yet remains inadequately understood. This study aimed to identify potential key genes in IPF and their relationship with immune cells by integrated bioinformatics analysis and verify by in vivo and in vitro experiments.MethodsGene microarray data were obtained from the Gene Expression Omnibus (GEO) for differential expression analysis. The differentially expressed genes (DEGs) were identified and subjected to functional enrichment analysis. By utilizing a combination of three machine learning algorithms, specific genes associated with idiopathic pulmonary fibrosis (IPF) were pinpointed. Then their diagnostic significance and potential co-regulators were elucidated. We further analyzed the correlation between key genes and immune infiltrating cells via single-sample gene set enrichment analysis (ssGSEA). Subsequently, a single-cell RNA sequencing data (scRNA-seq) was used to explore which cell types expressed key genes in IPF samples. Finally, a series of in vivo and in vitro experiments were conducted to validate the expression of candidate genes by western blot (WB), quantitative real-time PCR (qRT-PCR), and immunohistochemistry (IHC) analysis.ResultsA total of 647 DEGs of IPF were identified based on two datasets, including 225 downregulated genes and 422 upregulated genes. They are closely related to biological functions such as cell migration, structural organization, immune cell chemotaxis, and extracellular matrix. CFH and FHL2 were identified as key genes with diagnostic accuracy for IPF by three machine learning algorithms. Analysis using ssGSEA revealed a significant association of both CFH and FHL2 with diverse immune cells, such as B cells and NK cells. Further scRNA-seq analysis indicated CFH and FHL2 were specifically upregulated in human IPF tissues, which was confirmed by in vitro and in vivo experiments.ConclusionIn this study, CFH and FHL2 have been identified as novel potential biomarkers for IPF, with potential diagnostic utility in future clinical applications. Subsequent investigations into the functions of these genes in IPF and their interactions with immune cells may enhance comprehension of the disease’s pathogenesis and facilitate the identification of therapeutic targets.