Example #1
0
int main(int argc, char* argv[]) {

  if (argc < 3) {
    cout << "Needs 3 arguments: 1) file with pairwise distances between elements.  ";
    cout << "File should be 3 tab separated columns with 1 undirected edge per line of the format node1, node2, edgeWeight (similarity between node1 and node2)" << endl;
    cout << "2) threshold between clusters (alpha parameter)" << endl;
    cout << "3) merge density for overlapping clusters (beta parameter. Optional with default = 0.5)" << endl;
    cout << "4) name for terminal node (i.e. gene, patient, etc.). Optional with default = gene" << endl;
    return 0;
  }

  Corrector::initialize();
  /*for (unsigned i = 0; i < 600; ++i) {
    cout << i << "\t" << Corrector::correction(i) << endl;
  }
  return 1;*/

  map<string, unsigned> nodeNamesToIDs;

  // Load input network graphs
  string netFile = argv[1];
  double threshold = stod(argv[2]);
  double density = 0.5;
  if (argc >= 4) {
    density = stod(argv[3]);
  }
  string terminalName = "gene";
  if (argc >= 5) {
    terminalName = string(argv[4]);
  }
  time_t start, end;
  time(&start);
  cout << "# Loading input network graph" << endl;
  graph_undirected inputNetwork(netFile, nodeNamesToIDs);
  time(&end);
  double dif = difftime(end,start);
  cout << "# Loading input network took " << dif << " seconds" << endl;
  
  // Create ontology from other networks
  cout << "# Clique finding beginning" << endl;
  DAGraph ontology;
  ontology.setTerminalName(terminalName);
  nodeDistanceObject nodeDistances;

  time (&start);
  dagConstruct::constructDAG(inputNetwork, ontology, nodeDistances, threshold, density);
  time (&end);
  dif = difftime(end,start);
  cout << "# Ontology construction took " << dif << " seconds" << endl;
  cout << "# Ontology is: " << endl;

  for(map< pair<unsigned,unsigned>, string >::iterator edgesIt = ontology.edgesBegin(); edgesIt != ontology.edgesEnd(); ++edgesIt) {
    // THIS VERSION GIVES THE DISTANCE BETWEEN POINTS
    //cout << ontology.getName(edgesIt->first.first) << "\t" << ontology.getName(edgesIt->first.second) << "\t" << edgesIt->second << "\t" << (ontology.getWeight(edgesIt->first.second) - ontology.getWeight(edgesIt->first.first)) / 2.0 << endl;

    // THIS VERSION JUST TELLS THE WEIGHT ON THE PARENT TERM
    cout << ontology.getName(edgesIt->first.first) << "\t" << ontology.getName(edgesIt->first.second) << "\t" << edgesIt->second << "\t" << ontology.getWeight(edgesIt->first.first) << endl;
  }
  return 1;
}
Example #2
0
void readRouter()
{
	////FILE * datafile;
	FILE * outfile;
	struct network* target;
	////int id1;
	////int id2;
	////double weight;
	////int error;
	////int totalNum;
	struct netInfo* netinfo;
	struct CLSTS* clsts;
	FILE * pFile_node;
	FILE * pFile_pajek;

	// 2) analyze the properties
	target=NULL;
	outfile=fopen("./realdata/Router_net.txt", "r");
	inputNetwork(&target, outfile);
	fclose (outfile);

	printf("\n %d %d \n", target->nodeNum, target->linkNum);

	// getNetwork Info
	netinfo=(struct netInfo*)mem_alloc(sizeof(struct netInfo));
	initNetInfo(netinfo, target);
	getBasicNetInfo(target, netinfo);
	clsts=NULL;
	getCLSTS(target,&clsts);
	getClstNetInfo(target, clsts, netinfo); 

	pFile_node=fopen("Router_node.txt", "w");
	outputNodeInfo(netinfo, pFile_node);
	fclose (pFile_node);
	// statis info

	pFile_pajek=fopen("Router_pajek.txt", "w");
	outputNetwork_pajek( target, pFile_pajek);
	fclose (pFile_pajek);
	
	printf(" %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl, 			 		   
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
	
	freeNetwork(target);
	freeCLSTS(clsts);
	freeNetInfo(netinfo);

}
Example #3
0
int
readSCN(char * netfile) /*input: name of file recording network information*/

{
    int error;
    FILE *infile;
    time_t time_begin,time_end;
    struct tm * TM ;
    char dir_p[10];
    int name_size;
    static struct network * scn;
    /* 1) from files,  get the header dependency network and filelist*/
    error=0;
    name_size=30;
    infile=fopen(netfile, "r");
    if(infile==NULL)
    {
        printf("file \" %s \" not exist!\n", netfile);
        return 1;
    }
    inputNetwork(&scn, infile);
    fclose(infile);

    /* 2) get statistical properties of the network, and record all the information into output files */
    //   create ouput directories
    time(&time_begin);
    TM=localtime(&time_begin);
    strftime(dir_p, name_size, "%y%m%d%H%M", TM);
    strcat(dir_p,"/");
#if defined(_WIN32)
    error=_mkdir(dir_p);
#else
    error=mkdir(dir_p, 0777);
#endif

    analyzeSCN(scn,dir_p);

    time(&time_end);
    printf("\n exhausted time: %ld \n",time_end-time_begin);

    //showNetwork(file_net);
    /* 3) free file network, file list and other memory*/
    freeNetwork(scn);

    printf("\n ok! \n");
    return error;
}
Example #4
0
/*
	input output network test
*/
void
ioNetwork()
{
	int m0,m,step,iter;
	FILE *in, *out;
	time_t time_begin,time_end;
	struct network * target=NULL;
	struct network * newNet=NULL;


    time(&time_begin);
	out=fopen("net.txt","w");
	step=5;
       m0=m=2;
	iter=1;
	m=m;
	m0=m0;
	target=NULL;
	newNet=NULL;
    target=(struct network *)mem_alloc(sizeof(struct network));
	baModel_o(target, m0, m, step);

	printf(" the original network: \n");
	showNetwork(target);
	outputNetwork(target, out);
	fclose(out);

	in=fopen("net.txt","r");
	inputNetwork(&newNet, in);
	fclose(in);
	printf(" the read-in network: \n");
	showNetwork(newNet);
	
	time(&time_end);
      	printf("\n exhausted time: %ld \n",time_end-time_begin);
}
Example #5
0
void 
netToPajek(char * netfile, char * pajekfile)
{

	FILE * outfile;
	FILE * pFile_pajek;
	struct network* target;

	// 1) input network and analyze the properties
	target=NULL;
	outfile=fopen(netfile, "r");
	inputNetwork(&target, outfile);
	fclose (outfile);

	printf("\n %d %d \n", target->nodeNum, target->linkNum);
	
	// 2) to pajek file
	pFile_pajek=fopen(pajekfile, "w");
	outputNetwork_pajek_frac( target, pFile_pajek);
	fclose (pFile_pajek);
	
	freeNetwork(target);

}
Example #6
0
void
read_AS_caida()
{
	FILE * datafile;
	FILE * outfile;
	struct network* target;
	int id1;
	int id2;
	double weight;
	int error;
	int totalNum;
	struct netInfo* netinfo;
	struct CLSTS* clsts;
	FILE * pFile_node;

	
	// 1) read the network data from the raw-data file "AS_oregon2.txt"
	target=(struct network *)mem_alloc(sizeof(struct network));

	totalNum=11461;
	initNetwork(target, totalNum, UN_DIRECT_UN_WEIGHT);

	datafile = fopen("./realdata/AS_oregon2.txt", "r");
	while(1)
	{
		error=fscanf(datafile, "%d %d \n", &id1, &id2, &weight);
		// use (id1 id2 weight) to construct  a network
		//printf(" %d (%d , %d) %f \n",error, id1,id2,weight);
		//getchar();
		if(error==-1)
			break;
		error=addLinkToNetwork(target, id1, id2, 1.0);
		error=addLinkToNetwork(target, id2, id1, 1.0);
	}
	fclose(datafile);
	
	outfile=fopen("./realdata/AS_oregon2_net.txt", "w");
	outputNetwork(target, outfile);
	fclose (outfile);

	freeNetwork(target);

	// 2) analyze the properties
	target=NULL;
	outfile=fopen("./realdata/AS_oregon2_net.txt", "r");
	inputNetwork(&target, outfile);
	fclose (outfile);

	printf("\n %d %d \n", target->nodeNum, target->linkNum);

	// getNetwork Info
	netinfo=(struct netInfo*)mem_alloc(sizeof(struct netInfo));
	initNetInfo(netinfo, target);
	getBasicNetInfo(target, netinfo);
	clsts=NULL;
	getCLSTS(target,&clsts);
	getClstNetInfo(target, clsts, netinfo); 

	pFile_node=fopen("AS_oregon2_node.txt", "w");
	outputNodeInfo(netinfo, pFile_node);
	fclose (pFile_node);
	// statis info

	printf(" %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl, 			 		   
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
	
	freeNetwork(target);
	freeCLSTS(clsts);
	freeNetInfo(netinfo);

}