MamdaNewsHeadline::MamdaNewsHeadlineImpl::~MamdaNewsHeadlineImpl () { destroyStringArray (mNativeCodes, mNumNativeCodes); destroyStringArray (mNativeSymbols, mNumNativeSymbols); destroyStringArray (mIndustries, mNumIndustries); destroyStringArray (mMarketSectors, mNumMarketSectors); destroyStringArray (mRegions, mNumRegions); destroyStringArray (mCountries, mNumCountries); destroyStringArray (mProducts, mNumProducts); destroyStringArray (mTopics, mNumTopics); destroyStringArray (mMiscCodes, mNumMiscCodes); destroyStringArray (mSymbols, mNumSymbols); }
void test_implode(const char * str, const char * delims, const char * glue) { int len; char * * strArr = explode(str, delims, &len); char * resultStr = implode(strArr, len, glue); printf("Exploding \"%s\" by \"%s\" then imploding using \"%s\" gives \"%s\"\n", str, delims, glue, resultStr); destroyStringArray(strArr, len); free(resultStr); }
void test_sortStringArray(const char * str) { int len; char * * strArr = explode(str, " ", &len); sortStringArray(strArr, len); char * sortedStr = implode(strArr, len, " "); printf("Sorting \"%s\" gives \"%s\"\n", str, sortedStr); destroyStringArray(strArr, len); free(sortedStr); }
/*------------------------------------------------------------------------*/ int get_z_ticks_property(void* _pvCtx, char* pobjUID) { int iNbTicks = 0; int *piNbTicks = &iNbTicks; int iView = 0; int* piView = &iView; /* retrieve number of ticks */ getGraphicObjectProperty(pobjUID, __GO_Z_AXIS_NUMBER_TICKS__, jni_int, (void**)&piNbTicks); /* retrieve view: 0 -> 2d // 1 -> 3d */ getGraphicObjectProperty(pobjUID, __GO_VIEW__, jni_int, (void**)&piView); if (piNbTicks == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"),"z_ticks"); return -1; } if (iNbTicks == 0 || iView == 0) { /* return empty matrices */ buildTListForTicks( NULL, NULL, 0); } else { char ** labels = NULL; double * positions = NULL; getGraphicObjectProperty(pobjUID, __GO_Z_AXIS_TICKS_LOCATIONS__, jni_double_vector, (void **) &positions); getGraphicObjectProperty(pobjUID, __GO_Z_AXIS_TICKS_LABELS__, jni_string_vector, (void **) &labels); if (positions == NULL || labels == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"),"z_ticks"); return -1; } buildTListForTicks( positions, labels, iNbTicks); /* free arrays */ #if 0 destroyStringArray(labels, iNbTicks); FREE(positions); #endif } return 0; }
void test_explode(const char * str, const char * delims) { int strArrLen; char * * strArr = explode(str, delims, &strArrLen); printf("Exploding \"%s\" gives: { ", str); int ind; for (ind = 0; ind < strArrLen; ind ++) { printf("\"%s\" ",strArr[ind]); } printf("}, total %d elements.\n", strArrLen); destroyStringArray(strArr, strArrLen); }
/*------------------------------------------------------------------------*/ void* get_y_ticks_property(void* _pvCtx, int iObjUID) { int iNbTicks = 0; int *piNbTicks = &iNbTicks; void* tList = NULL; /* retrieve number of ticks */ getGraphicObjectProperty(iObjUID, __GO_Y_AXIS_NUMBER_TICKS__, jni_int, (void **) &piNbTicks); if (piNbTicks == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "y_ticks"); return NULL; } if (iNbTicks == 0) { /* return empty matrices */ tList = buildTListForTicks(NULL, NULL, 0); } else { char ** labels = NULL; double* positions = NULL; getGraphicObjectProperty(iObjUID, __GO_Y_AXIS_TICKS_LOCATIONS__, jni_double_vector, (void **) &positions); getGraphicObjectProperty(iObjUID, __GO_Y_AXIS_TICKS_LABELS__, jni_string_vector, (void **) &labels); if (positions == NULL || labels == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "y_ticks"); return NULL; } tList = buildTListForTicks(positions, labels, iNbTicks); /* free arrays */ #if 0 destroyStringArray(labels, iNbTicks); FREE(positions); #endif } return tList; }
/*------------------------------------------------------------------------*/ int set_tics_labels_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol) { BOOL status = FALSE; int iNbTicksLabels = 0; int* piNbTicksLabels = &iNbTicksLabels; char** stringVector = NULL; if (valueType != sci_strings) { Scierror(999, _("Wrong type for '%s' property: String matrix expected.\n"), "tics_labels"); return SET_PROPERTY_ERROR; } getGraphicObjectProperty(iObjUID, __GO_NUMBER_TICKS_LABELS__, jni_int, (void**)&piNbTicksLabels); if (piNbTicksLabels == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "tics_labels"); return SET_PROPERTY_ERROR; } if (iNbTicksLabels > nbRow * nbCol) { Scierror(999, _("Wrong size for '%s' property: At least %d elements expected.\n"), "tics_labels", iNbTicksLabels); return SET_PROPERTY_ERROR; } stringVector = createCopyStringMatrixFromStack(_pvData, nbRow * nbCol); /* Check if we should load LaTex / MathML Java libraries */ loadTextRenderingAPI(stringVector, nbRow * nbCol, 1); status = setGraphicObjectProperty(iObjUID, __GO_TICKS_LABELS__, stringVector, jni_string_vector, nbRow * nbCol); destroyStringArray(stringVector, nbRow * nbCol); if (status == TRUE) { return SET_PROPERTY_SUCCEED; } else { Scierror(999, _("'%s' property does not exist for this handle.\n"), "tics_labels"); return SET_PROPERTY_ERROR; } }
int InitAxesModel() { int cubeScaling = 0; int logFlag = 0; int ticksColor = 0; int axisLocation = 0; int boxType = 0; int filled = 0; int gridColor = 0; int gridPosition = 0; int view = 0; int axisReverse = 0; int axisVisible = 0; int defaultNumberTicks = 0; int autoTicks = 0; int autoSubticks = 0; int nbSubticks = 0; int hiddenAxisColor = 0; int hiddenColor = 0; int isoview = 0; int visible = 0; int *piVisible = &visible; int clipState = 0; int tightLimits = 0; int arcDrawingMethod = 0; int labelsFontStyle = 6; int labelsFontColor = -1; int i = 0; double labelsFontSize = 1; double axesBounds[4]; double dataBounds[6]; double rotationAngles[2]; double tab[] = { 0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. }; /* graduations init. tmptab */ /* z-axis initial ticks locations */ double tabZTicksLocations[] = { -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 }; char labelBuffer[LABEL_BUFFER_LENGTH]; char **stringVector = NULL; int lineColor = -1; int background = -2; int foreground = -1; double lineWidth = 1.0; /* 0: solid */ int lineStyle = 0; int markMode = 0; int lineMode = 1; int fillMode = 1; int markStyle = 0; int markSize = 0; /* 0: point, 1: tabulated */ int markSizeUnit = 1; int iLabelUID = 0; int iFiguremdlUID = getFigureModel(); int iAxesmdlUID = getAxesModel(); sciInitGraphicMode(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_BACKGROUND__, &background, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_COLOR__, &foreground, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_FONT_SIZE__, &labelsFontSize, jni_double, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_FONT_COLOR__, &labelsFontColor, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_FONT_STYLE__, &labelsFontStyle, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_THICKNESS__, &lineWidth, jni_double, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_STYLE__, &lineStyle, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_MODE__, &markMode, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_MODE__, &lineMode, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_FILL_MODE__, &fillMode, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_STYLE__, &markStyle, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_SIZE__, &markSize, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_SIZE_UNIT__, &markSizeUnit, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_BACKGROUND__, &background, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_FOREGROUND__, &foreground, jni_int, 1); cubeScaling = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_CUBE_SCALING__, &cubeScaling, jni_bool, 1); /* Log flags set to linear for the 3 axes */ logFlag = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_LOG_FLAG__, &logFlag, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_LOG_FLAG__, &logFlag, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_LOG_FLAG__, &logFlag, jni_bool, 1); ticksColor = -1; setGraphicObjectProperty(iAxesmdlUID, __GO_TICKS_COLOR__, &ticksColor, jni_int, 1); nbSubticks = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); /* 0 corresponds to bottom position */ axisLocation = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_LOCATION__, &axisLocation, jni_int, 1); /* 4 corresponds to left position */ axisLocation = 4; setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_LOCATION__, &axisLocation, jni_int, 1); /* 0 corresponds to OFF */ boxType = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_BOX_TYPE__, &boxType, jni_int, 1); filled = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_FILLED__, &filled, jni_bool, 1); gridColor = -1; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_GRID_COLOR__, &gridColor, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_GRID_COLOR__, &gridColor, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_GRID_COLOR__, &gridColor, jni_int, 1); /* 0: background */ setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_COLOR__, &lineColor, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_BACKGROUND__, &background, jni_int, 1); gridPosition = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_GRID_POSITION__, &gridPosition, jni_int, 1); rotationAngles[0] = 0.0; rotationAngles[1] = 270.0; setGraphicObjectProperty(iAxesmdlUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2); /* 0: 2D view */ view = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_VIEW__, &view, jni_int, 1); /* Must be set after VIEW, since setting VIEW to 2D overwrites the 3D rotation angles */ rotationAngles[0] = 45.0; rotationAngles[1] = 215.0; setGraphicObjectProperty(iAxesmdlUID, __GO_ROTATION_ANGLES_3D__, rotationAngles, jni_double_vector, 2); axisVisible = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_VISIBLE__, &axisVisible, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_VISIBLE__, &axisVisible, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_VISIBLE__, &axisVisible, jni_bool, 1); axisReverse = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_REVERSE__, &axisReverse, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_REVERSE__, &axisReverse, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_REVERSE__, &axisReverse, jni_bool, 1); /* Corresponds to the MVC AUTO_SUBTICKS property (!flagNax is equivalent to AUTO_SUBTICKS) */ #if 0 ppaxesmdl->flagNax = FALSE; #endif autoSubticks = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_AUTO_SUBTICKS__, &autoSubticks, jni_bool, 1); /* To be corrected when the equivalent of flagnax is implemented within the MVC */ nbSubticks = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); /* * The code creating default ticks labels and positions should be put * into the Model. Ticks positions and locations should be computed using the default data bounds * instead of using pre-defined values. * Note that the pre-MVC ticks labels creation code is implemented in the C++ Renderer module * and should be moved to the Java Model's relevant parts (TicksProperty). */ /* * Automatic ticks computation must be activated for the 3 axes before setting ticks values to * ensure that the ticks values set are the automatic ticks' ones. */ autoTicks = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); defaultNumberTicks = 11; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_TICKS_LOCATIONS__, tab, jni_double_vector, defaultNumberTicks); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_TICKS_LOCATIONS__, tab, jni_double_vector, defaultNumberTicks); stringVector = createStringArray(defaultNumberTicks); if (stringVector == NULL) { return -1; } /* * A proper format should be used (ChoixFormatE function) */ for (i = 0; i < defaultNumberTicks; i++) { sprintf(labelBuffer, "%.1f", tab[i]); stringVector[i] = os_strdup(labelBuffer); if (stringVector[i] == NULL) { return -1; } } setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, defaultNumberTicks); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, defaultNumberTicks); /* * The same number of ticks is used now for the x,y and z axes. * Previously, the z-axis contained only 3 ticks (-1, 0, 1). However, the renderer module was * overriding this default number (3) by creating an 11-tick z-axis when required (3D view). * Ticks locations and labels are however different for the z-axis (from -1 to +1 instead of 0 to 1). */ setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_TICKS_LOCATIONS__, tabZTicksLocations, jni_double_vector, defaultNumberTicks); /* ChoixFormatE should be used */ for (i = 0; i < defaultNumberTicks; i++) { FREE(stringVector[i]); sprintf(labelBuffer, "%.1f", tabZTicksLocations[i]); stringVector[i] = os_strdup(labelBuffer); if (stringVector[i] == NULL) { return -1; } } setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, defaultNumberTicks); destroyStringArray(stringVector, defaultNumberTicks); /* * Indicates the direction of projection (0 for the axis corresponding to the direction, * 1 for the others). * To be implemented within the MVC if determined to be useful. */ #if 0 ppaxesmdl->project[0] = 1; ppaxesmdl->project[1] = 1; ppaxesmdl->project[2] = 0; #endif hiddenAxisColor = 4; setGraphicObjectProperty(iAxesmdlUID, __GO_HIDDEN_AXIS_COLOR__, &hiddenAxisColor, jni_int, 1); hiddenColor = 4; setGraphicObjectProperty(iAxesmdlUID, __GO_HIDDEN_COLOR__, &hiddenColor, jni_int, 1); isoview = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_ISOVIEW__, &isoview, jni_bool, 1); /* Axes bounds set to fill the whole drawing area */ axesBounds[0] = 0.0; axesBounds[1] = 0.0; axesBounds[2] = 1.0; axesBounds[3] = 1.0; setGraphicObjectProperty(iAxesmdlUID, __GO_AXES_BOUNDS__, axesBounds, jni_double_vector, 4); /* xmin, xmax */ dataBounds[0] = 0.0; dataBounds[1] = 1.0; /* ymin, ymax */ dataBounds[2] = 0.0; dataBounds[3] = 1.0; /* zmin, zmax */ dataBounds[4] = -1.0; dataBounds[5] = 1.0; setGraphicObjectProperty(iAxesmdlUID, __GO_DATA_BOUNDS__, dataBounds, jni_double_vector, 6); /* visible */ getGraphicObjectProperty(iFiguremdlUID, __GO_VISIBLE__, jni_bool, (void**)&piVisible); setGraphicObjectProperty(iAxesmdlUID, __GO_VISIBLE__, &visible, jni_bool, 1); /* 0: clipping off */ clipState = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_CLIP_STATE__, &clipState, jni_int, 1); /* "real data bounds" and "data bounds" are initially the same */ setGraphicObjectProperty(iAxesmdlUID, __GO_REAL_DATA_BOUNDS__, dataBounds, jni_double_vector, 6); tightLimits = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_TIGHT_LIMITS__, &tightLimits, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_TIGHT_LIMITS__, &tightLimits, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_TIGHT_LIMITS__, &tightLimits, jni_bool, 1); /* Sets the default arc drawing method to lines (1), which is faster */ arcDrawingMethod = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_ARC_DRAWING_METHOD__, &arcDrawingMethod, jni_int, 1); /* Creates the Axes model's labels and sets the model as their parent */ iLabelUID = initLabel(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_TITLE__, &iLabelUID, jni_int, 1); iLabelUID = initLabel(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_LABEL__, &iLabelUID, jni_int, 1); iLabelUID = initLabel(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_LABEL__, &iLabelUID, jni_int, 1); iLabelUID = initLabel(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_LABEL__, &iLabelUID, jni_int, 1); return 0; }
/*------------------------------------------------------------------------*/ int set_xtics_coord_property(void* _pvCtx, char* pobjUID, void* _pvData, int valueType, int nbRow, int nbCol) { BOOL status = FALSE; int N = 0; double* vector = NULL; char c_format[5]; int iXNumberTicks = 0; int* piXNumberTicks = &iXNumberTicks; char** stringVector = NULL; int iTicksStyle = 0; int* piTicksStyle = &iTicksStyle; char ticksStyle = 0; if (valueType != sci_matrix) { Scierror(999, _("Wrong type for '%s' property: Real matrix expected.\n"), "xtics_coord"); return SET_PROPERTY_ERROR; } if (nbRow != 1) { Scierror(999, _("Wrong size for '%s' property: Row vector expected.\n"), "xtics_coord"); return SET_PROPERTY_ERROR; } getGraphicObjectProperty(pobjUID, __GO_X_NUMBER_TICKS__, jni_int, (void**)&piXNumberTicks); if (piXNumberTicks == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "xtics_coord"); return SET_PROPERTY_ERROR; } if (iXNumberTicks == 1 && nbCol != 1) { Scierror(999, _("Wrong size for '%s' property: Scalar expected.\n"), "xtics_coord"); return SET_PROPERTY_ERROR; } if (iXNumberTicks != 1 && nbCol == 1) { Scierror(999, _("Wrong size for '%s' property: At least %d elements expected.\n"), "xtics_coord", 2); return SET_PROPERTY_ERROR; } /* what follows remains here as it was */ status = setGraphicObjectProperty(pobjUID, __GO_X_TICKS_COORDS__, _pvData, jni_double_vector, nbCol); if (status == FALSE) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "xtics_coord"); return SET_PROPERTY_ERROR; } getGraphicObjectProperty(pobjUID, __GO_TICKS_STYLE__, jni_int, (void**)&piTicksStyle); if (iTicksStyle == 0) { ticksStyle = 'v'; } else if (iTicksStyle == 1) { ticksStyle = 'r'; } else if (iTicksStyle == 2) { ticksStyle = 'i'; } if (ComputeXIntervals(pobjUID, ticksStyle, &vector, &N, 0) != 0) { /* Something wrong happened */ FREE(vector); return -1; } if (ComputeC_format(pobjUID, c_format) != 0) { /* Something wrong happened */ FREE(vector); return -1; } stringVector = copyFormatedArray(vector, N, c_format, 256); status = setGraphicObjectProperty(pobjUID, __GO_TICKS_LABELS__, stringVector, jni_string_vector, N); FREE(vector); destroyStringArray(stringVector, N); if (status == TRUE) { return SET_PROPERTY_SUCCEED; } else { return SET_PROPERTY_ERROR; } }
void checkBlock(mafBlock_t *block) { // read through each line of a mafBlock and filter duplicates. // Report the top scoring duplication only. mafLine_t *ml = maf_mafBlock_getHeadLine(block); unsigned n = maf_mafLine_getNumberOfSequences(ml); char **species = (char **) de_malloc(sizeof(char *) * n); char **sequences = (char **) de_malloc(sizeof(char *) * n); int index = 0; bool containsDuplicates = false; duplicate_t *d = NULL, *dupSpeciesHead = NULL; while (ml != NULL) { if (maf_mafLine_getType(ml) != 's') { // skip non-sequence lines ml = maf_mafLine_getNext(ml); continue; } species[index] = de_strdup(maf_mafLine_getSpecies(ml)); sequences[index] = de_strdup(maf_mafLine_getSequence(ml)); duplicate_t *thisDup = findDuplicate(dupSpeciesHead, maf_mafLine_getSpecies(ml)); if (thisDup == NULL) { // first instance of species, add to list if (dupSpeciesHead == NULL) { dupSpeciesHead = newDuplicate(); d = dupSpeciesHead; } else { d->next = newDuplicate(); d = d->next; } d->species = de_strdup(maf_mafLine_getSpecies(ml)); // create the mafline linked list d->headScoredMaf = newScoredMafLine(); d->headScoredMaf->mafLine = ml; d->tailScoredMaf = d->headScoredMaf; } else { // this sequence is a duplicate, extend the duplicate list. containsDuplicates = true; ++(thisDup->numSequences); scoredMafLine_t *sml = thisDup->tailScoredMaf; sml->next = newScoredMafLine(); sml = sml->next; sml->mafLine = ml; thisDup->tailScoredMaf = sml; } ++index; ml = maf_mafLine_getNext(ml); } if (!containsDuplicates) { reportBlock(block); destroyStringArray(species, n); destroyStringArray(sequences, n); destroyDuplicates(dupSpeciesHead); return; } // this block contains duplicates char *consensus = (char *) de_malloc(longestLine(block) + 1); consensus[0] = '\0'; buildConsensus(consensus, sequences, n, maf_mafLine_getLineNumber(maf_mafBlock_getHeadLine(block))); // lineno used for error reporting findBestDupes(dupSpeciesHead, consensus); reportBlockWithDuplicates(block, dupSpeciesHead); // clean up destroyStringArray(species, n); destroyStringArray(sequences, n); destroyDuplicates(dupSpeciesHead); free(consensus); }
void checkBlock(mafBlock_t *block) { // read through each line of a mafBlock and filter duplicates. // Report the top scoring duplication only. unsigned n = maf_numberOfSequencesMafLineList(block->headLine); char **species = (char **) de_malloc(sizeof(char *) * n); char **sequences = (char **) de_malloc(sizeof(char *) * n); int index = 0; bool containsDuplicates = false; mafLine_t *m = block->headLine; duplicate_t *d = NULL, *dupSpeciesHead = NULL; while (m != NULL) { if (m->type != 's') { // skip non-sequence lines m = m->next; continue; } species[index] = (char *) de_malloc(kMaxSeqName); sequences[index] = (char *) de_malloc(strlen(m->sequence) + 1); strcpy(species[index], m->species); strcpy(sequences[index], m->sequence); duplicate_t *thisDup = findDuplicate(dupSpeciesHead, m->species); if (thisDup == NULL) { // add new duplicate species debug("adding new species %s\n", m->species); if (dupSpeciesHead == NULL) { dupSpeciesHead = newDuplicate(); d = dupSpeciesHead; } else { d->next = newDuplicate(); d = d->next; } d->species = (char *) de_malloc(kMaxSeqName); strcpy(d->species, m->species); // create the mafline linked list d->headScoredMaf = newScoredMafLine(); d->headScoredMaf->mafLine = m; } else { // this sequence is a duplicate, extend the duplicate list. debug("extending duplicate on species %s\n", m->species); containsDuplicates = true; scoredMafLine_t *ml = thisDup->headScoredMaf; while (ml->next != NULL) ml = ml->next; ml->next = newScoredMafLine(); ml = ml->next; ml->mafLine = m; } ++index; m = m->next; } if (!containsDuplicates) { reportBlock(block); destroyStringArray(species, n); destroyStringArray(sequences, n); destroyDuplicates(dupSpeciesHead); return; } // this block contains duplicates char *consensus = (char *) de_malloc(longestLine(block) + 1); consensus[0] = '\0'; buildConsensus(consensus, sequences, n, block->headLine->lineNumber); findBestDupes(dupSpeciesHead, consensus); reportBlockWithDuplicates(block, dupSpeciesHead); destroyStringArray(species, n); destroyStringArray(sequences, n); destroyDuplicates(dupSpeciesHead); free(consensus); }