Skip to content

Commit 1d9c65b

Browse files
greebieruebot
authored andcommitted
Use stdin, stdout, and stderr; resolves #47. (#63)
* Update README to reflect changes * Remove references to libgen in Makefile (no longer used for Mac or Linux). * Add test suite for input-output functions. * Remove debug flags from tests and have functions return (1) instead of exit(1). * Use #define instead of const for Ubuntu gcc. * Use stderr instead of stdout for error outputs.
1 parent bbde012 commit 1d9c65b

File tree

15 files changed

+433
-153
lines changed

15 files changed

+433
-153
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ OUT
1010
/tmp/
1111
*.swp
1212
.DS_Store
13+
/TEST_OUT_FOLDER/
14+
ana
15+
io
16+
qp

Makefile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
UNAME := $(shell uname)
22

33
ifeq ($(UNAME), Linux)
4-
IGRAPH_PATH = /usr/local/
4+
BASE_PATH = /usr/local/
5+
IGRAPH_PATH = $(BASE_PATH)
56
endif
67
ifeq ($(UNAME), Darwin)
78
IGRAPH_PATH = /usr/local/Cellar/igraph/0.7.1_6/
@@ -21,34 +22,40 @@ INCLUDE = ./src/headers
2122
DEPS = -I$(INCLUDE) -I$(IGRAPH_INCLUDE) -I$(UNITY_INCLUDE)
2223
BUILD = build/
2324

24-
all: test install
25+
all: clean test install
2526

