Merge branch 'master' into topic/analyze_phenotypes_page
[sgn.git] / lib / CXGN / GenotypeIO.pm
blob5d4013915b28cfd9316e37ca6777e5832126f452
2 package CXGN::GenotypeIO;
4 use Moose;
5 use JSON::Any;
6 use Data::Dumper;
7 use CXGN::Genotype;
9 use CXGN::GenotypeIOmain;
11 has 'format' => ( isa => 'Str',
12 is => 'rw',
13 default => 'vcf', # or dosage
16 has 'plugin' => ( isa => 'Ref',
17 is => 'rw',
22 sub BUILD {
23 my $self = shift;
24 my $args = shift;
26 my $plugin = CXGN::GenotypeIOmain->new();
28 if ($args->{format} eq "vcf") {
29 $plugin->load_plugin("VCF");
31 elsif ($args->{format} eq "dosage") {
32 $plugin->load_plugin("Dosage");
34 elsif ($args->{format} eq "dosage_transposed") {
35 $plugin->load_plugin("DosageTransposed");
37 else {
38 print STDERR "No valid format provided. Using vcf.\n";
39 $plugin->load_plugin("VCF");
41 $plugin->file($args->{file});
43 my $data = $plugin->init($args);
45 $self->plugin($plugin);
47 #print STDERR "count = $data->{count}\n";
48 #$self->count($data->{count});
49 #$self->header($data->{header});
50 #$self->current(0);
53 sub next {
54 my $self =shift;
56 my ($markers, $rawscores, $accession_name) = $self->plugin()->next();
57 if (keys(%$rawscores)==0) { return undef; }
58 my $gt = CXGN::Genotype->new();
59 $gt->name($accession_name);
60 $gt->rawscores($rawscores);
61 $gt->markers($self->markers());
63 # print STDERR "NAME: $genotype\n";
64 # print STDERR join ", ", keys %$rawscores;
66 return $gt;
69 sub accessions {
70 my $self = shift;
71 return $self->plugin()->accessions();
74 sub markers {
75 my $self = shift;
76 #print STDERR "Markers now: ".Dumper($self->plugin()->markers())."\n";
77 return $self->plugin()->markers();
80 sub close {
81 my $self = shift;
82 $self->plugin()->close();
85 sub summary_stats {
86 my $self = shift;
88 my $file = $self->plugin()->file();
89 my $stats = $self->plugin()->summary_stats($file);
90 return $stats;