Exemplo n.º 1
0
/* main genomecov function */
int main_genomecov(int argc, char *argv[]){
    char *output, *outCovfile, *optoutput=NULL;
    int c;
    time_t start_time, end_time;
    start_time = time(NULL);
    while ((c = getopt(argc, argv, "o:h?")) >= 0) {
        switch (c) {
            case 'o': optoutput = strdup(optarg); break;
            case 'h':
            case '?': return genomecov_usage(); break;
            default: return 1;
        }
    }
    if (optind + 2 > argc)
        return genomecov_usage();
    char *chrsizefile = argv[optind];
    char *bedgraph = argv[optind+1];
    if(optoutput) {
        output = optoutput;
    } else {
        output = cloneString(get_filename_without_ext(basename(bedgraph)));
    }
    
    if(asprintf(&outCovfile, "%s.genomeCoverage", output) < 0)
        errAbort("Mem Error.\n");

    fprintf(stderr, "* Calculating genome coverage\n");
    struct hash *hash = calGenomeCovBedGraph(chrsizefile, bedgraph);
    writeGenomeCov(hash, outCovfile);

    end_time = time(NULL);
    fprintf(stderr, "* Done, time used %.0f seconds.\n", difftime(end_time, start_time));
    return 0;
}
Exemplo n.º 2
0
pal::string_t get_runtime_config_from_file(const pal::string_t& file)
{
    auto name = get_filename_without_ext(file);
    auto json_name = name + _X(".runtimeconfig.json");
    auto json_path = get_directory(file);

    append_path(&json_path, json_name.c_str());
    if (pal::file_exists(json_path))
    {
        return json_path;
    }
    return pal::string_t();
}
Exemplo n.º 3
0
Arquivo: libhost.cpp Projeto: krwq/cli
pal::string_t get_runtime_config_from_file(const pal::string_t& file, pal::string_t* dev_cfg)
{
    auto name = get_filename_without_ext(file);
    auto json_name = name + _X(".runtimeconfig.json");
    auto dev_json_name = name + _X(".runtimeconfig.dev.json");
    auto json_path = get_directory(file);
    auto dev_json_path = json_path;

    append_path(&json_path, json_name.c_str());
    append_path(&dev_json_path, dev_json_name.c_str());
    trace::verbose(_X("Runtime config is cfg=%s dev=%s"), json_path.c_str(), dev_json_path.c_str());

    dev_cfg->assign(dev_json_path);
    return json_path;
}
Exemplo n.º 4
0
/**
 *  Resovle the TPA assembly locations
 */