2627
install: src/main/graphpass.c
27-
gcc src/main/*.c $(DEPS) -L$(IGRAPH_LIB) -ligraph -lm -o graphpass
28-
- ./graphpass -qn
28+
gcc src/main/*.c $(DEPS) -L$(IGRAPH_LIB) -ligraph -lm -o graphpass
29+
- ./graphpass -qnv
2930

3031
release: src/main/graphpass.c
3132
gcc src/main/*.c $(DEPS) -L$(IGRAPH_LIB) -ligraph -lm -o graphpass
32-
- ./graphpass -qg
33+
- ./graphpass -qgnv
3334

3435
debug: ./src/main/graphpass.c
35-
gcc -g src/main/*.c $(DEPS) -L$(IGRAPH_LIB) -ligraph -lm -o graphpass
36+
gcc -g -Wall src/main/*.c $(DEPS) -L$(IGRAPH_LIB) -ligraph -lm -o graphpass
3637

37-
test: qp ana run clean
38+
test: qp ana io run clean
3839

3940
qp: $(TEST_INCLUDE)runner_test_qp.c
4041
gcc $(UNITY_INCLUDE)/unity.c $(TEST_INCLUDE)runner_test_qp.c $(DEPS) $(TEST_INCLUDE)quickrun_test.c $(HELPER_FILES) -L$(IGRAPH_LIB) -ligraph -lm -o qp
4142

4243
ana: $(TEST_INCLUDE)runner_test_ana.c
4344
gcc $(UNITY_INCLUDE)/unity.c $(TEST_INCLUDE)runner_test_ana.c $(DEPS) $(TEST_INCLUDE)analyze_test.c $(HELPER_FILES) -L$(IGRAPH_LIB) -ligraph -lm -o ana
4445

46+
io: $(TEST_INCLUDE)runner_test_io.c
47+
gcc $(UNITY_INCLUDE)/unity.c $(TEST_INCLUDE)runner_test_io.c $(DEPS) $(TEST_INCLUDE)io_test.c $(HELPER_FILES) -L$(IGRAPH_LIB) -ligraph -lm -o io
48+
4549
run:
4650
- ./ana
4751
./qp
52+
./io
4853

4954
.PHONY : clean
5055
clean:
5156
rm -f qp
5257
rm -f ana
58+
rm -f io
5359
rm -rf TEST_OUT_FOLDER
60+
rm -rf $(BUILD)
5461
rm -f graphpass

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,21 @@ make
9494
Once compiled use the following command:
9595

9696
```
97-
./graphpass {FLAGS}
97+
./graphpass {INPUT PATH} {OUTPUT PATH} {FLAGS}
9898
```
9999

100100
The following flags are available:
101101

102-
* `--file {FILENAME}` - sets the default filename. If not set, `graphpass` will use
103-
a default network in `src/resources`.
104-
* `--dir {DIRECTORY}` - the path to look for {FILENAME} by default this is `src/resources/`
105-
* `--output {OUTPUT}` - the directory to send output files such as filtered graphs and data reports.
106-
* `--percent {PERCENT}` - a percentage to remove from the file. By default this is 0.0.
107-
* `--method {options}` - a string of various methods through which to filter the
102+
* `--input {FILEPATH} or -i` - The filepath of the file to run GraphPass on. If not set, GraphPass will use
103+
a default network in `src/resources`. This will override the value in `{INPUT PATH}`.
104+
* `--output {FILEPATH} or -o` - The filepath for outputs, overriding `{OUTPUT PATH}`. If the output path contains a filename, GraphPass will use that, otherwise it will default to the filename provided in `{INPUT PATH}`. Unless the quickpass (`-q`) is selected, the filename will also be altered to show the percentage filtered from the graph and the method used.
105+
* `--percent {PERCENT} or -p` - a percentage to remove from the file. By default this is 0.0.
106+
* `--method {options} or -m` - a string of various methods through which to filter the
108107
graph.
108+
* `--quick or -q` - GraphPass will run a basic set of algorithms for visualization with no filtering. The filename will be the same as the input filename.
109+
* `--gexf or -g` - GraphPass will return the graph output in gexf (good for SigmaJS) instead of graphml.
110+
* `--max-nodes {Value}` - Change default maximum number of nodes that GraphPass will accept. By default this is 50,000. Values larger than 50k may cause GraphPass to use up a computer's memory.
111+
* `--max-edges {Value}` - Change default maximum number of edges that GraphPass will accept. By default this is 500,000. Values larger than 500k are unlikely to cause significant delays in computation time, but could result in memory issue upon visualization in Gephi or SigmaJS.
109112

110113
These various methods are outlined below:
111114

@@ -122,21 +125,19 @@ These various methods are outlined below:
122125
For example:
123126

124127
```
125-
./graphpass --percent 10 --methods b --file links-for-gephi.graphml --output OUT/
128+
./graphpass /path/to/links-for-gephi.graphml --percent 10 --methods b /path/to/output_filename
126129
```
127130

128-
Will remove 10% of the graph using betweenness as a cutting measure and lay the network out. It will find `links-for-gephi.graphml` file in `src/resources` and output a new one to `/OUT` (titled `links-for-gephi10Betweenness.graphml`).
131+
Will remove 10% of the graph using betweenness as a cutting measure and lay the network out. It will find `links-for-gephi.graphml` file in `path/to/input` and output a new one to `/path/to/output_filename.graphml` (titled `output_filename10Betweenness.graphml`).
129132

130133
# Optional arguments
131134

132135
* `--report` or `-r` : create an output report showing the impact of filtering on graph features.
133136
* `--no-save` or `-n` : does not save any filtered files (useful if you just want a report).
134-
* `--quick` or `-q` : provides a "quickrun" for basic
135-
* `--gexf` or `-g` : output as a .gexf (e.g. for SigmaJS inputs) instead of .graphml.
136137

137138
# Troubleshooting
138139

139-
It is possible that you can get a "error while loading shared libraries" error in Linux. If so, try running `sudo ldconfig` to set the libraries path for your local installation of igraph.
140+
It is possible that you can get a "error while loading shared libraries" error in Linux. If so, try running `sudo ldconfig` to set the libraries path for your local installation of igraph.
140141

141142
# License
142143

src/headers/graphpass.h

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,65 +36,82 @@ typedef enum { FAIL, WARN, COMM } broadcast;
3636

3737
igraph_t g;
3838
igraph_attribute_table_t att;
39-
const char* ug_FILENAME; /**< The filename from -f flag. */
40-
const char* ug_DIRECTORY; /**< Directory to access FILENAME */
41-
char* ug_methods; /**< METHODS to filter */
42-
char* ug_OUTPUT; /**< Folder to output new graphs */
43-
char* OUTPATH; /**< Path to output folder (DIRECTORY + OUTPUT) */
44-
igraph_integer_t NODESIZE; /**< Number of Nodes in original graph */
45-
igraph_integer_t EDGESIZE; /**< Number of Edges in original graph */
46-
float ug_percent; /**< Filtering percentage 0.0 by default */
47-
long ug_maxnodes; /**< user-defined max nodes for processing, default MAX_NODES */
48-
long ug_maxedges; /**< user-defined maxiumum edges for processing default MAX_EDGES */
49-
bool ug_report; /**< Include a report? */
50-
bool ug_gformat; /**< Graph format - true is "GEXF" false is "GRAPHML" */
51-
bool ug_quickrun; /**< Lightweight visualization run */
52-
bool ug_save; /**< If false, does not save graphs at all (for reports) */
39+
40+
char* ug_OUT; /**< A FILEPATH called using -o flag. */
41+
char* ug_OUTFILE; /**< A FILENAME for outputting. */
42+
char* ug_INPUT; /**< A FILEPATH called using -i flag. */
43+
char* ug_FILENAME; /**< FILENAME extracted from stdin path. */
44+
char* ug_PATH; /**< Directory path extracted from stdin path. */
45+
char* ug_methods; /**< METHODS to filter. */
46+
char* ug_OUTPATH; /**< Path to output folder. */
47+
char* ug_OUTPUT; /**< Filename extracted from outpath, if it exists. */
48+
char* ug_OUTARG; /**< Filepath entered as ARG. */
49+
char* ug_DIRECTORY; /**< Directory extracted from ug_PATH. */
50+
bool ug_TEST; /**< Flags a test (ignores some expected FAIL messages). */
51+
igraph_integer_t NODESIZE; /**< Number of Nodes in original graph. */
52+
igraph_integer_t EDGESIZE; /**< Number of Edges in original graph. */
53+
float ug_percent; /**< Filtering percentage 0.0 by default. */
54+
long ug_maxnodes; /**< user-defined max nodes for processing, default MAX_NODES. */
55+
long ug_maxedges; /**< user-defined maxiumum edges for processing default MAX_EDGES. */
56+
bool ug_report; /**< Include a report?. */
57+
bool ug_gformat; /**< Graph format - true is "GEXF" false is "GRAPHML." */
58+
bool ug_quickrun; /**< Lightweight visualization run. */
59+
bool ug_save; /**< If false, does not save graphs at all (for reports). */
5360
bool ug_verbose; //**< Verbose mode (default off). */
5461
bool CALC_WEIGHTS;
55-
igraph_vector_t WEIGHTED; /**< If greater than 0, conducts weighted analysis */
62+
igraph_vector_t WEIGHTED; /**< If greater than 0, conducts weighted analysis. */
5663

