Ejemplo n.º 1
0
void IndexInitial()
{
	MsgFunction("IndexInitial");
	FILE* pFile = NULL;

	MsgRead(pchProteinIndexFile);
	if (pFile = fopen(pchProteinIndexFile, "r"))
	{
		int step_i = 0;
		for (step_i = 0; step_i <= INDEX_PROTEINS - 1; ++step_i)
		{
			fscanf(pFile, "%s %d", selectProteins[step_i].chName,
				&(selectProteins[step_i].iID));
		}
		fclose(pFile);
	}
	else
	{
		MsgError(pchProteinIndexFile);
	}

	MsgRead(pchPhenotypeIndexFile);
	if (pFile = fopen(pchPhenotypeIndexFile, "r"))
	{
		int step_i = 0;
		for (step_i = 0; step_i <= INDEX_PHENOTYPES - 1; ++step_i)
		{
			fscanf(pFile, "%s %d", selectPhenotypes[step_i].chName,
				&(selectPhenotypes[step_i].iID));
		}
		fclose(pFile);
	}
	else
	{
		MsgError(pchPhenotypeIndexFile);
	}

	MsgRead(pchGeneIndexFile);
	if (pFile = fopen(pchGeneIndexFile, "r"))
	{
		int step_i = 0;
		for (step_i = 0; step_i <= INDEX_GENES - 1; ++step_i)
		{
			fscanf(pFile, "%s %d", selectGenes[step_i].chName,
				&(selectGenes[step_i].iID));
//debug
//if(strcmp(selectGenes[step_i].chName, "613733")==0)
//{
//	cout << "";
//}
		}
		fclose(pFile);
	}
	else
	{
		MsgError(pchGeneIndexFile);
	}
}
Ejemplo n.º 2
0
static int
MsgCmd(int ac, char **av)
{
	char *buf;
	char *path, *cmdstr;
	int i, len;

	/* Get arguments */
	if (ac < 3)
		return (CMDRTN_USAGE);
	path = av[1];
	cmdstr = av[2];

	/* Put command and arguments back together as one string */
	for (len = 1, i = 3; i < ac; i++)
		len += strlen(av[i]) + 1;
	if ((buf = malloc(len)) == NULL) {
		warn("malloc");
		return (CMDRTN_ERROR);
	}
	for (*buf = '\0', i = 3; i < ac; i++) {
		snprintf(buf + strlen(buf),
		    len - strlen(buf), " %s", av[i]);
	}

	/* Send it */
	if (NgSendAsciiMsg(csock, path, "%s%s", cmdstr, buf) < 0) {
		free(buf);
		warn("send msg");
		return (CMDRTN_ERROR);
	}
	free(buf);

	/* See if a synchronous reply awaits */
	{
		struct timeval tv;
		fd_set rfds;

		FD_ZERO(&rfds);
		FD_SET(csock, &rfds);
		memset(&tv, 0, sizeof(tv));
		switch (select(csock + 1, &rfds, NULL, NULL, &tv)) {
		case -1:
			err(EX_OSERR, "select");
		case 0:
			break;
		default:
			MsgRead();
			break;
		}
	}

	/* Done */
	return (CMDRTN_OK);
}
Ejemplo n.º 3
0
int
io_console_write(resmgr_context_t *ctp, io_write_t *msg, iofunc_ocb_t *ocb) {
	int		n;
	int		off;
	int		len;
	int		ret;
	int		cnt;
	int		status;
	int		nonblock;
	char	*cptr;

	ret = EOK;
	cptr = (char *) (sizeof(msg->i) + (char *)&msg->i);
	off = 0;
	len = msg->i.nbytes;
	
	// Is device open for write?
	if((status = iofunc_write_verify(ctp, msg, ocb, &nonblock)) != EOK)
		return status;

	// No special xtypes
	if((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
		return(EINVAL);
	
	while(off < len) {
		
		/* Limit write to max payload, NULL terminate the string,
		 * and figure out how many ints we're writing.
		 */
		n = min(len - off,  _SLOG_MAXSIZE - _SLOG_HDRINTS*sizeof(int) - 1);
		cptr[n] = '\0';
		cnt = n/sizeof(int) +1;

		/* put it in the log */
		ret = _io_write_log(ctp, msg, ocb, cnt, 1);
		if(ret != EOK)
			break;
	
		off += n;

		//skip the MsgRead() if we're done.
		if (off == len)
			break;
		
		ret = MsgRead(ctp->rcvid, cptr, n, off + sizeof(msg->i));
		if(ret <= 0) 
			break;
	}

	_IO_SET_WRITE_NBYTES(ctp, off);
	return(ret);
}
Ejemplo n.º 4
0
int das_tmr_scan_msg( resmgr_context_t *ctp, RESMGR_OCB_T *pocb,
			int num_entries )
{
	int num_read;
	char plist[QMM10XT_N_TIMERS];	// hold scan list read from second part

	
	num_read = MsgRead(ctp->rcvid, plist, num_entries, sizeof(das_msg_t));
	
	if( qmm10xt_tmr_set_scan( pmain_board, plist, num_entries ) == TRUE )
		return ( EOK );
	else
		return ( EINVAL );
}
Ejemplo n.º 5
0
void ReadIDFile()
{
	MsgFunction("ReadIDFile");
	FILE* pFile = NULL;

	MsgRead(pchProteinIDFile);
	if (pFile = fopen(pchProteinIDFile, "r"))
	{
		int step_i = 0;
		for (step_i = 0; step_i < TOTAL_PROTEINS; ++step_i)
		{
			fscanf(pFile, "%s %d", TotalProteins[step_i].chName,
				&(TotalProteins[step_i].iID));
		}
		fclose(pFile);
	}
	else
	{
		printf("File %s open error\n", pchProteinIDFile);
	}

	MsgRead(pchPhenotypeIDFile);
	if (pFile = fopen(pchPhenotypeIDFile, "r"))
	{
		int step_i = 0;
		for (step_i = 0; step_i < TOTAL_PHENOTYPES; ++step_i)
		{
			fscanf(pFile, "%s %d", TotalPhenotypes[step_i].chName,
				&(TotalPhenotypes[step_i].iID));
		}
		fclose(pFile);
	}
	else
	{
		printf("File %s open error\n", pchPhenotypeIDFile);
	}
}
Ejemplo n.º 6
0
int resmgr_msg_again(resmgr_context_t *ctp, int rcvid) {
	if(MsgInfo(rcvid, &ctp->info) == -1) {
		return -1;
	}

	if((ctp->info.msglen = MsgRead(ctp->rcvid = rcvid, ctp->msg, ctp->msg_max_size, 0)) == -1) {
		return -1;
	}

	(void)MsgCurrent(rcvid);

	_resmgr_handler(ctp);

	return 0;
}
Ejemplo n.º 7
0
void ReadPhenotypeSimiIndex()
{
	MsgRead(pchIndexFile);

	FILE* fin = fopen(pchIndexFile, "r");
	if (fin)
	{
		int i = 0;
		for (i = 0; i <= iMaxPhenotype - 1; i++)
		{
			char aLine[PHENOTYPE_LENGTH] = {'\0'};
			fscanf(fin, "%s", aLine);

			strcpy(phenotypeSimiIndex[i].chName, aLine);
			phenotypeSimiIndex[i].iID = i;
		}
		fclose(fin);
	}
	else
	{}
}
Ejemplo n.º 8
0
void CreateSelectFile()
{
	MsgFunction("CreateSelectFile");

	CreateIndexGeneProtein();
	CreateIndexPhenotype();
	ReadGeneProtein();
	memset(selectPhenotypeProtein, CAUSE_PROTEIN_END, sizeof(selectPhenotypeProtein));

	//Phenotype tempPhenotype;

	MsgRead(morbidMapFile);
	FILE* fin = fopen(morbidMapFile, "r");
	if (fin)
	{
		int w = 0;
		for(w = 0; w <= iMax -1 && !feof(fin); w++)
		{
			char aLine[LINE_LENGTH] = {'\0'};
			fgets(aLine, LINE_LENGTH, fin);
			*(aLine+strlen(aLine)-1) = '\0';

			char* posP = aLine;
			char* posG  = aLine;
			char* p = ExtractPhenotypeID(aLine);
			char* g = ExtractGeneID(aLine);

			while (p != NULL)
			{
				Phenotype tempPhenotype;

				strcpy(tempPhenotype.chName, p);

				Phenotype* pPh = NULL;
				pPh = (Phenotype*) bsearch(&tempPhenotype, selectPhenotypes, INDEX_PHENOTYPES, sizeof(Phenotype), PhenotypeCompare);
				if (pPh != NULL)
				{
					int phenotypePos = pPh -> iID;
					while(g != NULL) //in fact 一行一个G
					{
						Phenotype tempGene;
						strcpy(tempGene.chName, g);
						Gene* pG = NULL;
						pG = (Gene*) bsearch(&tempGene, selectGenes, INDEX_GENES, sizeof(Gene), GeneCompare);
						if (pG != NULL)
						{
							int genePos = pG -> iID;
							int end = 0;
							int k = 0;
							for (k = 0;k <= CAUSE_PROTEINS - 1 ; k++ )// j <= RELATE_PROTEINS - 1
							{
								if (selectPhenotypeProtein[phenotypePos][k]== CAUSE_PROTEIN_END)
								{
									end = k;
									break;
								}
								else
								{}
							}

							int m = 0;
							for (m = 0; m <= RELATE_PROTEINS - 1 && GeneProtein[genePos][m] != CAUSE_PROTEIN_END; m++ )
							{
								bool isExist = false;
								int n = 0;
								for (n = 0; n <= RELATE_PROTEINS - 1 && selectPhenotypeProtein[phenotypePos][n] != CAUSE_PROTEIN_END ; n++)
								{
									if (selectPhenotypeProtein[phenotypePos][n] == GeneProtein[genePos][m])
									{
										isExist = true;
										break;
									}
									else
									{}
								}

								if (isExist == false)
								{
									selectPhenotypeProtein[phenotypePos][end] = GeneProtein[genePos][m];
									end++;
								}
								else
								{}
							}
							selectPhenotypeProtein[phenotypePos][end] = CAUSE_PROTEIN_END;
						}
						else
						{}
						//strcpy(phenotypes[i].chName, rs[j].str().substr(1,6).c_str());
						//i++ ;

						posG = strstr(aLine, g);
						posG = posG + GENE_LENGTH - 1;
						if (posG <= aLine + strlen(aLine) )
						{
							g = ExtractPhenotypeID(posG);
						}
						else
						{}

					}
				}
				else
				{}

				posP = strstr(aLine, p);
				posP = posP + PHENOTYPE_LENGTH - 1;
				if (posP <= aLine + strlen(aLine) )
				{
					p = ExtractPhenotypeID(posP);
				}
			}
		}
		fclose(fin);
	}
	else
	{}

//test
	/*ofstream fout1("Data\\test\\selected.test", ios::out);

	for (i = 0; i <= TOTAL_PHENOTYPES -1 ; i++)
	{
		if (selectPhenotypeProtein[i][0] == CAUSE_PROTEIN_END)
		{
			continue;
		}
		else
		{}

		if (strcmp(selectPhenotypes[i].chName, NOSIMIINFO) == 0)
		{
			break;
		}
		else
		{}

		bool isHG = false;
		for (k = 0; k <= CAUSE_PROTEINS - 1 && selectPhenotypeProtein[i][k] != CAUSE_PROTEIN_END; k++)
		{
			string proteinLoc = proteinMaps[selectPhenotypeProtein[i][k]].pos.oriString;
			if (proteinLoc.find('H') != string::npos  || proteinLoc.find('G') != string::npos)
			{
				isHG = true;
				break;
			}
			else
			{}
		}

		if (isHG == false)
		{
			for (j = 0; j <= CAUSE_PROTEINS - 1; j++)
			{

				fout1 << selectPhenotypeProtein[i][j] << ",";
				if (selectPhenotypeProtein[i][j] == CAUSE_PROTEIN_END)
				{
					break;
				}
				else
				{}
			}
			fout1<<endl;
		}
		else
		{}
	}
	fout1.flush();
	fout1.close();*/

	//609033以下的,没有表型相似度了,break
	//去掉没有蛋白质的
	//去掉蛋白质区间是H,G表示的
	//output selected.txt
	ReadProteinMap(proteinMaps, selectProteins, INDEX_PROTEINS);
	ReadPhenotypeSimiIndex();

	MsgWrite(selectedFile);
	FILE* fout = fopen(selectedFile, "w");

	if (fout)
	{
		int available = 0;
		int i = 0;
		for (i = 0; i <= INDEX_PHENOTYPES -1; i++)
		{
		    Phenotype tempPhenotype = selectPhenotypes[i];

			Phenotype* pPh = NULL;
			pPh = (Phenotype*) bsearch(&tempPhenotype, phenotypeSimiIndex, iMaxPhenotype, sizeof(Phenotype), PhenotypeCompare);
			if (pPh == NULL)
			{
				continue;
			}
			else
			{}


			//去掉没有找到蛋白质的
			if (strcmp(selectPhenotypes[i].chName, NOSIMIINFO) == 0)
			{
				break;
			}
			else
			{}

			//以下没有表型相似度
			if (selectPhenotypeProtein[i][0] == CAUSE_PROTEIN_END)
			{
				continue;
			}
			else
			{}

			//去掉没有区间信息的(蛋白质区间没有,或者编码以H,G开头的)
			bool isHG = false;
			int k = 0;
			for (k = 0; k <= CAUSE_PROTEINS - 1 && selectPhenotypeProtein[i][k] != CAUSE_PROTEIN_END; k++)
			{
	//debug
	//cout << proteinMaps[selectPhenotypeProtein[i][k]].chName << endl;
	//cout << i <<endl;

				//string proteinPosStr = proteinMaps[selectPhenotypeProtein[i][k]].oriString;
				//if (proteinPosStr.at(0) == 'G' || proteinPosStr.at(0) == 'H')
				int proteinLoc = proteinMaps[selectPhenotypeProtein[i][k]].pos;
				if (proteinLoc == UNNORMAL_POS)
				{
					isHG = true;
					break;
				}
				else
				{}
			}
			if (isHG == false)
			{
				available++;
				//fout << selectPhenotypes[i].chName << " ";
				fprintf(fout, "%s ", selectPhenotypes[i].chName);
				int j = 0;
				for (j = 0; j <= CAUSE_PROTEINS - 1 && selectPhenotypeProtein[i][j] != CAUSE_PROTEIN_END; j++)
				{

					//fout << selectProteins[selectPhenotypeProtein[i][j]].chName << ",";
					fprintf(fout, "%s,", selectProteins[selectPhenotypeProtein[i][j]].chName);
					//fout << selectPhenotypeProtein[i][j] << ",";

				}
				//fout << endl;
				fprintf(fout, "\n");
			}
			else //含有'H','G'开头的不规则蛋白质区间编码,表型不要了
			{}
		}
		printf("->sMax:%d\n", available);

		fflush(fout);
		fclose(fout);
	}
	else
	{
		MsgError(selectedFile);
	}
}
Ejemplo n.º 9
0
//static const int gpMax = 2773; //bio_g->p 行数
void CreateIndexGeneProtein()
{
	MsgFunction("CreateIndexGeneProtein");

	char proteinTemp[LINE_LENGTH] = {'\0'};

	char gene[PHENOTYPE_LENGTH] = {'\0'};
	//char protein[PROTEIN_LENGTH] = {'\0'};

	int m = 0;
	int n = 0;

	MsgRead(geneProteinFile);
	FILE* fin = fopen(geneProteinFile, "r");
	if (fin)
	{
		int i = 0;
		for(i = 0; !feof(fin) && i <= gpMax - 1; i++)
		{
			fscanf(fin, "%s %s", gene, proteinTemp);
//debug
//if (strcmp(gene, "609062") == 0)
//{
//	cout<< gene;
//}
			strcpy(genes[m].chName, gene);
			m++;

			char* pProteinNameHead = proteinTemp;
			int current = 0;
			for (current = 0; current <= strlen(proteinTemp) - 1 ; current += PROTEIN_LENGTH)
			{
				pProteinNameHead = proteinTemp + current;
				strncpy(proteins[n].chName, pProteinNameHead, PROTEIN_LENGTH - 1);
				n++;
			}

		}
		fclose(fin);
	}
	else
	{
		MsgError(selectedFile);
	}

	qsort (genes, m, sizeof(Gene), GeneCompare);
	qsort (proteins, n, sizeof(Protein), ProteinCompare);

	MsgWrite(pchGeneIndexFile);
	FILE* fout = fopen(pchGeneIndexFile, "w");
	if (fout)
	{
		int j = 0;
		for (j = 0; j <= m - 1; j++)
		{
			fprintf(fout, "%s %d\n", genes[j].chName, j);
		}
		printf("->INDEX_GENES:%d\n", j);
		fflush(fout);
		fclose(fout);
	}
	else
	{
		MsgError(pchPhenotypeIDFile);
	}


	MsgWrite(pchProteinIDFile);
	fout = fopen(pchProteinIndexFile, "w");
	if (fout)
	{
		char last [PROTEIN_LENGTH] = {'\0'};
		int k = 0;
		int j = 0;
		for (j = 0; j <= n - 1; j++)
		{
			if (strcmp(proteins[j].chName, last) != 0)
			{
				fprintf(fout, "%s %d\n", proteins[j].chName, k);
				k++;
			}
			else
			{}
			strcpy(last, proteins[j].chName);
		}
		printf("->INDEX_PROTEINS:%d", k);
		fflush(fout);
		fclose(fout);
	}
	else
	{
		MsgError(pchProteinIDFile);
	}
}
Ejemplo n.º 10
0
void ReadGeneProtein()
{
	MsgFunction("ReadGeneProtein");

	IndexInitial();

	char gene[PHENOTYPE_LENGTH] = {'\0'};
	char protein[PROTEIN_LENGTH] = {'\0'};
	char proteinTemp[LINE_LENGTH] = {'\0'};

	MsgRead(geneProteinFile);
	FILE* pFile = fopen(geneProteinFile, "r");
	if (pFile)
	{
		while (!feof(pFile))
		{
			fscanf(pFile, "%s %s", gene, proteinTemp);//可以跳过空行

			Phenotype tempGene;
			strcpy(tempGene.chName, gene);
//debug
//if (strcmp(gene, "613733") == 0)
//{
//cout << gene;
//}
			Gene* pResult = NULL;
			pResult = (Gene*) bsearch(&tempGene, selectGenes, INDEX_GENES, sizeof(Gene), GeneCompare);
			if (pResult != NULL)
			{
				int genePos =  pResult - selectGenes;

				int i = 0;
				char* pProteinNameHead = proteinTemp;

				int current = 0;
				for (current = 0; current <= strlen(proteinTemp) - 1 ; current += PROTEIN_LENGTH)
				{
					pProteinNameHead = proteinTemp + current;
					strncpy(protein, pProteinNameHead, PROTEIN_LENGTH - 1);
					protein[PROTEIN_LENGTH - 1] = '\0';

					Protein tempProtein;
					strcpy(tempProtein.chName, protein);
					Protein* pResult = NULL;
					pResult = (Protein*) bsearch(&tempProtein, selectProteins, INDEX_PROTEINS, sizeof(Protein), ProteinCompare);

					if (pResult != NULL)
					{
						int proteinPos =  pResult - selectProteins;

						GeneProtein[genePos][i] = proteinPos;
						i++;

					}
					else
					{
						MsgError("error: protein index:");
						MsgError(tempProtein.chName);
					}
				}
				GeneProtein[genePos][i] = CAUSE_PROTEIN_END;
			}
			else
			{
				MsgError("error gene index");
				MsgError(tempGene.chName);
			}
		}
		fclose(pFile);
	}
	else
	{
		MsgError(geneProteinFile);
	}

//test
	//ofstream fout("Data\\test\\selectedGeneProtein.test", ios::out);
	//for (i = 0; i <= INDEX_GENES -1 ; i++)
	//{
	//	for (j = 0; j <= CAUSE_PROTEINS - 1; j++)
	//	{
	//		fout << GeneProtein[i][j] << ",";
	//		if (GeneProtein[i][j] == CAUSE_PROTEIN_END)
	//		{
	//			break;
	//		}
	//	}
	//	fout<<endl;
	//}
	//fout.flush();
	//fout.close();
}
Ejemplo n.º 11
0
void CreateIndexPhenotype()
{
	MsgFunction("CreateIndexPhenotype");

	int i = 0;
	//Phenotype tempPhenotype;
	Phenotype phenotypes[iMax];//从morbidmap->index

	MsgRead(morbidMapFile);
	FILE* fin = fopen(morbidMapFile, "r");
	if (fin)
	{
		int j = 0;
		for(j = 0; j <= iMax -1 && !feof(fin); j++)
		{
			char aLine[LINE_LENGTH] = {'\0'};
			fgets(aLine, LINE_LENGTH, fin);
			*(aLine+strlen(aLine)-1) = '\0';

			char* posP = aLine;
			char* p = ExtractPhenotypeID(aLine);

			while (p != NULL)
			{
				strcpy(phenotypes[i].chName, p);
				i++;

				posP = strstr(aLine, p);
				posP = posP + PHENOTYPE_LENGTH - 1;
				if (posP <= aLine + strlen(aLine) )
				{
					p = ExtractPhenotypeID(posP);
				}
				else
				{
					p = NULL;
				}
			}
		}
		qsort(phenotypes, i, sizeof(Phenotype), PhenotypeCompare);
	}
	else
	{}

	FILE* fout = fopen(pchPhenotypeIndexFile, "w");
	if (fout)
	{
		//string last = "";
		char last[PHENOTYPE_LENGTH] = {'\0'};
		int k = 0;
		int j = 0;
		for (j = 0; j <= i - 1; j++)
		{
			if (strcmp(phenotypes[j].chName, last) != 0)
			{
				//fout << phenotypes[j].chName << " " << k << endl;
				fprintf(fout, "%s %d\n",phenotypes[j].chName, k);
				k++;
			}
			else
			{}
			strcpy(last, phenotypes[j].chName);
		}
		printf("->INDEX_PHENOTYPES:%d\n", k);
		fflush(fout);
		fclose(fout);
	}
	else
	{}
}
Ejemplo n.º 12
0
void ReadMorbidMap()
{
	MsgFunction("ReadMorbidMap");

	int i = 0;
	for (i = 0; i<=TOTAL_PHENOTYPES-1; i++)
	{
		int j =0;
		for (j =0; j<=CAUSE_LOCATIONS-1; j++)
		{
			strcpy(TotalMorbidMaps[i][j].chName, "");
		}
	}

	char name[PROTEIN_LENGTH] = {'\0'};
	char location[16] = {'\0'};

	Phenotype tempPhenotype;

	MsgRead(morbidMapFile);
	FILE* fin = fopen(morbidMapFile, "r");
	if (fin)
	{
		int i = 0;
		for (i = 0; i <= iMax -1 && !feof(fin); i++ )
		{
			char aLine[LINE_LENGTH] = {'\0'};
			fgets(aLine, LINE_LENGTH, fin);
			*(aLine+strlen(aLine)-1) = '\0'; //'\n'也读进来了

			char* posP = aLine;
			char* p = ExtractPhenotypeID(aLine);

			while (p!= NULL)
			{
//debug
	//if (strcpy(name,"210210") == 0)
	//{
	//	cout << "210210";
	//}
	//cout << "debug ReadMorbidMap" << name << endl;
				strcpy(name, p);
				strcpy(tempPhenotype.chName, name);

				char* last = strrchr(aLine, '|');
				strcpy(location, last + 1);

				Phenotype* pResult = NULL;
				pResult = (Phenotype*) bsearch(&tempPhenotype, TotalPhenotypes, TOTAL_PHENOTYPES, sizeof(Phenotype), PhenotypeCompare);
				if (pResult != NULL)
				{
					int pos = pResult -> iID;
					int i = 0;
					for (i = 0; i <= CAUSE_LOCATIONS - 1; i++)
					{
						if (strcmp(TotalMorbidMaps[pos][i].chName, "") == 0)
						{
							strcpy(TotalMorbidMaps[pos][i].chName, name);

							StrToLocation(location, &TotalMorbidMaps[pos][i]);
							break;
						}
						else
						{}
					}
				}
				else
				{}
				posP = strstr(aLine, p);
				posP = posP + PHENOTYPE_LENGTH-1;
				if (posP <= aLine + strlen(aLine) )
				{
					p = ExtractPhenotypeID(posP);
				}
				else
				{}
			}
		}
		fclose(fin);
	}
	else
	{
		MsgError(morbidMapFile);
	}

//test
	//ofstream fout("Data\\test\\morbidmap.test", ios::out);
	//if (fout)
	//{
	//	for (pos = 0; pos <= TOTAL_PHENOTYPES - 1; pos++)
	//	{
	//		fout  << TotalMorbidMaps[pos][0].chName << " ";
	//		for (i = 0; i <= CAUSE_LOCATIONS - 1; i++)
	//
	//		{
	//			fout << "[" << BitToLocation(TotalMorbidMaps[pos][i].start) << "," << BitToLocation(TotalMorbidMaps[pos][i].end) << "] ";
	//		}
	//		fout << "\n";

	//		/*fout  << morbidMap[pos].at(0).chName << " ";
	//		for (vector<MorbidMap>::iterator iter = morbidMap[pos].begin() ; iter <= morbidMap[pos].begin()- 1; iter++)
	//		{
	//			fout << "[" + (*iter).start.oriString << "," << (*iter).end.oriString << "] ";
	//		}
	//		fout << "\n";*/
	//	}
	//	fout.flush();
	//	fout.close();
	//}
	//else
	//{}
}
Ejemplo n.º 13
0
void ReadPhenotypeProteinRelationFile()
{
	MsgFunction("ReadPhenotypeProteinRelationFile");
	char phenotypes[PHENOTYPE_LENGTH];
	char protein[PROTEIN_LENGTH];
	char proteinTemp[LINE_LENGTH];

	int phenotypeID = 0;
	int proteinID = 0;

	MsgRead(selectedFile);
	FILE* pFile = fopen(selectedFile, "r");
	if (pFile)
	{
		while (!feof(pFile))
		{
//debug
	/*if (strcmp(phenotypes, "202400") == 0)
	{
		cout << phenotypes;
	}*/
			fscanf(pFile, "%s %s", phenotypes, proteinTemp);//©иртлЬ╧Щ©упп
			phenotypeID = PhenotypeNameToID(phenotypes);

			int i = 0;
			char* pProteinNameHead = proteinTemp;

			int current = 0;
			for (current = 0; current <= strlen(proteinTemp) - 1 ; current += PROTEIN_LENGTH)
			{
				pProteinNameHead = proteinTemp + current;
				strncpy(protein, pProteinNameHead, PROTEIN_LENGTH - 1);
				protein[PROTEIN_LENGTH - 1] = '\0';

				proteinID = ProteinNameToID(protein);

				phenotypeProtein[phenotypeID][i] =  proteinID;
				i++;
			}
			phenotypeProtein[phenotypeID][i] = CAUSE_PROTEIN_END;
		}
		fclose(pFile);
	}
	else
	{
		printf("File %s open error\n", selectedFile);
	}


//test
	//ofstream fout("Data\\test\\selected.test", ios::out);
	//for (i = 0; i <= TOTAL_PHENOTYPES -1 ; i++)
	//{
	//	for (j = 0; j <= TOTAL_PROTEINS - 1; j++)
	//	{
	//		fout << phenotypeProtein[i][j] << ",";
	//		if (phenotypeProtein[i][j] == CAUSE_PROTEIN_END)
	//		{
	//			break;
	//		}
	//	}
	//	fout<<endl;
	//}
	//fout.flush();
	//fout.close();
}
Ejemplo n.º 14
0
int _resmgr_mount_handler(resmgr_context_t *ctp, resmgr_iomsgs_t *msg, struct link *link, io_mount_extra_t *extra,
			              int	(*func)(resmgr_context_t *ctp, resmgr_iomsgs_t *msg, void *handle, void *extra)) {
	struct binding				*binding = NULL;
	int							status = EOK;
	io_mount_extra_t			*newextra;

	if ( msg->link.connect.extra_type == _IO_CONNECT_EXTRA_MOUNT_OCB) {
		// Lookup passed in handle to send an ocb if required
		if((binding = (struct binding *)_resmgr_handle(&extra->extra.cl.info, 0, _RESMGR_HANDLE_FIND_LOCK)) == (void *)-1) {
			return ENXIO;
		}

		// Make sure they are from the same process
		/*
		if((status = _resmgr_access(ctp, &extra->node.info, 0, 0, 0, 0)) != EOK) {
			return status;
		}
		*/
	}
	

	//We need to find a faster/more elegant way to make sure that we have the whole 
	//sized buffer to slurp in. For now, just allocate a new buffer 
	if (!(newextra = (io_mount_extra_t *)malloc(extra->nbytes))) {
		if(binding) _resmgr_handle(&extra->extra.cl.info, 0, _RESMGR_HANDLE_UNLOCK);
		return(ENOMEM);
	}

	//Copy the structure following the message (extra + data) into our allocated buffer.
	if ((status = MsgRead(ctp->rcvid, newextra, extra->nbytes, (char *)extra - (char *)msg)) != extra->nbytes) {
		if(binding) _resmgr_handle(&extra->extra.cl.info, 0, _RESMGR_HANDLE_UNLOCK);
		free(newextra);
		return(errno);
	}

	//Now that we have the buffer, set the pointers to the data, type and special device string
	memset(&newextra->extra, 0, sizeof(newextra->extra));

	if (binding) {
		newextra->extra.srv.ocb = binding->ocb;
	}

	if (newextra->datalen) {
		newextra->extra.srv.data = (void *)(newextra +1);
	}

	newextra->extra.srv.type = 
	newextra->extra.srv.special = (char *)(newextra + 1) + newextra->datalen;

	if ((status = ((newextra->nbytes - sizeof(io_mount_extra_t)) 
						 - newextra->datalen) 
						 - (strlen(newextra->extra.srv.type) +1)) > 0) {
		newextra->extra.srv.special +=  strlen(newextra->extra.srv.type) + 1;
	}
	else {
		newextra->extra.srv.special = NULL;
	}

	//Actually perform the mount callout
	status = func(ctp, msg, link->handle, newextra);

	free(newextra);
	if(binding)_resmgr_handle(&extra->extra.cl.info, 0, _RESMGR_HANDLE_UNLOCK);

	return(status);
}
Ejemplo n.º 15
0
//static const int sMax = 1897;//2042; //selected.txt行数
void CreateIDFile()
{
	MsgFunction("CreateIDFile");

	//char aLine[LINE_LENGTH] = {'\0'};
	char proteinTemp[LINE_LENGTH] = "";
	char phenotype[PHENOTYPE_LENGTH] = "";
	char protein[PROTEIN_LENGTH] = "";

	int m = 0;
	int n = 0;

	MsgRead(selectedFile);
	FILE* fin = fopen(selectedFile, "r");
	if (fin)
	{
		int i = 0;
		for (i = 0; !feof(fin) && i <= sMax-1; i++)
		{
			fscanf(fin, "%s %s", phenotype, proteinTemp);
//debug
/*if (strcmp(phenotype, "202400") == 0)
{
	cout<< aLine;
}*/
			if (strcmp(phenotype, "") != 0)
			{
				strcpy(phenotypesOut[m].chName, phenotype);
				m++;

				char* pProteinNameHead = proteinTemp;
				int current = 0;
				for (current = 0; current <= strlen(proteinTemp) - 1 ; current += PROTEIN_LENGTH)
				{
					pProteinNameHead = proteinTemp + current;
					strncpy(proteinsOut[n].chName, pProteinNameHead, PROTEIN_LENGTH - 1);
					n++;
				}
			}
			else
			{}
		}
		fclose(fin);
	}
	else
	{
		MsgError(selectedFile);
	}

	qsort(phenotypesOut, m, sizeof(Phenotype), PhenotypeCompare);
	qsort(proteinsOut, n, sizeof(Protein), ProteinCompare);

	MsgWrite(pchPhenotypeIDFile);
	FILE* fout = fopen(pchPhenotypeIDFile, "w");
	if (fout)
	{
		//string last = "";
		int j = 0;
		for (j = 0; j <= m - 1; j++)
		{
			fprintf(fout, "%s %d\n", phenotypesOut[j].chName, j);
		}
		printf("->TOTAL_PHENOTYPES:%d\n", j);
		fflush(fout);
		fclose(fout);
	}
	else
	{
		MsgError(pchPhenotypeIDFile);
	}


	/*MsgWrite(pchProteinIDFile);
	fout = fopen(pchProteinIDFile, "w");
	if (fout)
	{
		char last[PROTEIN_LENGTH] = {'\0'};

		int k = 0;
		int j = 0;
		for (j = 0; j <= n - 1; j++)
		{
			if (strcmp(proteinsOut[j].chName, last) != 0)
			{
				fprintf(fout, "%s %d\n", proteinsOut[j].chName, k);
				k++;
			}
			else
			{}
			strcpy(last, proteinsOut[j].chName);
		}
		printf("->TOTAL_PROTEINS:%d\n", k);
		fflush(fout);
		fclose(fout);
	}
	else
	{
		MsgError(pchProteinIDFile);
	}*/
	CreateProteinIDNew();
}
Ejemplo n.º 16
0
void CreateProteinIDNew()
{
	MsgFunction("CreateProteinIDNew");

	//Protein tempProtein;

	MsgRead(proteinMapFile);
	FILE* fin = fopen(proteinMapFile, "r");

	if (fin)
	{
		int i = 0;
		int pos = 0;
		for (i = 0; i <= BIGLINE - 1 && !feof(fin); i++ )
		{
			char aLine[LINE_LENGTH];
			fgets(aLine, LINE_LENGTH, fin);

			char* del = ",";
			char* LF = "\n";

			char* name = strtok(aLine, del);
			char* chromosome = strtok(NULL, del);
			char* band = strtok(NULL, LF);

			if (!name || !chromosome || !band)
			{
				continue;
			}

			else if (chromosome[0] == 'G' ||chromosome[0] == 'H')
			{
				continue;
			}
			else if (i == 0)
			{
				continue;
			}
			else
			{
				//pTempArray[pos].iID = pos;
				strcpy(pTempArray[pos].chName, name);
				pos++;
			}
		}
		printf("->TOTAL_PROTEINS:%d\n", pos);
		qsort(pTempArray, pos, sizeof(Protein), ProteinCompare);

		FILE* fout = fopen(pchProteinIDFile, "w");
        MsgWrite(pchProteinIDFile);
		if (fout)
		{
		    int i = 0;
			for (i = 0; i<=pos-1;i++)
			{
				fprintf(fout, "%s %d\n",  pTempArray[i].chName, i);
			}
		}
		else
		{
			MsgError(pchProteinIDFile);
		}


		fclose(fin);
		fclose(fout);
	}
	else
	{
		MsgError(proteinMapFile);
	}
}
Ejemplo n.º 17
0
void CreatePhenotypeSimilarityFile()
{
	MsgRead(pchIndexFile);

	FILE* fin = fopen(pchIndexFile, "r");
	if (fin)
	{
		int i = 0;
		for (i = 0; i <= iMaxPhenotype - 1; i++)
		{
			char aLine[PHENOTYPE_LENGTH] = {'\0'};
			fscanf(fin, "%s", aLine);

			strcpy(PhenotypeIDIndex[i].chName, aLine);
			PhenotypeIDIndex[i].iID = i;
		}
		fclose(fin);
	}
	else
	{}

	MsgRead(pchDataFile);
	fin = fopen(pchDataFile, "r");
	if (fin)
	{
		int i = 0;
		for (i = 0; i <= iMaxPhenotype - 1; i++)
		{
			int head = 0;
			char aLine[iMaxRowLength+10] = {'\0'};
			fscanf(fin, "%s", aLine);

			int j = 0;
			for (j = 0; j <= iMaxPhenotype - 1; j++)
			{
				char simiStr[simiLength] = {'\0'};
				strncpy(simiStr, aLine + head, simiLength - 1);
				simiStr[simiLength - 1] = '\0';

				TotalSimilarity[i][j] = atof(simiStr);
				head += simiLength;
			}
		}
		fclose(fin);
	}
	else
	{
		MsgError(pchDataFile);
	}

	int i = 0;
	for (i = 0; i <= TOTAL_PHENOTYPES - 1; i++)
	{
		Phenotype* pI = NULL;
		pI = (Phenotype*) bsearch(&TotalPhenotypes[i], PhenotypeIDIndex, iMaxPhenotype, sizeof(Phenotype), PhenotypeCompare);

		int j = 0;
		for (j = 0; j <= TOTAL_PHENOTYPES - 1 && j <= i; j++)
		{
			Phenotype* pJ = NULL;
			pJ = (Phenotype*) bsearch(&TotalPhenotypes[j], PhenotypeIDIndex, iMaxPhenotype, sizeof(Phenotype), PhenotypeCompare);

			if (pI != NULL && pJ != NULL)
			{
				phenotypesSimilarity[i][j] = TotalSimilarity[pI->iID][pJ->iID];
				phenotypesSimilarity[j][i] = phenotypesSimilarity[i][j];
			}
			else
			{}
		}
	}

	MsgWrite(phenotypeSimilarityFileBin);
	FILE* pFile = fopen(phenotypeSimilarityFileBin, "wb");
	if (pFile)
	{
		fwrite(phenotypesSimilarity, sizeof(float), TOTAL_PHENOTYPES * TOTAL_PHENOTYPES, pFile);
		fflush(pFile);
		fclose(pFile);
	}
	else
	{
		MsgError(phenotypeSimilarityFileBin);
	}
}