-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableToAdjacencyList.cxx
55 lines (52 loc) · 1.35 KB
/
TableToAdjacencyList.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2009 Sandia Corporation, Kitware Inc.
// See LICENSE.txt for details.
#include "vtkAbstractArray.h"
#include "vtkDelimitedTextReader.h"
#include "vtkSmartPointer.h"
#include "vtkStdString.h"
#include "vtkTable.h"
#include "vtkVariant.h"
// Converts file of the form
// Cell Name,gene1,gene2,gene3,...,geneN
// cell1,1,0,0,...,0
// cell2,0,0,1,...,0
// cell3,0,0,0,...,0
// ...
// cellM,0,0,0,...,1
//
// To the form
// cell,gene
// cell1,gene1
// cell2,gene3
// ...
// cellM,geneN
int main( int argc, char** argv )
{
if (argc != 2)
{
cerr << "Usage: TableToAdjacencyList outTable.csv > adjTable.csv" << endl;
return 1;
}
vtkSmartPointer<vtkDelimitedTextReader> tr =
vtkSmartPointer<vtkDelimitedTextReader>::New();
tr->SetHaveHeaders(true);
tr->SetMergeConsecutiveDelimiters(false);
tr->SetFieldDelimiterCharacters(",");
tr->SetFileName(argv[1]);
tr->Update();
vtkTable* tab = tr->GetOutput();
cout << "cell,gene" << endl;
for (vtkIdType row = 0; row < tab->GetNumberOfRows(); ++row)
{
vtkStdString cell = tab->GetValue(row, 0).ToString();
for (vtkIdType col = 1; col < tab->GetNumberOfColumns(); ++col)
{
if (tab->GetValue(row, col).ToInt() == 1)
{
vtkStdString gene = tab->GetColumn(col)->GetName();
cout << cell << "," << gene << endl;
}
}
}
return 0;
}