Exemplo n.º 1
0
void axtToPsl(char *inName, char *tSizeFile, char *qSizeFile, char *outName)
/* axtToPsl - Convert axt to psl format. */
{
struct hash *tSizeHash = readSizes(tSizeFile);
struct hash *qSizeHash = readSizes(qSizeFile);
struct lineFile *lf = lineFileOpen(inName, TRUE);
char strand[2];
FILE *f = mustOpen(outName, "w");
struct psl* psl;
struct axt *axt;
strand[1] = '\0';

while ((axt = axtRead(lf)) != NULL)
    {
    int qSize = findSize(qSizeHash, axt->qName);
    int qStart =  axt->qStart;
    int qEnd = axt->qEnd;
    if (axt->qStrand == '-')
        reverseIntRange(&qStart, &qEnd, qSize);
    strand[0] = axt->qStrand;
    psl = pslFromAlign(axt->qName, qSize, qStart, qEnd, axt->qSym, 
                       axt->tName, findSize(tSizeHash, axt->tName),
                       axt->tStart, axt->tEnd, axt->tSym, strand,
                       PSL_IS_SOFTMASK);
    if (psl != NULL)
	{
	pslTabOut(psl, f);
	pslFree(&psl);
	}
    axtFree(&axt);
    }
lineFileClose(&lf);
carefulClose(&f);
}
Exemplo n.º 2
0
void chainToPsl(char *inName, char *tSizeFile, char *qSizeFile,  char *targetList, char *queryList, char *outName)
/* chainToPsl - Convert chain file to psl format. */
{
struct hash *tSizeHash = readSizes(tSizeFile);
struct hash *qSizeHash = readSizes(qSizeFile);
struct lineFile *lf = lineFileOpen(inName, TRUE);
FILE *f = mustOpen(outName, "w");
struct hash *fileHash = newHash(0);  /* No value. */
struct hash *tHash = newHash(20);  /* seqFilePos value. */
struct hash *qHash = newHash(20);  /* seqFilePos value. */
struct dlList *fileCache = newDlList();
struct chain *chain;
int q,t;

verbose(1, "Scanning %s\n", targetList);
hashFileList(targetList, fileHash, tHash);
verbose(1, "Scanning %s\n", queryList);
hashFileList(queryList, fileHash, qHash);
verbose(1, "Converting %s\n", inName);

while ((chain = chainRead(lf)) != NULL)
    {
    //uglyf("chain %s %s \n",chain->tName,chain->qName); 
    q = findSize(qSizeHash, chain->qName);
    t = findSize(tSizeHash, chain->tName);
    aliStringToPsl(lf, chain->qName, chain->tName, chain->qSize, chain->tSize,
	min(chain->tEnd-chain->tStart, chain->qEnd-chain->qStart), chain->qStart, chain->qEnd, chain->tStart, chain->tEnd,
        chain->qStrand, f, chain, tHash, qHash, fileCache);
    chainFree(&chain);
    }
lineFileClose(&lf);
carefulClose(&f);
}
Exemplo n.º 3
0
 /*
  * Constructor: std::vector<int> B64coder::KeyToDecimal(char* key)
  *
  * Purpose: Finds the decimal value for each char in key with respect to cypher
  *
  * Arguments: char* key = starting address of a char array
  *
  * Returns: std::vector<int> = each int corresponds to a single values decimal value
  */