57-
/* Required External libraries */
64+
/* Required External libraries. */
5865

5966
#define PROGRAM_NAME "GraphPass"
6067
#define BUG_REPORT "https://www.github.com/archivesunleashed/graphpass/issues"
6168
#define GIT_REPOSITORY "https://www.github.com/archivesunleashed/graphpass"
6269

63-
/* Color Presets */
70+
/* Color Presets. */
6471

6572
#define COLOUR_SET_PASTEL "pastel.h"
6673
#define COLOUR_SET_PRIMARY "primary.h"
6774
#define COLOUR_SET_DAMPENED "dampened.h"
6875

69-
/* Visualization Presets */
76+
/* Visualization Presets. */
7077

7178
#define VIZ_SET_SPACIOUS "viz_spacious.h"
7279
#define VIZ_SET_LARGE "viz_large.h"
7380
#define VIZ_SET_SMALL "vis_small.h"
7481

75-
/* Default Settings */
82+
/* Default Settings. */
7683
#define MAX_METHODS 9
7784
#define ALL_METHODS "abdehiopr"
7885
#define SIZE_DEFAULT "Degree"
7986
#define SIZE_DEFAULT_CHAR 'd'
8087
#define COLOR_BASE "WalkTrapModularity"
81-
#define PAGERANK_DAMPING 0.85 /**< chance random walk will not restart */
88+
#define PAGERANK_DAMPING 0.85 /**< chance random walk will not restart. */
8289
#define LAYOUT_DEFAULT_CHAR 'f'
83-
#define MAX_NODES 50000 /**< default number of nodes in graph before shut down */
84-
#define MAX_EDGES 500000 /**< default number of edges in graph before shut down */
90+
#define MAX_NODES 50000 /**< default number of nodes in graph before shut down. */
91+
#define MAX_EDGES 500000 /**< default number of edges in graph before shut down. */
8592
#define MAX_USER_EDGES 1000000000
8693
#define MAX_USER_NODES 1000000000
8794

