Skip to content

Commit

Permalink
tidied view.*
Browse files Browse the repository at this point in the history
  • Loading branch information
atks committed Dec 3, 2013
1 parent ca00931 commit dfefbcb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 75 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SOURCES = program\
log_tool\
interval_tree\
genome_interval\
filter\
rb_tree\
lhmm\
hts_utils\
Expand All @@ -19,13 +20,12 @@ SOURCES = program\
bcf_ordered_reader\
bcf_ordered_writer\
bcf_synced_reader\
merge_duplicate_variants\
view\
normalize\
merge_duplicate_variants\
construct_probes\
discover\
genotype\
view\
filter\
profile_indels\
partition\
peek
Expand Down
16 changes: 8 additions & 8 deletions discover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#include "discover.h"

namespace
{

typedef struct
{
int32_t start1, end1;
Expand All @@ -34,6 +37,7 @@ KHASH_MAP_INIT_STR(rdict, interval_t)
#define MNP 2
#define INDEL 4


/**
* Class for mining candidate variants.
*
Expand Down Expand Up @@ -715,9 +719,6 @@ class VariantHunter
};
};

namespace
{

class Igor : Program
{
public:
Expand All @@ -737,7 +738,7 @@ class Igor : Program
uint32_t evidence_allele_count_cutoff;
double fractional_evidence_allele_count_cutoff;

uint16_t excludeFlag;
uint16_t exclude_flag;

///////
//i/o//
Expand Down Expand Up @@ -792,7 +793,6 @@ class Igor : Program
input_bam_file = arg_input_bam_file.getValue();
parse_intervals(intervals, arg_interval_list.getValue(), arg_intervals.getValue());
output_vcf_file = arg_output_vcf_file.getValue();

sample_id = arg_sample_id.getValue();
ref_fasta_file = arg_ref_fasta_file.getValue();
mapq_cutoff = arg_mapq_cutoff.getValue();
Expand All @@ -814,7 +814,7 @@ class Igor : Program
//////////////////////
//i/o initialization//
//////////////////////
excludeFlag = 0x0704;
exclude_flag = 0x0704;

odr = new BAMOrderedReader(input_bam_file, intervals);
s = bam_init1();
Expand Down Expand Up @@ -918,7 +918,7 @@ class Igor : Program
}

uint16_t flag = bam_get_flag(s);
if(flag & excludeFlag)
if(flag & exclude_flag)
{
++no_exclude_flag_reads;
//1. unmapped
Expand Down Expand Up @@ -950,7 +950,7 @@ class Igor : Program
++no_passed_reads;
}

odw->close();
odw->close();

};

Expand Down
5 changes: 0 additions & 5 deletions discover.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
#ifndef DISCOVER_H
#define DISCOVER_H

#include <cmath>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include "htslib/vcf.h"
Expand Down
105 changes: 53 additions & 52 deletions view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ class Igor : Program
BCFOrderedReader *odr;
BCFOrderedWriter *odw;

int* imap;
kstring_t s;

/////////
//stats//
/////////
uint32_t no_variants;
uint32_t no_samples;
uint32_t no_samples;

Igor(int argc, char **argv)
{
Expand All @@ -62,59 +59,51 @@ class Igor : Program
//////////////////////////
//options initialization//
//////////////////////////
try
{
std::string desc = "views a VCF file";
try
{
std::string desc = "views a VCF file";

TCLAP::CmdLine cmd(desc, ' ', version);
VTOutput my;
cmd.setOutput(&my);
TCLAP::ValueArg<std::string> arg_intervals("i", "i", "intervals []", false, "", "str", cmd);
TCLAP::ValueArg<std::string> arg_interval_list("I", "I", "file containing list of intervals []", false, "", "file", cmd);
TCLAP::ValueArg<std::string> arg_sample_list("s", "s", "file containing list of sample []", false, "", "file", cmd);
TCLAP::ValueArg<std::string> arg_filter("f", "f", "filter expression []", false, "", "exp", cmd);
TCLAP::ValueArg<std::string> arg_variant("v", "v", "variant type []", false, "", "exp", cmd);
TCLAP::ValueArg<std::string> arg_output_vcf_file("o", "o", "output VCF file [-]", false, "-", "str", cmd);
TCLAP::UnlabeledValueArg<std::string> arg_input_vcf_file("<in.vcf>", "input VCF file", true, "","file", cmd);
TCLAP::ValueArg<std::string> arg_intervals("i", "i", "intervals []", false, "", "str", cmd);
TCLAP::ValueArg<std::string> arg_interval_list("I", "I", "file containing list of intervals []", false, "", "file", cmd);
TCLAP::ValueArg<std::string> arg_sample_list("s", "s", "file containing list of sample []", false, "", "file", cmd);
TCLAP::ValueArg<std::string> arg_filter("f", "f", "filter expression []", false, "", "exp", cmd);
TCLAP::ValueArg<std::string> arg_variant("v", "v", "variant type []", false, "", "exp", cmd);
TCLAP::ValueArg<std::string> arg_output_vcf_file("o", "o", "output VCF file [-]", false, "-", "str", cmd);
TCLAP::UnlabeledValueArg<std::string> arg_input_vcf_file("<in.vcf>", "input VCF file", true, "","file", cmd);

cmd.parse(argc, argv);
cmd.parse(argc, argv);

input_vcf_file = arg_input_vcf_file.getValue();
output_vcf_file = arg_output_vcf_file.getValue();
parse_intervals(intervals, arg_interval_list.getValue(), arg_intervals.getValue());
read_sample_list(samples, arg_sample_list.getValue());
}
catch (TCLAP::ArgException &e)
{
std::cerr << "error: " << e.error() << " for arg " << e.argId() << "\n";
abort();
}
output_vcf_file = arg_output_vcf_file.getValue();
parse_intervals(intervals, arg_interval_list.getValue(), arg_intervals.getValue());
read_sample_list(samples, arg_sample_list.getValue());
}
catch (TCLAP::ArgException &e)
{
std::cerr << "error: " << e.error() << " for arg " << e.argId() << "\n";
abort();
}
};

void initialize()
{
//////////////////////
//////////////////////
//i/o initialization//
//////////////////////
odr = new BCFOrderedReader(input_vcf_file, intervals);
odw = new BCFOrderedWriter(output_vcf_file);
odw->set_hdr(odr->hdr);
bcf_hdr_fmt_text(odr->hdr);

//std::vector<int32_t> imap(samples.size(), -1);
//bcf_hdr_t * h = bcf_hdr_subset_samples(odr->hdr, samples, imap);
odw = new BCFOrderedWriter(output_vcf_file, 0);
odw->set_hdr(odr->hdr);
odw->write_hdr();

s.s = 0;
s.l = s.m = 0;

////////////////////////
//stats initialization//
////////////////////////
no_variants = 0;
no_samples = 0;
}
no_samples = 0;
}

void view()
{
Expand All @@ -125,38 +114,50 @@ class Igor : Program
bcf_unpack(v, BCF_UN_INFO);
bcf_get_pos1(v);
//bcf_set_variant_types(v);

//filter

//subset if necessary
//int bcf_subset(const bcf_hdr_t *h, bcf1_t *v, int n, int *imap)
//int bcf_subset(const bcf_hdr_t *h, bcf1_t *v, int n, int *imap)


odw->write(v);
v = odw->get_bcf1_from_pool();
}

odw->flush();
odw->close();
};

void print_options()
{
std::clog << "view v" << version << "\n\n";

std::clog << "options: input VCF file " << input_vcf_file << "\n";
std::clog << " [o] output VCF file " << output_vcf_file << "\n";
std::clog << " [i] intervals " << intervals.size() << " intervals" << "\n";
std::clog << "\n";
}
std::clog << "options: input VCF file " << input_vcf_file << "\n";
std::clog << " [o] output VCF file " << output_vcf_file << "\n";
if (intervals.size()!=0)
{
std::clog << " [i] intervals ";
for (uint32_t i=0; i<std::min((uint32_t)intervals.size(),(uint32_t)5); ++i)
{
if (i) std::clog << ", ";
std::clog << intervals[i].to_string();
}
if (intervals.size()>=5)
{
std::clog << " and " << (intervals.size()-5) << " other intervals\n";
}
}
std::clog << "\n";
}

void print_stats()
{
std::clog << "stats: no. variants : " << no_variants << "\n";
std::clog << " no. samples : " << no_samples << "\n";
std::clog << "\n";
std::clog << "stats: no. variants : " << no_variants << "\n";
std::clog << " no. samples : " << no_samples << "\n";
std::clog << "\n";
};
~Igor() {};

~Igor() {};

private:
};
Expand Down
10 changes: 3 additions & 7 deletions view.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@
#ifndef VIEW_H
#define VIEW_H

#include "tclap/CmdLine.h"
#include "tclap/Arg.h"
#include "htslib/vcf.h"
#include "htslib/kseq.h"
#include "hts_utils.h"
#include "bcf_synced_reader.h"
#include "program.h"
#include "bcf_ordered_reader.h"
#include "bcf_ordered_writer.h"
#include "hts_utils.h"
#include "variant_manip.h"
#include "program.h"

void view(int argc, char ** argv);

#endif
#endif

0 comments on commit dfefbcb

Please sign in to comment.