Example #1
0
inline void writeXGMMLFile(
    const G &g,
    const std::string &filename,
    const VV &vv,
    const EV &ev
) {
    using boost::format;

    std::ofstream file(filename);
    if(!file.good()) {
        throw GraphIOException(std::string("Could not open file: ") + filename);
    }

    file << "<?xml version=\"1.0\"?>\n";

    if(g[boost::graph_bundle].label.size() > 0) {
        file << "<graph label=\"" << g[boost::graph_bundle].label << "\" ";
    } else {
        file << "<graph label=\"" << basename(filename) << "\" ";
    }
    file << "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" ";
    file << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" ";
    file << "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" ";
    file << "xmlns=\"http://www.cs.rpi.edu/XGMML\" ";
    file << "directed=\"0\">\n";

    for(size_t i = 0; i < num_vertices(g); ++i) {
        file << format("\t<node id=\"%d\" label=\"%s\">\n") % (i+1) % g[i].label;
        for(size_t a = 0; a < vv.count(); ++a) {
            file << format("\t\t<att name=\"%s\" type=\"%s\" value=\"%s\"/>\n")
                 % vv.name(a) % vv.type(a) % vv.value_str(g[i], a);
        }
        file << "\t</node>\n";
    }

    for(size_t i = 0; i < num_vertices(g); ++i) {
        for(auto it = out_edges(i, g); it.first != it.second; ++it.first) {
            size_t j = target(*it.first, g);

            if(i <= j) {
                file << format("\t<edge source=\"%d\" target=\"%d\" label=\"%s\">\n")
                     % (i+1) % (j+1) % g[*it.first].label;

                for(size_t a = 0; a < ev.count(); ++a) {
                    file << format("\t\t<att name=\"%s\" type=\"%s\" value=\"%s\" />\n")
                         % ev.name(a) % ev.type(a) % ev.value_str(g[*it.first], a);
                }
                file << "\t</edge>\n";
            }
        }
    }
    file << "</graph>";
    file.close();
}
Example #2
0
	inline void writeTabFile(
			const G &g,
			const std::string &filename,
			const VV &vv,
			const EV &ev
		) {
		std::ofstream file(filename);
		if(!file.good()) {
			throw GraphIOException(std::string("Could not open file: ") + filename);
		}

		file << "INTERACTOR_A\tINTERACTOR_B\tlabel";
		for(size_t a = 0; a < ev.count(); ++a) {
			file << "\t" << ev.name(a);
		}
		file << "\n";

		for(size_t i = 0; i < num_vertices(g); ++i) {
			for(auto it = out_edges(i, g); it.first != it.second; ++it.first) {
				size_t j = target(*it.first, g);

				if(i <= j) {
					file << g[i].label << "\t" << g[j].label;
					if(g[*it.first].label.length() > 0) {
						file << "\t" << g[*it.first].label;
					} else {
						file << "\tNA";
					}
					for(size_t a = 0; a < ev.count(); ++a) {
						file << "\t" << ev.value_str(g[*it.first], a);
					}
					file << "\n";
				}
			}
		}
		file.close();
	}