bool deps_resolver_t::resolve_tpa_list(
        pal::string_t* output,
        std::unordered_set<pal::string_t>* breadcrumb)
{
    const std::vector<deps_entry_t> empty(0);
    std::unordered_set<pal::string_t> items;

    auto process_entry = [&](const pal::string_t& deps_dir, deps_json_t* deps, const deps_entry_t& entry) -> bool
    {
        if (entry.is_serviceable)
        {
            breadcrumb->insert(entry.library_name + _X(",") + entry.library_version);
            breadcrumb->insert(entry.library_name);
        }
        if (items.count(entry.asset_name))
        {
            return true;
        }
        // Ignore placeholders
        if (ends_with(entry.relative_path, _X("/_._"), false))
        {
            return true;
        }

        pal::string_t candidate;

        trace::info(_X("Processing TPA for deps entry [%s, %s, %s]"), entry.library_name.c_str(), entry.library_version.c_str(), entry.relative_path.c_str());

        if (probe_deps_entry(entry, deps_dir, &candidate))
        {
            add_tpa_asset(entry.asset_name, candidate, &items, output);
            return true;
        }
        else
        {
            trace::error(_X("Error: assembly specified in the dependencies manifest was not found -- package: '%s', version: '%s', path: '%s'"), 
                entry.library_name.c_str(), entry.library_version.c_str(), entry.relative_path.c_str());
            return false;
        }
    };

    // First add managed assembly to the TPA.
    // TODO: Remove: the deps should contain the managed DLL.
    // Workaround for: csc.deps.json doesn't have the csc.dll
    pal::string_t managed_app_asset = get_filename_without_ext(m_managed_app);
    add_tpa_asset(managed_app_asset, m_managed_app, &items, output);

    const auto& deps_entries = m_deps->get_entries(deps_entry_t::asset_types::runtime);
    for (const auto& entry : deps_entries)
    {
        if (!process_entry(m_app_dir, m_deps.get(), entry))
        {
            return false;
        }
    }

    // Finally, if the deps file wasn't present or has missing entries, then
    // add the app local assemblies to the TPA.
    if (!m_deps->exists())
    {
        dir_assemblies_t local_assemblies;

        // Obtain the local assemblies in the app dir.
        get_dir_assemblies(m_app_dir, _X("local"), &local_assemblies);
        for (const auto& kv : local_assemblies)
        {
            add_tpa_asset(kv.first, kv.second, &items, output);
        }
    }

    // Probe FX deps entries after app assemblies are added.
    const auto& fx_entries = m_portable ? m_fx_deps->get_entries(deps_entry_t::asset_types::runtime) : empty;
    for (const auto& entry : fx_entries)
    {
        if (!process_entry(m_fx_dir, m_fx_deps.get(), entry))
        {
            return false;
        }
    }

    return true;
}
Exemplo n.º 5
0
/* main function */
int main_bismark (int argc, char *argv[]) {
    
    char *output, *outReportfile, *outCpGfile, *outbedGraphfile, *row[100], *samfilecopy;
    char *forwardcg, *forwardchg, *forwardchh, *forwardread, *forwardread1;
    char *reversecg, *reversechg, *reversechh, *reverseread, *reverseread1;
    unsigned long long int *cnt;
    unsigned long long int *cnt2 = NULL;
    int optSam = 0, c, optaddChr = 0, optStats = 0, optBis = 0, optFull = 0, optKeep = 0;
    unsigned int optisize = 500;
    int optcov = 5;
    char *optoutput = NULL;
    struct hash *cpgHash = newHash(0);
    struct hash *chgHash = newHash(0);
    struct hash *chhHash = newHash(0);
    time_t start_time, end_time;
    start_time = time(NULL);
    
    while ((c = getopt(argc, argv, "SCsbFBo:c:I:h?")) >= 0) {
        switch (c) {
            case 'S': optSam = 1; break;
            case 'C': optaddChr = 1; break;
            case 's': optStats = 1; break;
            case 'b': optBis = 1; break;
            case 'F': optFull = 1; break;
            case 'B': optKeep = 1; break;
            case 'c': optcov = (int)strtol(optarg, 0, 0); break;
            case 'I': optisize = (unsigned int)strtol(optarg, 0, 0); break;
            case 'o': optoutput = strdup(optarg); break;
            case 'h':
            case '?': return bismark_usage(); break;
            default: return 1;
        }
    }
    if (optind + 3 > argc)
        return bismark_usage();

    char *chr_size_file = argv[optind];
    char *cpg_bed_file = argv[optind+1];
    char *sam_file = argv[optind+2];

    fprintf(stderr, "* CpG file provided: %s\n", cpg_bed_file);
    fprintf(stderr, "* Insert size cutoff: %u\n", optisize);
    fprintf(stderr, "* Read coverage threshold: %i\n", optcov);
   
    struct hash *chrHash = hashNameIntFile(chr_size_file);
    
    samfilecopy = cloneString(sam_file);
    int numFields = chopByChar(samfilecopy, ',', row, ArraySize(row));
    fprintf(stderr, "* Provided %i BAM/SAM file(s)\n", numFields);


    if(optFull) {
        fprintf(stderr, "* Warning: will run in Full mode, 8 track files and 1 report file will be generated\n");
        fprintf(stderr, "* Warning: will output stats over each C (in CHG)\n");
        fprintf(stderr, "* Warning: will output stats over each C (in CHH)\n");
        optStats = 0;
        optBis = 1;
    }
    
    if(optStats) {
        fprintf(stderr, "* Warning: will report stats only as -s specified\n");
    }
    // if use select bismark like output, read cpgHash at each C stats
    if(optBis) {
        fprintf(stderr, "* Warning: will output stats over each C (in CpG)\n");
        cpgHash = cpgBed2BinKeeperHashBismark(chrHash, cpg_bed_file);
    }else{
        fprintf(stderr, "* Warning: will output stats over each CpG\n");
        cpgHash = cpgBed2BinKeeperHash(chrHash, cpg_bed_file);
    }

    if(optoutput) {
        output = optoutput;
    } else {
        output = cloneString(get_filename_without_ext(basename(row[0])));
    }
    

    if(asprintf(&outCpGfile, "%s.CpG.bedGraph", output) < 0)
        errAbort("Mem Error.\n");
    if(asprintf(&outbedGraphfile, "%s.density.bedGraph", output) < 0)
        errAbort("Mem Error.\n");
    if (asprintf(&outReportfile, "%s.report", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&forwardcg, "%s.forward.CG.bedGraph", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&forwardchg, "%s.forward.CHG.bedGraph", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&forwardchh, "%s.forward.CHH.bedGraph", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&forwardread, "%s.forward.Density.bed", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&forwardread1, "%s.forward.Density.bedGraph", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&reversecg, "%s.reverse.CG.bedGraph", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&reversechg, "%s.reverse.CHG.bedGraph", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&reversechh, "%s.reverse.CHH.bedGraph", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&reverseread, "%s.reverse.Density.bed", output) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&reverseread1, "%s.reverse.Density.bedGraph", output) < 0)
        errAbort("Preparing output wrong");
    

    //sam file to bed file
    //fprintf(stderr, "* Parsing the SAM/BAM file\n");
    cnt = bismarkBamParse(sam_file, chrHash, cpgHash, chgHash, chhHash, forwardread, reverseread, optSam, optaddChr, optFull, optisize);
    
    //write to file
    if (optFull){
        fprintf(stderr, "* Output CpG methylation calls\n");
        writecpgBismarkLite(cpgHash, forwardcg, reversecg, optcov);
        fprintf(stderr, "* Output CHG methylation calls\n");
        writecpgBismarkLiteHash(chgHash, forwardchg, reversechg, optcov);
        fprintf(stderr, "* Output CHH methylation calls\n");
        writecpgBismarkLiteHash(chhHash, forwardchh, reversechh, optcov);
        fprintf(stderr, "* Sorting methylation calls\n");
        sortBedfile(forwardcg);
        sortBedfile(reversecg);
        sortBedfile(forwardchg);
        sortBedfile(reversechg);
        sortBedfile(forwardchh);
        sortBedfile(reversechh);
        fprintf(stderr, "* Sorting density bed\n");
        sortBedfile(forwardread);
        sortBedfile(reverseread);
        fprintf(stderr, "* Generating density bedGraph\n");
        bedItemOverlapCount(chrHash, forwardread, forwardread1);
        bedItemOverlapCount(chrHash, reverseread, reverseread1);
    }else{
        cnt2 = writecpgBismark(cpgHash, outbedGraphfile, outCpGfile, optStats, optcov);
        //sort output
        if(!optStats) {
            fprintf(stderr, "* Sorting output density\n");
            sortBedfile(outbedGraphfile);
        }
        //sort output
        if(!optStats) {
            fprintf(stderr, "* Sorting output CpG methylation call\n");
            sortBedfile(outCpGfile);
        }
    }

    //generate bigWig
    //fprintf(stderr, "* Generating bigWig\n");
    //bigWigFileCreate(outbedGraphfile, chr_size_file, 256, 1024, 0, 1, outbigWigfile);
    //bedGraphToBigWig(outbedGraphfile, chr_size_file, outbigWigfile);
    
    //write report file
    fprintf(stderr, "* Preparing report file\n");
    writeReportBismark(outReportfile, cnt, cnt2, numFields, row, optBis, hashIntSum(chrHash));

    if(!optKeep){
        fprintf(stderr, "* Deleting (huge) density bed files\n");
        unlink(forwardread);
        unlink(reverseread);
    }
    
    //cleaning
    hashFree(&chrHash);
    hashFree(&cpgHash);
    hashFree(&chgHash);
    hashFree(&chhHash);
    free(outCpGfile);
    free(outbedGraphfile);
    //free(outbigWigfile);
    free(outReportfile);
    free(samfilecopy);
    free(forwardcg);
    free(forwardchg);
    free(forwardchh);
    free(forwardread);
    free(forwardread1);
    free(reversecg);
    free(reversechg);
    free(reversechh);
    free(reverseread);
    free(reverseread1);
    end_time = time(NULL);
    fprintf(stderr, "* Done, time used %.0f seconds.\n", difftime(end_time, start_time));
    return 0;
}
Exemplo n.º 6
0
void deps_json_t::reconcile_libraries_with_targets(
    const json_value& json,
    const std::function<bool(const pal::string_t&)>& library_exists_fn,
    const std::function<const std::vector<pal::string_t>&(const pal::string_t&, int, bool*)>& get_rel_paths_by_asset_type_fn)
{
    const auto& libraries = json.at(_X("libraries")).as_object();
    for (const auto& library : libraries)
    {
        trace::info(_X("Reconciling library %s"), library.first.c_str());

        if (pal::to_lower(library.second.at(_X("type")).as_string()) != _X("package"))
        {
            trace::info(_X("Library %s is not a package"), library.first.c_str());
            continue;
        }
        if (!library_exists_fn(library.first))
        {
            trace::info(_X("Library %s does not exist"), library.first.c_str());
            continue;
        }

        const auto& properties = library.second.as_object();

        const pal::string_t& hash = properties.at(_X("sha512")).as_string();
        bool serviceable = properties.at(_X("serviceable")).as_bool();

        for (int i = 0; i < deps_entry_t::s_known_asset_types.size(); ++i)
        {
            bool rid_specific = false;
            for (const auto& rel_path : get_rel_paths_by_asset_type_fn(library.first, i, &rid_specific))
            {
                bool ni_dll = false;
                auto asset_name = get_filename_without_ext(rel_path);
                if (ends_with(asset_name, _X(".ni"), false))
                {
                    ni_dll = true;
                    asset_name = strip_file_ext(asset_name);
                }

                deps_entry_t entry;
                size_t pos = library.first.find(_X("/"));
                entry.library_name = library.first.substr(0, pos);
                entry.library_version = library.first.substr(pos + 1);
                entry.library_type = _X("package");
                entry.library_hash = hash;
                entry.asset_name = asset_name;
                entry.asset_type = (deps_entry_t::asset_types) i;
                entry.relative_path = rel_path;
                entry.is_serviceable = serviceable;
                entry.is_rid_specific = rid_specific;

                // TODO: Deps file does not follow spec. It uses '\\', should use '/'
                replace_char(&entry.relative_path, _X('\\'), _X('/'));

                m_deps_entries[i].push_back(entry);

                if (ni_dll)
                {
                    m_ni_entries[entry.asset_name] = m_deps_entries
                        [deps_entry_t::asset_types::runtime].size() - 1;
                }

                trace::info(_X("Added %s %s deps entry [%d] [%s, %s, %s]"), deps_entry_t::s_known_asset_types[i], entry.asset_name.c_str(), m_deps_entries[i].size() - 1, entry.library_name.c_str(), entry.library_version.c_str(), entry.relative_path.c_str());
                
            }
        }
    }
}
Exemplo n.º 7
0
/**
 *  Resolve the TPA assembly locations
 */
