Merge pull request #5163 from solgenomics/audit-error-checking
[sgn.git] / lib / CXGN / GenotypeIO.pm
blob2fd63dbc182978df5fea24ba56a4ff1f482447d9
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 observation_unit_names {
75 my $self = shift;
76 return $self->plugin()->observation_unit_names();
79 sub header_information_lines {
80 my $self = shift;
81 return $self->plugin()->header_information_lines();
84 sub markers {
85 my $self = shift;
86 #print STDERR "Markers now: ".Dumper($self->plugin()->markers())."\n";
87 return $self->plugin()->markers();
90 sub header {
91 my $self = shift;
92 #print STDERR "Markers now: ".Dumper($self->plugin()->markers())."\n";
93 return $self->plugin()->header();
96 sub close {
97 my $self = shift;
98 $self->plugin()->close();
101 sub summary_stats {
102 my $self = shift;
104 my $file = $self->plugin()->file();
105 my $stats = $self->plugin()->summary_stats($file);
106 return $stats;