Skip to content

Commit

Permalink
Merge branch 'add-electrode-table'
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Aug 9, 2022
2 parents f62e3e4 + 8589670 commit dbaeb05
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
# - name: test
# run: cd build && ctest
- name: deploy
if: github.ref == 'refs/heads/main'
env:
artifactoryApiKey: ${{ secrets.artifactoryApiKey }}
build_dir: "Build"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
# - name: test
# run: cd build && ctest
- name: deploy
if: github.ref == 'refs/heads/main'
env:
artifactoryApiKey: ${{ secrets.artifactoryApiKey }}
build_dir: "Build/Release"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
# - name: test
# run: cd build && ctest
- name: deploy
if: github.ref == 'refs/heads/main'
env:
artifactoryApiKey: ${{ secrets.artifactoryApiKey }}
build_dir: "Build/Release"
Expand Down
2 changes: 1 addition & 1 deletion Source/OpenEphysLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern "C" EXPORT void getLibInfo(Plugin::LibraryInfo* info)
{
info->apiVersion = PLUGIN_API_VER;
info->name = "NWB2 Format";
info->libVersion = "0.2.0";
info->libVersion = "0.2.1";
info->numPlugins = NUM_PLUGINS;
}

Expand Down
90 changes: 85 additions & 5 deletions Source/RecordEngine/NWBFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ int NWBFile::createFileStructure()
if (createGroup("/general")) return -1;
if (createGroup("general/devices")) return -1;
if (createGroup("general/extracellular_ephys")) return -1;
if (createGroup("general/extracellular_ephys/electrodes")) return -1;

StringArray colnames;
colnames.add("group");
colnames.add("group_name");
setAttributeStrArray(colnames, "general/extracellular_ephys/electrodes", "colnames");
setAttributeStr("metadata about extracellular electrodes", "general/extracellular_ephys/electrodes", "description");
setAttributeStr("hdmf-common", "general/extracellular_ephys/electrodes", "namespace");
setAttributeStr("DynamicTable", "general/extracellular_ephys/electrodes", "neurodata_type");
setAttributeStr(generateUuid(), "general/extracellular_ephys/electrodes", "object_id");

if (createGroup("/processing")) return -1;