std::vector<int> B64coder::KeyToDecimal(char* key)
{
        int length = findSize(key);
        std::vector<int> DecCy(length);
        int loc;
        for ( int i = 0; i < length; i++ )
        {
                loc = B64->cypherIndex(*key);
                DecCy[i] = loc;
                key++;
        }
        return DecCy;
}
Exemplo n.º 4
0
Node * Shell_Sort(Node *list)
{

  long Size; //store the size of the integer list
  Size = findSize(list); //find the size
  int q = largest_index(3, Size); //find the largest value for q less than size
  long j, l;
  int count1;
  Node * head = list;
  int pow1, pow2, k;
  
  for (pow1 = q; pow1 >= 0; pow1--)
    {
      for (pow2 = pow1; pow2 >= 0 ; pow2--)
	{
	  Node * cur = head;
	  k = power(3, pow2) * power(2, pow1 - pow2); //use this formula to calculate the sequence elements
	  for (j = 1; j <= (Size - k); j++)
	    {
	      List * dhead = NULL;
	      dhead = List_Insert(dhead, cur);	//insert starting from the first j'th value
	      Node * tmp1 = cur;     
	      for (l = j + k; l <= Size; l = l + k)
		{ //printf("\nj+k=%ld\n", l);
		  count1 = 0;   
		  while (count1 != k)
		    {  
		      tmp1 = tmp1 -> next; //keep on iterating till you reach the correct node
		      count1++;
		    }
		  dhead = List_Insert(dhead, tmp1); //insert node into the sublist
		}
	      Insertion_Sort(dhead); //implement insertion sort
	      cur = cur -> next; //make current as the next node
	      while (dhead != NULL) //free memory due to each sublist before the next iteration
		{
		  List * tmp = dhead;
		  dhead = dhead -> next;
		  free(tmp);
		}	      
	    }	  
	}
    }
  return head; //return the list of integers that has been sorted
}
Exemplo n.º 5
0
int main(int argc,char *argv[]){
	/*input file pointer*/
	FILE *fpInp;
	/*Toplam bulunan string sayisi*/
	int intTotalNumber=0;
	/*String Size*/
	int intStrSize=0;

	/*Arguman kontrolu*/
	/*Program ismi-txt file-aranacak string
	  3 arguman olmasi gerekiyor*/
	if(argc!=3){
		if(argc>3)
			printf("Fazla Argüman\n");
		else
			printf("Eksik Argüman\n");
			
		printf("---Programin dogru kullanim sekli---\n");
		usage();
		exit(0);
	}	

	/*dosyayi aciyoruz*/
	/*kontrollerimizi yapiyoruz*/
	if((fpInp=fopen(argv[1],"r"))==NULL){
		printf("Dosya Hatasi : %s\n",strerror(errno));
		exit(0);
	}
	
	/*dosyayi kapatiyoruz*/
	fclose(fpInp);

	/*Size'ı belirliyoruz*/
	intStrSize=findSize(fpInp,argv[1]);
	/*printf("size : %d",intStrSize);*/

	intTotalNumber=findString(fpInp,argv[1],intStrSize,argv[2]);

	/*Kac kez bulundugunu ekrana basiyoruz*/
	printf("Kelimenin text dosyasindaki toplam sayisi : %d\n",intTotalNumber);

	return 0;
}
void axtDropOverlap(char *inName, char *tSizeFile, char *qSizeFile, char *outName)
/* used for cleaning up self alignments - deletes all overlapping self alignments */
{
struct hash *qSizeHash = readSizes(qSizeFile);
struct lineFile *lf = lineFileOpen(inName, TRUE);
FILE *f = mustOpen(outName, "w");
struct axt *axt;
int totMatch = 0;
int totSkip = 0;
int totLines = 0;

while ((axt = axtRead(lf)) != NULL)
    {
    totLines++;
    totMatch += axt->score;
	if (sameString(axt->qName, axt->tName))
        {
        int qs = axt->qStart;
        int qe = axt->qEnd;
        if (axt->qStrand == '-')
            reverseIntRange(&qs, &qe, findSize(qSizeHash, axt->qName));
        if (axt->tStart == qs && axt->tEnd == qe) 
            {
            /*
            printf( "skip %c\t%s\t%d\t%d\t%d\t%s\t%d\t%d\t%d\n",
              axt->qStrand,
              axt->qName, axt->symCount, axt->qStart, axt->qEnd,
              axt->tName, axt->symCount, axt->tStart, axt->tEnd
              );
              */
            totSkip++;
            continue;
            }
        }
    axtWrite(axt, f);

    axtFree(&axt);
    }
fclose(f);
lineFileClose(&lf);
}
int fileOperations(FILE *outputFile,int* fd,char *directoryName,char *findString){

	DIR *openFile;
	FILE *inputFile=NULL;
	struct dirent *input;
	char directory[MAX];
	char fullDirectory[MAX];
	struct stat statFile;
	pid_t  pid;
	char strPipe[MAX];
	char readpipe[MAX];
	char arr[MAX];
	int stat = 0;
	int size = 0;
	int fifo2;
	int in;
	openFile = opendir(directoryName);

	if(openFile == NULL){
		printf("Dosya acilamadi\n");
		closedir(openFile);
		exit (1);
	}
	
	strncpy(directory,directoryName, MAX - 1);

	//signal(SIGINT, &ctrlcSignal);
        /*Directory okudum*/
	while((input = readdir(openFile)) != NULL){
		
		if(strcmp(input->d_name,".")!=0 && strcmp(input->d_name,"..")!=0){
			
			/*Directory ve altindaki dosyayi bir arraye attim*/
			sprintf(fullDirectory, "%s/%s",directory, input -> d_name );

			if (lstat(fullDirectory,&statFile) < 0){
          			 perror(fullDirectory);
			}
			/*Dosya mi directory mi oldugunu kontrol ettim dosya ise*/
			if (S_ISDIR(statFile.st_mode) == 0){

				/*Dosya sayimi artirdim*/
				totalFile = totalFile + 1;
				if((pid = fork())== -1){
					perror("Not fork\n");
					exit (1);
				}if(pid == 0){
					size = findSize(inputFile,fullDirectory);
					
					totalW += myGrep(inputFile,outputFile,strPipe,fd,size,fullDirectory,findString);
					
					exit (totalW);
				}else{
						// while (r_wait(NULL) > 0);
					/*Asagidaki fonksiyonlari http://www.kaanaslan.com/resource/article/display_article.php?id=87
					 * sitesinden referans alarak kullandim */
					wait(&stat);
					totalW = WEXITSTATUS(stat);
					
				}
				/*Childlari topladim*/
				totalChild = totalChild + 1;
			}else{/*Dosya degil ise recursive olarak fonksiyonumu tekrar cagirdim ki dosyayi bulsun*/
				
				/*Directory sayimi buldum*/
				totalDirectory = totalDirectory + 1;

				if((pid = fork())== -1){
					perror("Not fork\n");
					exit (1);
			
				}
				if(pid == 0){
					
					fileOperations(outputFile,fd,fullDirectory,findString);
				
					if((in= read(fd[0], readpipe,MAX)> 0)){
						
						if(in<=0){
					
							perror("read error \n");
							exit(1);
					        }
					
				
						//close(fd[0]);
					
						if((fifo2 = open(myfifo, O_RDWR ))==-1){
							perror("Not fifo");
						        exit(1);
						}
							
					
						if(write(fifo2,readpipe,sizeof(char)*MAX)<0)
						{
						    	
						    	perror("Failed to write");
						    	exit(1);
					        }
						    	
						close(fifo2);
						if((fifo2 = open(myfifo,O_RDONLY))==-1){
							perror("Not fifo");
						        exit(1);
						}
						in = read( fifo2, arr,sizeof(char)*MAX);
						if(in<=0)
				                {
							perror("not read");
							exit(1);
		
						}
					
						fprintf(outputFile,"%s\n",arr);
						exit(1);
						
				
				     }
				}else{
					
					//while (r_wait(NULL) > 0);
					//close(fd[1]);
					//unlink("myfifo");
					
					
				}	
			}
			
		}
	}
	
	//close(fifo2);
	closedir(openFile);
	return 0;
}
Exemplo n.º 8
0
Link::Link(Node *n) {
  h = n;
  size = findSize();
}
Exemplo n.º 9
0
Link::Link(int v, Node *n) {
  h = new Node(v,n);
  size = findSize();
}
Exemplo n.º 10
0
Link::Link(int v) { h = new Node(v); size = findSize(); }
Exemplo n.º 11
0
Link::Link() { h = 0; size = findSize(); }