'how to convert lmd file to csv? [Flow Cytometry data]
lmd file extension is often used for generating flow cytometry data. But this couldn't be directly used for processing either in R or Python. Is there a way to somehow convert it to csv or some renowned format?
Solution 1:[1]
This is a bit tricky. So far I haven't come across any such direct conversion function. Perhaps, fcs is a more common format for flow-cytometry. Hence, we will first need to convert lmd to fcs and then to csv format.
Step 1: lmd to fcs [Using R]
# install
source("http://bioconductor.org/biocLite.R")
biocLite("flowCore")
# convert
library(tools) # for file_path_sans_ext
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install(version = '3.10')
BiocManager::install("flowCore")
library(flowCore)
in.fname <- 'Filename.LMD'
folder <- '/home/User/Desktop/Data/'
x <- read.FCS(paste0(folder, in.fname))
summary(x)
out.fname <- paste0(file_path_sans_ext(in.fname), '.fcs')
write.FCS(x, paste0(folder, out.fname))
Note: Change User and Filename with your desired path and filename respectively Your fcs file will be saved in the same folder.
Source: https://github.com/eyurtsev/FlowCytometryTools/issues/3
Step 2: fcs to csv
This could be done simply using the read.FCS() function to read in a FCS file, and then using write.delim() or write.csv() to create a .txt or .csv file.
Source: https://www.bioconductor.org/packages/release/bioc/vignettes/flowCore/inst/doc/HowTo-flowCore.pdf
Solution 2:[2]
Exclusively using python:
Code to convert FCS file to CSV
import pandas as pd
import fcsparser
path = ('<filename>.fcs')
meta = fcsparser.parse(path,meta_data_only=True)
meta, data = fcsparser.parse(path, meta_data_only=False, reformat_meta=True)
print(data)
df = pd.DataFrame(data)
df.to_csv('<filename>.csv')
Code to convert FCS file to CSV
import pandas as pd
import numpy as np
import fcswrite
path = ('<filename>.csv')
data = pd.read_csv(path).to_numpy()
chn_names = <list of channel names>
fcswrite.write_fcs(filename="<filename.fcs",chn_names=chn_names, data=data)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sachin Motwani |
Solution 2 |