if (createGroup("/stimulus")) return -1;
Expand Down Expand Up @@ -144,6 +155,9 @@ bool NWBFile::startNewRecording(
eventDataSets.clearQuick(true);

int totalChannelCount = 0;
Array<int> all_electrode_inds;
StringArray groupNames;
StringArray groupReferences;

// 1. Create continuous datasets
for (int i = 0; i < continuousArray.size(); i++)
Expand All @@ -158,16 +172,38 @@ bool NWBFile::startNewRecording(
channel_conversion.add(group[ch]->getBitVolts() / 1e6);
}

String groupName = group[0]->getSourceNodeName() + "-"
+ String(group[0]->getSourceNodeId())
+ "." + group[0]->getStreamName();

String fullPath = "general/extracellular_ephys/" + groupName;
createGroup(fullPath);
setAttributeStr("description", fullPath, "description");
setAttributeStr("unknown", fullPath, "location");
setAttributeStr("core", fullPath, "namespace");
setAttributeStr("ElectrodeGroup", fullPath, "neurodata_type");
setAttributeStr(generateUuid(), fullPath, "object_id");

createGroup("general/devices/" + groupName);

setAttributeStr("description", "general/devices/" + groupName, "description");
setAttributeStr("unknown", "general/devices/" + groupName, "manufacturer");
setAttributeStr("core", "general/devices/" + groupName, "namespace");
setAttributeStr("Device", "general/devices/" + groupName, "neurodata_type");
setAttributeStr(generateUuid(), "general/devices/" + groupName, "object_id");

createReference("/" + fullPath + "/device", "/general/devices/" + groupName);

Array<int> electrode_inds;
for (int ch = 0; ch < group.size(); ch++)
{
int index = group[ch]->getGlobalIndex();
electrode_inds.add(totalChannelCount++);
all_electrode_inds.add(index);
groupNames.add(groupName);
groupReferences.add("/general/extracellular_ephys/" + groupName);
}

String groupName = group[0]->getSourceNodeName() + "-"
+ String(group[0]->getSourceNodeId())
+ "." + group[0]->getStreamName();

ecephys::ElectricalSeries* electricalSeries =
new ecephys::ElectricalSeries(rootPath,
groupName,
Expand Down Expand Up @@ -235,7 +271,19 @@ bool NWBFile::startNewRecording(

for (int ch = 0; ch < sourceInfo->getNumChannels(); ch++)
{
electrode_inds.add(sourceInfo->getSourceChannels()[0]->getGlobalIndex());
int globalIndex = sourceInfo->getSourceChannels()[ch]->getGlobalIndex();
int tableIndex = all_electrode_inds.indexOf(globalIndex);

if (tableIndex > -1)
{
electrode_inds.add(tableIndex);
}
else
{
// If we don't have a matching electrode row, just use zero for now.
// In the future this should create a new table row.
electrode_inds.add(0);
}
}

ecephys::SpikeEventSeries* spikeEventSeries =
Expand Down Expand Up @@ -385,6 +433,36 @@ bool NWBFile::startNewRecording(

syncMsgDataSet.reset(annotationSeries);

// 5. Create electrode table
ScopedPointer<HDF5RecordingData> elSet = createDataSet(BaseDataType::I32, 1, 1, "general/extracellular_ephys/electrodes/id");

std::vector<int> electrodeNumbers;
for (auto i : all_electrode_inds)
electrodeNumbers.push_back(i);

CHECK_ERROR(elSet->writeDataBlock(electrodeNumbers.size(), BaseDataType::I32, &electrodeNumbers[0]));

setAttributeStr("hdmf-common", "general/extracellular_ephys/electrodes/id", "namespace");
setAttributeStr("ElementIdentifiers", "general/extracellular_ephys/electrodes/id", "neurodata_type");
setAttributeStr(generateUuid(), "general/extracellular_ephys/electrodes/id", "object_id");

ScopedPointer<HDF5RecordingData> groupNamesDataset = createDataSet(BaseDataType::STR(250), 0, 1, "general/extracellular_ephys/electrodes/group_name");

for (int i = 0; i < groupNames.size(); i++)
groupNamesDataset->writeDataBlock(1, BaseDataType::STR(groupNames[i].length()), groupNames[i].toUTF8());

setAttributeStr("the name of the ElectrodeGroup this electrode is a part of", "general/extracellular_ephys/electrodes/group_name", "description");
setAttributeStr("hdmf-common", "general/extracellular_ephys/electrodes/group_name", "namespace");
setAttributeStr("VectorData", "general/extracellular_ephys/electrodes/group_name", "neurodata_type");
setAttributeStr(generateUuid(), "general/extracellular_ephys/electrodes/group_name", "object_id");

createReferenceDataSet("general/extracellular_ephys/electrodes/group", groupReferences);

setAttributeStr("a reference to the ElectrodeGroup this electrode is a part of", "general/extracellular_ephys/electrodes/group", "description");
setAttributeStr("hdmf-common", "general/extracellular_ephys/electrodes/group", "namespace");
setAttributeStr("VectorData", "general/extracellular_ephys/electrodes/group", "neurodata_type");
setAttributeStr(generateUuid(), "general/extracellular_ephys/electrodes/group", "object_id");

return true;

}
Expand Down Expand Up @@ -643,6 +721,8 @@ HDF5RecordingData *NWBFile::createElectrodeDataSet(String path, String descripti
CHECK_ERROR(setAttributeStr(description, path, "description"));
CHECK_ERROR(setAttributeStr("hdmf-common", path, "namespace"));
CHECK_ERROR(setAttributeStr("DynamicTableRegion", path, "neurodata_type"));
CHECK_ERROR(setAttributeStr(generateUuid(), path, "object_id"));
CHECK_ERROR(setAttributeRef("general/extracellular_ephys/electrodes", path, "table"));
}
return elSet;
}
Expand Down

0 comments on commit dbaeb05

Please sign in to comment.