void objc_IncrementExtraRefCount(id object) {
    RefCountBucket *refCount;
    RefCountTable *table = refTable();

    objc_lock_lock(&RefCountLock);
    if((refCount = XXHashGet(table, object)) == NULL) {
        refCount = AllocBucketFromTable(table);
        refCount->object = object;
        refCount->count = 1;
        XXHashInsert(refTable(), refCount);
    }
    refCount->count++;
    objc_lock_unlock(&RefCountLock);
}
示例#2
0
void UniqueConstraint::setRefConstraintsReferencingMe (
     const struct TrafConstrntsDesc* desc, 
     CollHeap* heap,
     BindWA* bindWA)
{
  struct TrafDesc *referencingConstraintDesc = desc->referencing_constrnts_desc;
  ComplementaryRIConstraint *constraintsReferencingMe;

  while (referencingConstraintDesc)
    {
      char *refConstrntName = 
        referencingConstraintDesc->refConstrntsDesc()->constrntname;
      char *refTableName = 
        referencingConstraintDesc->refConstrntsDesc()->tablename;
      
      QualifiedName refConstrnt(refConstrntName, 3, heap, bindWA);
      QualifiedName refTable(refTableName, 3, heap, bindWA);
      
      constraintsReferencingMe = new (heap) ComplementaryRIConstraint(refConstrnt, 
                                                                      refTable,
                                                                      heap);
      refConstraintsReferencingMe_.insert(constraintsReferencingMe);
      
      referencingConstraintDesc = referencingConstraintDesc->next;
    }
} // UniqueConstraint::setRefConstraintsReferencingMe
bool objc_DecrementExtraRefCountWasZero(id object) {
    bool result = false;
    RefCountBucket *refCount;

    objc_lock_lock(&RefCountLock);
    if((refCount = XXHashGet(refTable(), object)) == NULL)
        result = true;
    else {
        refCount->count--;
        if(refCount->count == 1)
            XXHashRemove(refTable(), refCount);
    }
    objc_lock_unlock(&RefCountLock);

    return result;
}
objc_uinteger objc_ExtraRefCount(id object) {
    objc_uinteger result = 1;
    RefCountBucket *refCount;

    objc_lock_lock(&RefCountLock);
    if((refCount = XXHashGet(refTable(), object)) != NULL)
        result = refCount->count;
    objc_lock_unlock(&RefCountLock);

    return result;
}
示例#5
0
//
// Main
//
int somaticVariantFiltersMain(int argc, char** argv)
{
    parseSomaticVariantFiltersOptions(argc, argv);

    Timer* pTimer = new Timer(PROGRAM_IDENT);
    
    // Load Reference
    ReadTable refTable(opt::referenceFile, SRF_NO_VALIDATION);
    refTable.indexReadsByID();

    // Load BAMs
    BamTools::BamReader* pTumorBamReader = new BamTools::BamReader;
    pTumorBamReader->Open(opt::tumorBamFile);
    pTumorBamReader->LocateIndex();

    assert(pTumorBamReader->HasIndex());

    BamTools::BamReader* pNormalBamReader = new BamTools::BamReader;
    pNormalBamReader->Open(opt::normalBamFile);
    pNormalBamReader->LocateIndex();
    assert(pNormalBamReader->HasIndex());

    // Track duplicated variants
    HashSet<std::string> duplicateHash;

    std::ifstream input(opt::vcfFile.c_str());
    std::string line;

    while(getline(input, line))
    {
        if(line.empty())
            continue;

        if(line[0] == '#')
        {
            std::cout << line << "\n";
            continue;
        }
        
        // parse record
        VCFRecord record(line);
        if(record.isMultiAllelic())
        {
            std::cerr << "Error: multi-allelic VCF found, please run vcfbreakmulti\n";
            exit(EXIT_FAILURE);
        }

        // Check if we've seen this variant already
        std::string key = makeVariantKey(record);
        if(duplicateHash.find(key) != duplicateHash.end())
            continue;
        else
            duplicateHash.insert(key);

        if(opt::verbose > 0)
        {
            std::stringstream ss;
            ss << "Variant: " << record << "\n";
            fprintf(stderr, "===============================================\n%s", ss.str().c_str());
        }

        StringStringHash tagHash;
        makeTagHash(record, tagHash);

        StringVector fail_reasons;

        int hplen = 0;
        if(!getTagValue(tagHash, "HPLen", hplen))
            hplen = calculateHomopolymerLength(record, &refTable);
        if(hplen > opt::maxHPLen)
            fail_reasons.push_back("Homopolymer");

        double dust = 0.0f;
        if(!getTagValue(tagHash, "Dust", dust))
            dust = HapgenUtil::calculateDustScoreAtPosition(record.refName, 
                                                            record.refPosition, 
                                                            &refTable);

        if(dust > opt::maxDust)
            fail_reasons.push_back("LowComplexity");
        
        double af;
        if(getTagValue(tagHash, "AF", af) && af < opt::minAF)
            fail_reasons.push_back("LowAlleleFrequency");

        int varDP;
        if(getTagValue(tagHash, "VarDP", varDP) && varDP < opt::minVarDP)
            fail_reasons.push_back("LowVarDP");

        double strandBias;
        if(getTagValue(tagHash, "SB", strandBias) && strandBias >= opt::maxStrandBias)
            fail_reasons.push_back("StrandBias");

        CoverageStats tumor_stats = getVariantCoverage(pTumorBamReader, record, &refTable);
        CoverageStats normal_stats = getVariantCoverage(pNormalBamReader, record, &refTable);

        if(opt::verbose > 0)
        {
            fprintf(stderr, "Tumor: [%zu %zu]\n",  tumor_stats.n_total_reads, tumor_stats.n_evidence_reads);
            fprintf(stderr, "Normal: [%zu %zu]\n", normal_stats.n_total_reads, normal_stats.n_evidence_reads);
        }

        if(normal_stats.n_evidence_reads > opt::maxNormalReads)
            fail_reasons.push_back("NormalEvidence");
        
        if(normal_stats.n_total_reads < opt::minNormalDepth)
            fail_reasons.push_back("LowNormalDepth");

        if(!tumor_stats.snv_evidence_quals.empty())
        {
            double median_quality = median(tumor_stats.snv_evidence_quals);
            if(median_quality < opt::minMedianQuality)
                fail_reasons.push_back("LowQuality");
        }

        if(tumor_stats.median_mapping_quality < opt::minMedianQuality)
            fail_reasons.push_back("LowMappingQuality");

        if(!fail_reasons.empty())
        {
            if(record.passStr != "PASS" && record.passStr != ".")
                fail_reasons.insert(fail_reasons.begin(), record.passStr);

            std::stringstream strss;
            std::copy(fail_reasons.begin(), fail_reasons.end(), std::ostream_iterator<std::string>(strss, ";"));
            record.passStr = strss.str();
            record.passStr.erase(record.passStr.size() - 1); // erase trailing ;
        }

        std::cout << record << "\n";
    }
    
    // Cleanup
    delete pTumorBamReader;
    delete pNormalBamReader;
    delete pTimer;

    return 0;
}