src/hg/pslMap/pslMap.c 1.17
1.17 2009/07/10 18:11:56 markd
added option to output mapping chain that was used
Index: src/hg/pslMap/pslMap.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/pslMap/pslMap.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -b -B -U 4 -r1.16 -r1.17
--- src/hg/pslMap/pslMap.c 27 Jul 2007 05:26:19 -0000 1.16
+++ src/hg/pslMap/pslMap.c 10 Jul 2009 18:11:56 -0000 1.17
@@ -20,8 +20,9 @@
{"chainMapFile", OPTION_BOOLEAN},
{"swapMap", OPTION_BOOLEAN},
{"swapIn", OPTION_BOOLEAN},
{"mapInfo", OPTION_STRING},
+ {"mappingPsls", OPTION_STRING},
{"simplifyMappingIds", OPTION_BOOLEAN},
{NULL, 0}
};
@@ -32,8 +33,9 @@
static boolean swapMap = FALSE;
static boolean swapIn = FALSE;
static boolean simplifyMappingIds = FALSE;
static char* mapInfoFile = NULL;
+static char* mappingPslFile = NULL;
static char *mapInfoHdr =
"#srcQName\t" "srcQStart\t" "srcQEnd\t" "srcQSize\t"
"srcTName\t" "srcTStart\t" "srcTEnd\t"
@@ -211,9 +213,9 @@
freeMem(oldQName);
}
static void mapPslPair(struct psl *inPsl, struct mapAln *mapAln,
- FILE* outPslFh, FILE *mapInfoFh)
+ FILE* outPslFh, FILE *mapInfoFh, FILE *mappingPslFh)
/* map one pair of query and target PSL */
{
struct psl* mappedPsl;
if (inPsl->tSize != mapAln->psl->qSize)
@@ -229,22 +231,24 @@
addQNameSuffix(mappedPsl);
pslTabOut(mappedPsl, outPslFh);
if (mapInfoFh != NULL)
writeMapInfo(mapInfoFh, inPsl, mapAln, mappedPsl);
+ if (mappingPslFh != NULL)
+ pslTabOut(mapAln->psl, mappingPslFh);
}
pslFree(&mappedPsl);
}
static void mapQueryPsl(struct psl* inPsl, struct chromBins *mapAlns,
- FILE* outPslFh, FILE *mapInfoFh)
+ FILE* outPslFh, FILE *mapInfoFh, FILE *mappingPslFh)
/* map a query psl to all targets */
{
static struct dyString *idBuf = NULL;
struct binElement *overMapAlns
= chromBinsFind(mapAlns, getMappingId(inPsl->tName, &idBuf), inPsl->tStart, inPsl->tEnd);
struct binElement *overMapAln;
for (overMapAln = overMapAlns; overMapAln != NULL; overMapAln = overMapAln->next)
- mapPslPair(inPsl, (struct mapAln *)overMapAln->val, outPslFh, mapInfoFh);
+ mapPslPair(inPsl, (struct mapAln *)overMapAln->val, outPslFh, mapInfoFh, mappingPslFh);
slFreeList(&overMapAlns);
}
static void pslMap(char* inPslFile, char *mapFile, char *outPslFile)
@@ -252,9 +256,9 @@
{
struct chromBins *mapAlns;
struct psl* inPsl;
struct lineFile* inPslLf = pslFileOpen(inPslFile);
-FILE *outPslFh, *mapInfoFh = NULL;
+FILE *outPslFh, *mapInfoFh = NULL, *mappingPslFh = NULL;
if (chainMapFile)
mapAlns = loadMapChains(mapFile);
else
@@ -265,15 +269,18 @@
{
mapInfoFh = mustOpen(mapInfoFile, "w");
fputs(mapInfoHdr, mapInfoFh);
}
+if (mappingPslFile != NULL)
+ mappingPslFh = mustOpen(mappingPslFile, "w");
while ((inPsl = pslNext(inPslLf)) != NULL)
{
if (swapIn)
pslSwap(inPsl, FALSE);
- mapQueryPsl(inPsl, mapAlns, outPslFh, mapInfoFh);
+ mapQueryPsl(inPsl, mapAlns, outPslFh, mapInfoFh, mappingPslFh);
pslFree(&inPsl);
}
+carefulClose(&mappingPslFh);
carefulClose(&mapInfoFh);
carefulClose(&outPslFh);
lineFileClose(&inPslLf);
}
@@ -291,8 +298,9 @@
swapMap = optionExists("swapMap");
swapIn = optionExists("swapIn");
simplifyMappingIds = optionExists("simplifyMappingIds");
mapInfoFile = optionVal("mapInfo", NULL);
+mappingPslFile = optionVal("mappingPsls", NULL);
pslMap(argv[1], argv[2], argv[3]);
return 0;
}