struct variant *variantNew(char *chrom, unsigned start, unsigned end, unsigned numAlleles, char *slashSepAlleles, char *refAllele, struct lm *lm) /* Create a variant from basic information that is easy to extract from most other variant * formats: coords, allele count, string of slash-separated alleles and reference allele. */ { struct variant *variant; // We have a new variant! lmAllocVar(lm, variant); variant->chrom = lmCloneString(lm, chrom); variant->chromStart = start; variant->chromEnd = end; variant->numAlleles = numAlleles; // get the alleles. char *nextAlleleString = lmCloneString(lm, slashSepAlleles); int alleleNumber = 0; for( ; alleleNumber < numAlleles; alleleNumber++) { if (nextAlleleString == NULL) errAbort("number of alleles in /-separated string doesn't match numAlleles"); char *thisAlleleString = nextAlleleString; // advance pointer to next variant string // probably there's some kent routine to do this behind the curtain nextAlleleString = strchr(thisAlleleString, '/'); if (nextAlleleString) // null out '/' and move to next char { *nextAlleleString = 0; nextAlleleString++; } boolean isRefAllele = (sameWord(thisAlleleString, refAllele) || (isEmpty(refAllele) && sameString(thisAlleleString, "-"))); int alleleStringLength = strlen(thisAlleleString); if (isDash(thisAlleleString)) { alleleStringLength = 0; thisAlleleString[0] = '\0'; } // we have a new allele! struct allele *allele; AllocVar(allele); slAddHead(&variant->alleles, allele); allele->variant = variant; allele->length = alleleStringLength; allele->sequence = lmCloneString(lm, thisAlleleString); allele->isReference = isRefAllele; } slReverse(&variant->alleles); return variant; }
char* pathstr(char *arg, char character) { if(character != 'P' || character != 'C') //this is so we can use the one function for both PATH and CDPATH { printf("invalid argument '%c'\n", character); exit(EXIT_FAILURE); } if (isDash(arg)) { printf("argument has a '/' in it\n"); exit(EXIT_FAILURE); } char pathname[MAXPATHLEN]; switch(character) { case 'P': sprintf(pathname, "%s", PATH); break; case 'C': sprintf(pathname, "%s", CDPATH); break; } int listlength = numElements(pathname); char pathlist[listlength][MAXPATHLEN]; char *pathtemp = pathname; //this is so strtok doesn't modify our global variable char *finalstr = malloc(MAXPATHLEN); char *token; char *ch = ":"; // get first token token = strtok(pathtemp, ch); int index = 0; // walk through other tokens while( token != NULL ) { strcpy(pathlist[index], token); ++index; token = strtok(NULL, ch); } // now we should have an array of our directories for(int i=0; i<listlength; i++) { char *dirname = pathlist[i]; DIR *dirp; struct dirent *dp; dirp = opendir(dirname); if(dirp == NULL) { printf("directory doesn't exist"); //re word this exit(EXIT_FAILURE); } while((dp = readdir(dirp)) != NULL) { if(strcmp(dp->d_name, arg)) { sprintf(finalstr, "%s/%s", pathlist[i], arg); } } closedir(dirp); } return finalstr; }