Beispiel #1
0
void fragFind(struct seqList *goodSeq, char *badName, int fragSize, int mismatchesAllowed, 
    boolean considerRc, double profile[16][4])
/* Do fast finding of patterns that are in FA file "goodName", but not in FA file
 * "badName."  BadName can be null.  Pass in the size of the pattern (fragSize) and
 * the number of mismatches to pattern you're willing to tolerate (mismatchesAllowed).
 * It returns the pattern in profile. */
{
int *goodTable, *badTable = NULL;
int goodCount, badCount = 0;
int goodIx;
long startTime;
DNA unpacked[17];

if (mismatchesAllowed > 3)
    errAbort("Sorry, fragFind can only handle 0-3 mismatches.");
if (fragSize > 10)
    errAbort("Sorry, fragFind can only handle fragments up to 10 bases.");

startTime = clock1000();
makeOligoHistogram(NULL, goodSeq, fragSize, &goodTable, &goodCount);
if (badName)
    makeOligoHistogram(badName, NULL, fragSize, &badTable, &badCount);
if (badName)
    {
    normalizeTable(goodTable, fragSize);
    normalizeTable(badTable, fragSize);
    diffTables(goodTable, badTable, fragSize);
    goodIx = fuzzVal(badTable, fragSize, mismatchesAllowed, considerRc);
    }
else
    {
    goodIx = fuzzVal(goodTable, fragSize, mismatchesAllowed, considerRc);
    }
freez(&goodTable);
freez(&badTable);
unpackVal(goodIx, fragSize, unpacked);
makeProfile(unpacked, fragSize, mismatchesAllowed, goodSeq, considerRc, profile);
}
Beispiel #2
0
void ModelsDiffHelper::diffModels(unsigned diff_type)
{
    map<unsigned, BaseObject *> obj_order;
    BaseObject *object=nullptr, *aux_object=nullptr;
    ObjectType obj_type;
    QString obj_name;
    unsigned idx=0, factor=0, prog=0;
    DatabaseModel *aux_model=nullptr;
    bool objs_differs=false, xml_differs=false;

    if(diff_canceled)
        return;

    if(diff_type==ObjectsDiffInfo::DROP_OBJECT)
    {
        /* For DROP detection, we must gather the objects from the database in order to check
           if they exists on the model. The object drop order here is the inverse of the creation order
           on the database */
        obj_order=imported_model->getCreationOrder(SchemaParser::SQL_DEFINITION, true);
        aux_model=source_model;
        factor=25;
    }
    else if(diff_type==ObjectsDiffInfo::CREATE_OBJECT ||
            diff_type==ObjectsDiffInfo::ALTER_OBJECT)
    {
        /* For creation or modification of objects the order followed is the same
           as the creation order on the source model */
        obj_order=source_model->getCreationOrder(SchemaParser::SQL_DEFINITION, true);
        aux_model=imported_model;
        factor=50;
        prog=50;
    }

    for(auto &obj_itr : obj_order)
    {
        object=obj_itr.second;
        obj_type=object->getObjectType();
        idx++;

        /* If this checking the following objects are discarded:
           1) BASE_RELATIONSHIP objects
           2) Objects which SQL code is disabled or system objects
           3) Cluster objects such as roles and tablespaces (when the operatoin is DROP and keep_cluster_objs is true) */
        if(obj_type!=BASE_RELATIONSHIP &&
                !object->isSystemObject() && !object->isSQLDisabled() &&
                ((diff_type==ObjectsDiffInfo::DROP_OBJECT && (!diff_opts[OPT_KEEP_CLUSTER_OBJS] || (diff_opts[OPT_KEEP_CLUSTER_OBJS] && obj_type!=OBJ_ROLE && obj_type!=OBJ_TABLESPACE))) ||
                 (diff_type!=ObjectsDiffInfo::DROP_OBJECT)))
        {
            emit s_progressUpdated(prog + ((idx/static_cast<float>(obj_order.size())) * factor),
                                   trUtf8("Processing object `%1' (%2)...").arg(object->getSignature()).arg(object->getTypeName()),
                                   object->getObjectType());

            //Processing objects that are not database, table child object (they are processed further)
            if(obj_type!=OBJ_DATABASE && !TableObject::isTableObject(obj_type))// && obj_type!=BASE_RELATIONSHIP)
            {
                /* Processing permissions. If the operation is DROP and keep_obj_perms is true the
                   the permission is ignored */
                if(obj_type==OBJ_PERMISSION &&
                        ((diff_type!=ObjectsDiffInfo::DROP_OBJECT) || !diff_opts[OPT_KEEP_OBJ_PERMS]))
                    generateDiffInfo(diff_type, object);

                //Processing relationship (in this case only generalization ones are considered)
                else if(obj_type==OBJ_RELATIONSHIP)
                {
                    Relationship *rel=dynamic_cast<Relationship *>(object);

                    if(rel->getRelationshipType()==BaseRelationship::RELATIONSHIP_GEN)
                    {
                        Table *ref_tab=nullptr, *rec_tab=nullptr;

                        ref_tab=aux_model->getTable(rel->getReferenceTable()->getName(true));
                        rec_tab=aux_model->getTable(rel->getReceiverTable()->getName(true));

                        /* If the receiver table exists on the model generates a info for the relationship,
                           otherwise, the generalization will be created automatically when the table is
                           created (see table's code defintion) */
                        if(rec_tab && !aux_model->getRelationship(ref_tab, rec_tab))
                            generateDiffInfo(diff_type, rel);
                    }
                }
                else if(obj_type!=OBJ_PERMISSION)
                {
                    //Get the object from the database
                    obj_name=object->getSignature();
                    aux_object=aux_model->getObject(obj_name, obj_type);

                    //Special case for many-to-many relationships
                    if(obj_type==OBJ_TABLE && !aux_object)
                        aux_object=getRelNNTable(obj_name, aux_model);

                    if(diff_type!=ObjectsDiffInfo::DROP_OBJECT && aux_object)
                    {
                        /* Try to get a diff from the retrieve object and the current object,
                           comparing only basic attributes like schema, tablespace and owner
                           this is why the BaseObject::getAlterDefinition is called */
                        objs_differs=!aux_object->BaseObject::getAlterDefinition(object).isEmpty();

                        //If the objects does not differ, try to compare their XML definition
                        if(!objs_differs)
                            xml_differs=object->isCodeDiffersFrom(aux_object,
                        {   ParsersAttributes::PROTECTED,
                            ParsersAttributes::SQL_DISABLED,
                            ParsersAttributes::RECT_VISIBLE,
                            ParsersAttributes::FILL_COLOR
                        },
                        {   ParsersAttributes::ROLE,
                            ParsersAttributes::TABLESPACE,
                            ParsersAttributes::COLLATION,
                            ParsersAttributes::POSITION,
                            ParsersAttributes::APPENDED_SQL,
                            ParsersAttributes::PREPENDED_SQL
                        });

                        //If a difference was detected between the objects
                        if(objs_differs || xml_differs)
                        {
                            generateDiffInfo(ObjectsDiffInfo::ALTER_OBJECT, object, aux_object);

                            //If the object is a table, do additional comparision between their child objects
                            if((!diff_opts[OPT_FORCE_RECREATION] || diff_opts[OPT_RECREATE_UNCHANGEBLE]) && object->getObjectType()==OBJ_TABLE)
                            {
                                Table *tab=dynamic_cast<Table *>(object), *aux_tab=dynamic_cast<Table *>(aux_object);
                                diffTables(tab, aux_tab, ObjectsDiffInfo::DROP_OBJECT);
                                diffTables(tab, aux_tab, ObjectsDiffInfo::CREATE_OBJECT);
                            }

                            objs_differs=xml_differs=false;
                        }
                    }
                    else if(!aux_object)
                        generateDiffInfo(diff_type, object);
                }
            }
            //Comparison for constraints (fks), triggers, rules, indexes
            else if(TableObject::isTableObject(obj_type))
                diffTableObject(dynamic_cast<TableObject *>(object), diff_type);
            //Comparison between model db and the imported db
            else if(diff_type==ObjectsDiffInfo::CREATE_OBJECT)
            {
                if(!source_model->getAlterDefinition(imported_model).isEmpty())
                    generateDiffInfo(ObjectsDiffInfo::ALTER_OBJECT, source_model, imported_model);
            }

            if(diff_canceled)
                break;
        }
        else
        {
            generateDiffInfo(ObjectsDiffInfo::IGNORE_OBJECT, object);
            emit s_progressUpdated(prog + ((idx/static_cast<float>(obj_order.size())) * factor),
                                   trUtf8("Skipping object `%1' (%2)...").arg(object->getSignature()).arg(object->getTypeName()),
                                   object->getObjectType());

            if(diff_canceled)
                break;
        }
    }
}