int main(int argc, char** argv) { struct mafFile* mf; struct mafAli* ali; struct mafComp* mc; if ( argc != 2) { printf("remove_self maf-file\n"); return 1; } init_scores70(); mafWriteStart(stdout, 0); mf = mafOpen(argv[1], 0); while((ali = mafNext(mf)) != NULL) { mc = ali->components; if(mc->next->strand == '+' && mc->start > mc->next->start) continue; else if(mc->next->strand == '-' && mc->start > (mc->next->srcSize - mc->next->start - mc->next->size)) continue; else mafWrite(stdout, ali); } mafFileFree(&mf); mafWriteEnd(stdout); return 0; }
void mafMeFirst(char *inMaf, char *meFile, char *outMaf) /* mafMeFirst - Move component to top if it is one of the named ones. Useful * in conjunction with mafFrags when you don't want the one with the gene name * to be in the middle.. */ { struct hash *meHash = hashWordsInFile(meFile, 18); struct mafFile *mf = mafOpen(inMaf); FILE *f = mustOpen(outMaf, "w"); mafWriteStart(f, mf->scoring); struct mafAli *maf; while ((maf = mafNext(mf)) != NULL) { struct mafComp *comp = compInHash(maf, meHash); if (comp == NULL) errAbort("No components in %s in maf ending line %d of %s", meFile, mf->lf->lineIx, mf->lf->fileName); slRemoveEl(&maf->components, comp); slAddHead(&maf->components, comp); mafWrite(f, maf); mafAliFree(&maf); } mafWriteEnd(f); carefulClose(&f); }
void mafWriteAll(struct mafFile *mf, char *fileName) /* Write out full mafFile. */ { FILE *f = mustOpen(fileName, "w"); struct mafAli *ali; mafWriteStart(f, mf->scoring); for (ali = mf->alignments; ali != NULL; ali = ali->next) mafWrite(f, ali); mafWriteEnd(f); carefulClose(&f); }
static void mafFrags(char *database, char *track, char *bedFile, char *mafFile) /* mafFrags - Collect MAFs from regions specified in a 6 column bed file. */ { struct slName *orgList = NULL; struct lineFile *lf = lineFileOpen(bedFile, TRUE); FILE *f = mustOpen(mafFile, "w"); if (optionExists("orgs")) { char *orgFile = optionVal("orgs", NULL); char *buf; readInGulp(orgFile, &buf, NULL); orgList = stringToSlNames(buf); /* Ensure that org list starts with database. */ struct slName *me = slNameFind(orgList, database); if (me == NULL) errAbort("Need to have reference database '%s' in %s", database, orgFile); if (me != orgList) { slRemoveEl(&orgList, me); slAddHead(&orgList, me); } } mafWriteStart(f, "zero"); if (bed12) { char *row[12]; while (lineFileRow(lf, row)) { struct bed *bed = bedLoadN(row, ArraySize(row)); struct mafAli *maf = mafFromBed12(database, track, bed, orgList); if (meFirst) moveMeToFirst(maf, bed->name); mafWrite(f, maf); mafAliFree(&maf); bedFree(&bed); } } else { char *row[6]; while (lineFileRow(lf, row)) { struct bed *bed = bedLoadN(row, ArraySize(row)); processBed6(database, track, f, bed, orgList); bedFree(&bed); } } mafWriteEnd(f); carefulClose(&f); }
/* write a malnSet to a MAF file */ void malnSet_writeMaf(struct malnSet *malnSet, char *mafFileName) { malnSet_assert(malnSet); stList *sorted = buildRootSorted(malnSet); FILE *mafFh = mustOpen(mafFileName, "w"); mafWriteStart(mafFh, NULL); stListIterator *iter = stList_getIterator(sorted); struct malnBlk *blk; while ((blk = stList_getNext(iter)) != NULL) { writeBlkToMaf(blk, mafFh); } stList_destructIterator(iter); mafWriteEnd(mafFh); carefulClose(&mafFh); stList_destruct(sorted); }
void endOutFile(FILE *f) { mafWriteEnd(f); carefulClose(&f); }
void stageMultiz(char *hSizeFile, char *mSizeFile, char *rSizeFile, char *humanAxtFile, char *ratMouseDir, char *outputDir) /* stageMultiz - Stage input directory for Webb's multiple aligner. */ { struct binKeeper *humanBk = loadAxtsIntoRange(humanAxtFile, hPrefix, mPrefix); struct hash *mouseHash = newHash(0); struct hash *hSizeHash = loadSizeHash(hSizeFile); struct hash *mSizeHash = loadSizeHash(mSizeFile); struct hash *rSizeHash = loadSizeHash(rSizeFile); struct hash *dupeHash = newHash(16); int hStart; char humanChromName[256]; makeDir(outputDir); splitPath(humanAxtFile, NULL, humanChromName, NULL); if (chromOut) winSize = hashIntVal(hSizeHash, humanChromName); for (hStart = 0; hStart<maxChromSize - winSize; hStart += winSize - overlapSize) { int hEnd = hStart + winSize; struct binElement *humanList = binKeeperFindSorted(humanBk, hStart, hEnd); struct binElement *humanEl; char dirName[512], hmName[512], mrName[512]; FILE *f; if (humanList != NULL) { /* Make output directory and create output file names. */ if (chromOut) sprintf(dirName, "%s", outputDir); else sprintf(dirName, "%s/%s.%d", outputDir, humanChromName, hStart); verbose(1, "Making %s\n", dirName); makeDir(dirName); sprintf(hmName, "%s/12.maf", dirName); sprintf(mrName, "%s/23.maf", dirName); /* Write human/mouse file. */ f = mustOpen(hmName, "w"); mafWriteStart(f, "blastz"); for (humanEl = humanList; humanEl != NULL; humanEl = humanEl->next) { struct axt *axt = humanEl->val; outputAxtAsMaf(f, axt, hSizeHash, hPrefix, mSizeHash, mPrefix); } mafWriteEnd(f); carefulClose(&f); /* Write mouse/rat file. */ f = mustOpen(mrName, "w"); mafWriteStart(f, "blastz"); for (humanEl = humanList; humanEl != NULL; humanEl = humanEl->next) { struct axt *axt = humanEl->val; int start = axt->qStart, end = axt->qEnd; int mouseChromSize = hashIntVal(mSizeHash, axt->qName); if (axt->qStrand == '-') reverseIntRange(&start, &end, mouseChromSize); writeMousePartsAsMaf(f, mouseHash, ratMouseDir, axt->qName, start, end, mouseChromSize, rSizeHash, dupeHash); } mafWriteEnd(f); carefulClose(&f); slFreeList(&humanList); } } }
void xmfaToMaf(char *in, char *out) /* xmfaToMaf - Convert from xmfa to maf format. */ { int c; FILE *input = mustOpen(in, "r"); FILE *output = mustOpen(out, "w"); char* commentLine; struct dnaSeq* sequence; struct mafAli *ali; struct sqlConnection* conn = hAllocConn(); mafWriteStart(output, "mlagan"); AllocVar(ali); while(myFaReadMixedNext(input, TRUE, "default name", TRUE, &commentLine, &sequence)) { char srcName[128]; c = fgetc(input); if(c == '=' || c == '>') { /* add the current sequence and process the block if we've see an '='*/ char org[32]; char chrom[32]; int start; int stop; char strand; struct mafComp *comp; double score; char buffer[1024]; ungetc(c, input); AllocVar(comp); /* parse the comment line */ sscanf(commentLine, ">%s %[^:]:%d-%d %c", org, chrom, &start, &stop, &strand); /* build the name */ safef(srcName, sizeof(srcName), "%s.%s", optionVal(org, org), chrom); comp->src = cloneString(srcName); sqlSafef(buffer, 1024, "SELECT size FROM %s.chromInfo WHERE chrom = \"%s\"", optionVal(org, org), chrom); assert(sqlQuickQuery(conn, buffer, buffer, 1024) != 0); comp->srcSize = atoi(buffer); comp->strand = strand; start = start - 1; comp->start = start; comp->size = ungappedSize(sequence); if(strand == '-') comp->start = comp->srcSize - (comp->start + comp->size); comp->text = sequence->dna; sequence->dna = 0; slAddHead(&ali->components, comp); freeDnaSeq(&sequence); if(c == '=') { fscanf(input, "= score=%lf\n", &score); ali->score = score; slReverse(&ali->components); mafWrite(output, ali); mafAliFree(&ali); AllocVar(ali); } } } mafWriteEnd(output); }