bool deps_resolver_t::resolve_tpa_list(
        pal::string_t* output,
        std::unordered_set<pal::string_t>* breadcrumb,
        bool ignore_missing_assemblies)
{
    const std::vector<deps_entry_t> empty(0);
    name_to_resolved_asset_map_t items;

    auto process_entry = [&](const pal::string_t& deps_dir, const deps_entry_t& entry, int fx_level) -> bool
    {
        if (breadcrumb != nullptr && entry.is_serviceable)
        {
            breadcrumb->insert(entry.library_name + _X(",") + entry.library_version);
            breadcrumb->insert(entry.library_name);
        }

        // Ignore placeholders
        if (ends_with(entry.asset.relative_path, _X("/_._"), false))
        {
            return true;
        }

        trace::info(_X("Processing TPA for deps entry [%s, %s, %s]"), entry.library_name.c_str(), entry.library_version.c_str(), entry.asset.relative_path.c_str());

        pal::string_t resolved_path;

        name_to_resolved_asset_map_t::iterator existing = items.find(entry.asset.name);
        if (existing == items.end())
        {
            if (probe_deps_entry(entry, deps_dir, fx_level, &resolved_path))
            {
                deps_resolved_asset_t resolved_asset(entry.asset, resolved_path);
                add_tpa_asset(resolved_asset, &items);
                return true;
            }

            return report_missing_assembly_in_manifest(entry, ignore_missing_assemblies);
        }
        else
        {
            // Verify the extension is the same as the previous verified entry
            if (get_deps_filename(entry.asset.relative_path) != get_filename(existing->second.resolved_path))
            {
                trace::error(
                    DuplicateAssemblyWithDifferentExtensionMessage.c_str(),
                    entry.deps_file.c_str(),
                    entry.library_name.c_str(),
                    entry.library_version.c_str(),
                    entry.asset.relative_path.c_str(),
                    existing->second.resolved_path.c_str());

                return false;
            }

            deps_resolved_asset_t* existing_entry = &existing->second;

            // If deps entry is same or newer than existing, then see if it should be replaced
            if (entry.asset.assembly_version > existing_entry->asset.assembly_version ||
                (entry.asset.assembly_version == existing_entry->asset.assembly_version && entry.asset.file_version >= existing_entry->asset.file_version))
            {
                if (probe_deps_entry(entry, deps_dir, fx_level, &resolved_path))
                {
                    // If the path is the same, then no need to replace
                    if (resolved_path != existing_entry->resolved_path)
                    {
                        trace::verbose(_X("Replacing deps entry [%s, AssemblyVersion:%s, FileVersion:%s] with [%s, AssemblyVersion:%s, FileVersion:%s]"),
                            existing_entry->resolved_path.c_str(), existing_entry->asset.assembly_version.as_str().c_str(), existing_entry->asset.file_version.as_str().c_str(),
                            resolved_path.c_str(), entry.asset.assembly_version.as_str().c_str(), entry.asset.file_version.as_str().c_str());

                        existing_entry = nullptr;
                        items.erase(existing);

                        deps_asset_t asset(entry.asset.name, entry.asset.relative_path, entry.asset.assembly_version, entry.asset.file_version);
                        deps_resolved_asset_t resolved_asset(asset, resolved_path);
                        add_tpa_asset(resolved_asset, &items);
                    }
                }
                else if (fx_level != 0)
                {
                    // The framework is missing a newer package, so this is an error.
                    // For compat, it is not an error for the app; this can occur for the main application assembly when using --depsfile
                    // and the app assembly does not exist with the deps file.
                    return report_missing_assembly_in_manifest(entry);
                }
            }

            return true;
        }
    };

    // We do not support self-contained in a libhost scenario since in the self-contained scenario,
    // we cannot determine what assemblies are framework assemblies, and what assemblies are app-local assemblies.
    if (m_host_mode != host_mode_t::libhost)
    {
        // First add managed assembly to the TPA.
        // TODO: Remove: the deps should contain the managed DLL.
        // Workaround for: csc.deps.json doesn't have the csc.dll
        deps_asset_t asset(get_filename_without_ext(m_managed_app), get_filename(m_managed_app), version_t(), version_t());
        deps_resolved_asset_t resolved_asset(asset, m_managed_app);
        add_tpa_asset(resolved_asset, &items);

        // Add the app's entries
        const auto& deps_entries = get_deps().get_entries(deps_entry_t::asset_types::runtime);
        for (const auto& entry : deps_entries)
        {
            if (!process_entry(m_app_dir, entry, 0))
            {
                return false;
            }
        }

        // If the deps file wasn't present or has missing entries, then
        // add the app local assemblies to the TPA. This is only valid
        // in non-libhost scenarios (e.g. comhost).
        if (!get_deps().exists())
        {
            // Obtain the local assemblies in the app dir.
            get_dir_assemblies(m_app_dir, _X("local"), &items);
        }
    }

    // There should be no additional deps files in a libhost scenario.
    // See comments during additional deps.json resolution.
    assert(m_additional_deps.empty() || m_host_mode != host_mode_t::libhost);

    // If additional deps files were specified that need to be treated as part of the
    // application, then add them to the mix as well.
    for (const auto& additional_deps : m_additional_deps)
    {
        auto additional_deps_entries = additional_deps->get_entries(deps_entry_t::asset_types::runtime);
        for (auto entry : additional_deps_entries)
        {
            if (!process_entry(m_app_dir, entry, 0))
            {
                return false;
            }
        }
    }

    // Probe FX deps entries after app assemblies are added.
    for (int i = 1; i < m_fx_definitions.size(); ++i)
    {
        const auto& deps_entries = m_is_framework_dependent ? m_fx_definitions[i]->get_deps().get_entries(deps_entry_t::asset_types::runtime) : empty;
        for (const auto& entry : deps_entries)
        {
            if (!process_entry(m_fx_definitions[i]->get_dir(), entry, i))
            {
                return false;
            }
        }
    }

    // Convert the paths into a string and return it 
    for (const auto& item : items)
    {
        // Workaround for CoreFX not being able to resolve sym links.
        pal::string_t real_asset_path = item.second.resolved_path;
        pal::realpath(&real_asset_path);
        output->append(real_asset_path);
        output->push_back(PATH_SEPARATOR);
    }

    return true;
}
Exemplo n.º 8
0
/* main filter function */
int main_filter(int argc, char *argv[]){
    char *output, *subfam, *out, *outReport;
    unsigned long long int *cnt;
    struct hash *hashRmsk = newHash(0);
    struct hash *hashRep = newHash(0);
    struct hash *hashFam = newHash(0);
    struct hash *hashCla = newHash(0);
    int optSam = 0, optthreshold = 1;
    char *optoutput = NULL, *optname = NULL, *optclass = NULL, *optfamily = NULL;
    unsigned int optreadlist = 0, optQual = 10, optisize = 500, optExt = 150;
    int filterField = 0, c, optDup = 0, optNorm = 0, optaddChr = 0, optDis =0, optTreat = 0;
    float optCov = 0.0001;

    time_t start_time, end_time;
    start_time = time(NULL);
    
    while ((c = getopt(argc, argv, "SQ:g:N:n:c:t:f:rRTDCE:I:o:h?")) >= 0) {
        switch (c) {
            case 'S': optSam = 1; break;
            case 'Q': optQual = (unsigned int)strtol(optarg, 0, 0); break;
            case 'g': optCov = atof(optarg); break;
            case 'N': optNorm = (unsigned int)strtol(optarg, 0, 0); break;
            case 't': optthreshold = (unsigned int)strtol(optarg, 0, 0); break;
            case 'r': optreadlist = 1; break;
            case 'R': optDup = 1; break;
            case 'T': optTreat = 1; break;
            case 'D': optDis = 1; break;
            case 'C': optaddChr = 1; break;
            case 'n': optname = strdup(optarg); break;
            case 'c': optclass = strdup(optarg); break;
            case 'f': optfamily = strdup(optarg); break;
            case 'E': optExt = (unsigned int)strtol(optarg, 0, 0); break;
            case 'I': optisize = (unsigned int)strtol(optarg, 0, 0); break;
            case 'o': optoutput = strdup(optarg); break;
            case 'h':
            case '?': return filter_usage(); break;
            default: return 1;
        }
    }
    if (optind + 4 > argc)
        return filter_usage();

    char *chr_size_file = argv[optind];
    char *rep_size_file = argv[optind+1];
    char *rmsk_file = argv[optind+2];
    char *sam_file = argv[optind+3];
    
    if ( (optname && optclass) || (optname && optfamily) || (optclass && optfamily) || (optname && optclass && optfamily))
        errAbort("Please specify only one filter, either -n, -c or -f.");
    
    int nindex = 0;
    if (optNorm == 0){
        nindex = 7;
    } else if (optNorm == 1){
        nindex = 8;
    } else if (optNorm == 2) {
        nindex = 6;    
    } else if (optNorm == 3) {
        nindex = 4;    
    } else{
        errAbort("Wrong normalization method specified");
    }
    
    subfam = cloneString("ALL");
    if (optname) {
        optclass = NULL;
        optfamily = NULL;
        subfam = cloneString(optname);
        filterField = 10;
    }else if (optclass) {
        optname = NULL;
        optfamily = NULL;
        subfam = cloneString(optclass);
        filterField = 11;
    } else if (optfamily) {
        optname = NULL;
        optclass= NULL;
        subfam = cloneString(optfamily);
        filterField = 12;
    }
    if (sameString(subfam, "ALL")){
        fprintf(stderr, "* You didn't specify any filter, will output all repeats\n");
        filterField = 0;
    }
    
    if(optoutput) {
        output = optoutput;
    } else {
        output = cloneString(get_filename_without_ext(basename(sam_file)));
    }
    
    struct hash *chrHash = hashNameIntFile(chr_size_file);
    struct hash *repHash = hashNameIntFile(rep_size_file);
    
    fprintf(stderr, "* Start to parse the rmsk file\n");
    rmsk2binKeeperHash(rmsk_file, chrHash, repHash, &hashRmsk, &hashRep, &hashFam, &hashCla, filterField, subfam);
    
    //sam file
    fprintf(stderr, "* Start to parse the SAM/BAM file\n");
    //if (optPair){
    //    cnt = PEsamFile2nodupRepbedFile(sam_file, chrHash, hashRmsk, hashRep, hashFam, hashCla, optSam, optQual, 1, optDup, optaddChr, optisize);
    //} else {
    //    cnt = samFile2nodupRepbedFile(sam_file, chrHash, hashRmsk, hashRep, hashFam, hashCla, optSam, optQual, 1, optDup, optaddChr);
    //}
    cnt = samFile2nodupRepbedFileNew(sam_file, chrHash, hashRmsk, hashRep, hashFam, hashCla, optSam, optQual, 1, optDup, optaddChr, optDis, optisize, optExt, optCov, optTreat, NULL, NULL, 0);


    fprintf(stderr, "* Preparing the output file\n");
    if (asprintf(&out, "%s_%s.iteres.loci", output, subfam) < 0)
        errAbort("Preparing output wrong");
    if (asprintf(&outReport, "%s_%s.iteres.reportloci", output, subfam) < 0)
        errAbort("Preparing output wrong");
    
    writeFilterOut(hashRmsk, out, optreadlist, optthreshold, subfam, cnt[nindex]); 
    
    //write report file
    fprintf(stderr, "* Preparing report file\n");
    writeReport(outReport, cnt, optQual, subfam);
    
    hashFree(&chrHash);
    hashFree(&repHash);
    hashFree(&hashRmsk);
    hashFree(&hashRep);
    hashFree(&hashFam);
    hashFree(&hashCla);
    free(out);
    free(outReport);
    
    end_time = time(NULL);
    fprintf(stderr, "* Done, time used %.0f seconds.\n", difftime(end_time, start_time));
    return 0;    
}