95+
/* For test suite. */
96+
#define TEST_ARRAY_LENGTH 3 // Update as you add test examples.
97+
#define TEST_MAX_STRING_SIZE 22
98+
#define TEST_FILENAME_SIZE 9
99+
88100
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
89101

102+
struct Argument {
103+
char* val;
104+
struct Argument *next;
105+
};
106+
90107
struct Node {
91108
char* abbrev;
92109
igraph_real_t val;
93110
struct Node *next;
94111
};
95112

96113
/** @struct RankNode
97-
@brief unimplemented struct for holding the top 20 rankids for the graph.
114+
@brief Unimplemented struct for holding the top 20 rankids for the graph.
98115
*/
99116
struct RankNode {
100117
int rankids[20];
@@ -120,26 +137,30 @@ struct Node* clustering;
120137
struct Node* pv;
121138
struct Node* ts;
122139
struct RankNode* ranks;
140+
struct Argument* ug_args;
141+
int get_directory (char *path, char **result);
142+
int get_filename (char *path, char **result);
123143

124144
int shuffle(int *array, int n);
125-
/** adds a new value to a Node **/
145+
/** Adds a new value to a Node. **/
126146
int push(struct Node** head_ref, igraph_real_t value, char* attr);
127147

128-
/** adds a new value to a RankNode **/
148+
/** Adds a new value to a RankNode. **/
129149
int pushRank (struct RankNode** head_ref, int rankids[20]);
130150
int igraph_i_xml_escape(char* src, char** dest);
151+
int pushArg (struct Argument** arg, char *value);
131152

132153
int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
133154
igraph_bool_t prefixattr);
134155
igraph_real_t mean_vector (igraph_vector_t *v1);
135156
igraph_real_t variance_vector (igraph_vector_t *v1);
136157
igraph_real_t std_vector(igraph_vector_t *v1);
137-
igraph_real_t stderror_vector(igraph_vector_t *v1);
158+
igraph_real_t std_error_vector(igraph_vector_t *v1);
138159
igraph_real_t t_stat_vector(igraph_vector_t *v1);
139160
igraph_real_t t_test_vector(igraph_vector_t *v1, igraph_real_t df);
140161

141162
int rankCompare(igraph_t *g1, igraph_t *g2, char* attr, igraph_real_t* result_pv, igraph_real_t* result_ts );
142-
/** Writes the report **/
163+
/** Writes the report. **/
143164
int write_report(igraph_t *graph);
144165
int colors (igraph_t *graph);
145166
int layout_graph(igraph_t *graph, char layout);

src/main/analyze.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ igraph_real_t std_vector(igraph_vector_t *v1) {
4949
return sqrt(variance_vector(v1));
5050
}
5151

52-
igraph_real_t stderror_vector(igraph_vector_t *v1) {
52+
igraph_real_t std_error_vector(igraph_vector_t *v1) {
5353
return (std_vector(v1) / sqrt(igraph_vector_size(v1)));
5454
}
5555

5656
igraph_real_t t_stat_vector(igraph_vector_t *v1) {
57-
return (mean_vector(v1)/stderror_vector(v1));
57+
return (mean_vector(v1)/std_error_vector(v1));
5858
}
5959

6060
igraph_real_t t_test_vector(igraph_vector_t *v1, igraph_real_t df) {
@@ -531,4 +531,3 @@ int create_graph_csv(char* filepath, int start, int perc) {
531531
fclose(fs);
532532
return 0;
533533
}
534-

src/main/filter.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,3 @@ int filter_graph() {
325325
igraph_vector_destroy(&idRef);
326326
return 0;
327327
}
328-
329-
330-
331-

0 commit comments

Comments
 (0)