python - KeyError:使用 fcswrite 库时出现“'FCS 格式'”
问题描述
我正在尝试使用 fcs write 创建一个新的 .fcs 文件,但是出现错误。我不确定这个错误对我的代码意味着什么,因为我没有使用错误源自的密钥。
我的代码
import os
import FlowCytometryTools
from FlowCytometryTools import FCMeasurement
import fcswrite
# ---- Set dataDirectory equal to the directory that contains the files you wish to remove PHI ---
dataDirectory = r'C:\Users\hghas\OneDrive\Desktop\Demonstration'
os.chdir(dataDirectory)
for i, file in enumerate(os.listdir()):
# Loading file
sample = FCMeasurement(ID=f'Test Sample #{i+1}', datafile=file)
# Removing PHI
sample.meta['@SAMPLEID1'] = f"Study #{i + 1}"
mrn, hNumber = sample.meta['@SAMPLEID3'].split()
sample.meta['@SAMPLEID3'] = hNumber
sample.meta['@SAMPLEID4'] = None
temp = sample.get_meta()
temp['@SAMPLEID3']="Hello"
#sample.set_meta(temp)
print(sample.meta['@SAMPLEID3'])
measurementData = sample.get_data()
channelNames = list(sample.channel_names)
fcswrite.write_fcs(r'C:\Users\hghas\OneDrive\Desktop\Demonstration\test.fcs', channelNames, measurementData, text_kw_pr=temp)
# Renaming the files
newName = "{} {} {}{}".format(sample.meta['@SAMPLEID1'], sample.meta['@SAMPLEID2'], sample.meta['@SAMPLEID3'], ".fcs")
os.rename(file, newName)
错误
Traceback (most recent call last):
File "C:\Users\hghas\PycharmProjects\PHI_Removal_Sunnybrook\main.py", line 29, in <module>
fcswrite.write_fcs(r'C:\Users\hghas\OneDrive\Desktop\Demonstration\test.fcs', channelNames, measurementData, text_kw_pr=temp)
File "C:\Users\hghas\anaconda3\envs\testing\lib\site-packages\fcswrite\fcswrite.py", line 172, in write_fcs
TEXT = TEXT.format(data_start_byte=data_start_byte,
KeyError: "'FCS format'
来自 fcswrite 的导致错误的代码块
text_padding = 47 # for visual separation and safety
data_start_byte = header_size + len(TEXT) + text_padding
data_end_byte = data_start_byte + len(DATA) - 1
TEXT = TEXT.format(data_start_byte=data_start_byte,
data_end_byte=data_end_byte)
解决方案
推荐阅读
- firebase - 突然我收到无效的 Firebase 数据库路径:driver@driver.com Firebase 数据库路径不得包含“。”、“#”、“$”等
- java - 使用 H2 数据库的 JUnit 测试在调试模式下通过,但在测试模式下失败
- javascript - 在动态创建的输入文本上附加 eventListener
- python - 更改 crm.lead 模型中的默认货币 (odoo 12)
- javascript - 在按钮单击时水平反应滚动组件
- python - 在熊猫中重新索引时删除不必要的行
- c# - 为什么着色器不在地形上工作?它应该画一个圆圈
- laravel - Laravel + PhpStorm 缓存问题
- ios - GPS 地理位置权限对话框未在 iOS 中显示
- kubernetes-helm - Helm 暴露普罗米修斯仪表板