void KviRegisteredChannelDataBase::add(KviRegisteredChannel * c) { KviRegisteredChannel * old = findExact(c->name(),c->netMask()); if(old) { // merge properties QHash<QString,QString> * pPropertyDict = old->propertyDict(); KVI_ASSERT(pPropertyDict); for(QHash<QString,QString>::Iterator it = pPropertyDict->begin();it != pPropertyDict->end();++it) { if(!c->property(it.key()).isEmpty()) c->setProperty(it.key(),it.value()); } remove(old); } KviRegisteredChannelList * l = m_pChannelDict->value(c->name()); if(!l) { l = new KviRegisteredChannelList(); l->setAutoDelete(true); m_pChannelDict->insert(c->name(),l); } // insert where there are less wildcards int o = c->netMask().count(QChar('*')); int idx = 0; for(KviRegisteredChannel * rc = l->first();rc;rc = l->next()) { if(rc->netMask().count(QChar('*')) > o) { // the existing has more wildcards, insert here! l->insert(idx,c); return; } idx++; } l->append(c); }
void txGeneAccession(char *oldBedFile, char *lastIdFile, char *newBedFile, char *txToAccFile, char *oldToNewFile) /* txGeneAccession - Assign permanent accession number to genes. */ { /* Read in all input. */ struct bed *oldList = bedLoadNAll(oldBedFile, 12); verbose(2, "Read %d from %s\n", slCount(oldList), oldBedFile); struct bed *newList = bedLoadNAll(newBedFile, 12); verbose(2, "Read %d from %s\n", slCount(newList), newBedFile); int txId = readNumberFromFile(lastIdFile); verbose(2, "Last txId used was %d (from %s)\n", txId, lastIdFile); /* Make a random-access data structure for old list. */ struct hash *oldHash = bedsIntoKeeperHash(oldList); /* Make a little hash to help prevent us from reusing an * old accession twice (which might happen if we extend it * in two incompatible ways). */ struct hash *usedHash = hashNew(16); /* Record our decisions in hash as well as file. */ struct hash *idToAccHash = hashNew(16); /* Loop through new list first looking for exact matches. Record * exact matches in hash so we don't look for them again during * the next, "compatable" match phase. */ struct hash *oldExactHash = hashNew(16), *newExactHash = hashNew(16); struct bed *oldBed, *newBed; FILE *f = mustOpen(txToAccFile, "w"); FILE *fOld = mustOpen(oldToNewFile, "w"); for (newBed = newList; newBed != NULL; newBed = newBed->next) { oldBed = findExact(newBed, oldHash, usedHash); if (oldBed != NULL) { hashAdd(oldExactHash, oldBed->name, oldBed); hashAdd(newExactHash, newBed->name, newBed); hashAdd(usedHash, oldBed->name, NULL); fprintf(f, "%s\t%s\n", newBed->name, oldBed->name); hashAdd(idToAccHash, newBed->name, oldBed->name); fprintf(fOld, "%s:%d-%d\t%s\t%s\t%s\n", oldBed->chrom, oldBed->chromStart, oldBed->chromEnd, oldBed->name, oldBed->name, "exact"); } } /* Loop through new bed looking for compatible things. If * we can't find anything compatable, make up a new accession. */ for (newBed = newList; newBed != NULL; newBed = newBed->next) { if (!hashLookup(newExactHash, newBed->name)) { oldBed = findCompatible(newBed, oldHash, usedHash); if (oldBed == NULL) { char newAcc[16]; txGeneAccFromId(++txId, newAcc); strcat(newAcc, ".1"); fprintf(f, "%s\t%s\n", newBed->name, newAcc); hashAdd(idToAccHash, newBed->name, cloneString(newAcc)); oldBed = findMostOverlapping(newBed, oldHash); char *oldAcc = (oldBed == NULL ? "" : oldBed->name); fprintf(fOld, "%s:%d-%d\t%s\t%s\t%s\n", newBed->chrom, newBed->chromStart, newBed->chromEnd, oldAcc, newAcc, "new"); } else { char *acc = cloneString(oldBed->name); char *ver = strchr(acc, '.'); if (ver == NULL) errAbort("No version found in %s", oldBed->name); *ver++ = 0; int version = sqlUnsigned(ver); char newAcc[16]; safef(newAcc, sizeof(newAcc), "%s.%d", acc, version+1); hashAdd(usedHash, oldBed->name, NULL); fprintf(f, "%s\t%s\n", newBed->name, newAcc); hashAdd(idToAccHash, newBed->name, newAcc); fprintf(fOld, "%s:%d-%d\t%s\t%s\t%s\n", newBed->chrom, newBed->chromStart, newBed->chromEnd, oldBed->name, newAcc, "compatible"); } } } carefulClose(&f); /* Make a random-access data structure for old list. */ struct hash *newHash = bedsIntoKeeperHash(newList); /* Write record of ones that don't map. */ for (oldBed = oldList; oldBed != NULL; oldBed = oldBed->next) { if (!hashLookup(usedHash, oldBed->name)) { char *newAcc = ""; struct bed *newBed = findMostOverlapping(oldBed, newHash); if (newBed != NULL) newAcc = hashMustFindVal(idToAccHash, newBed->name); fprintf(fOld, "%s:%d-%d\t%s\t%s\t%s\n", oldBed->chrom, oldBed->chromStart, oldBed->chromEnd, oldBed->name, newAcc, "lost"); } } carefulClose(&fOld); if (!optionExists("test")) { FILE *fId = mustOpen(lastIdFile, "w"); fprintf(fId, "%d\n", txId); carefulClose(&fId); } }