18 use CXGN
::Genotype
::SNP
;
20 has
'file' => ( isa
=> 'Str',
25 has
'fh' => (isa
=> 'FileHandle',
29 has
'header' => ( isa
=> 'Str',
33 has
'accessions' => ( isa
=> 'ArrayRef',
37 has
'ignore_accessions' => (isa
=> 'HashRef',
41 has
'valid_accessions' => (isa
=> 'ArrayRef',
45 has
'filter' => ( isa
=> 'Str',
55 my $fh = IO
::File
->new($args->{file
});
66 #print STDERR "found header $_\n";
68 # CHROM POS ID REF ALT QUAL FILTER INFO FORMAT SNPS..
69 my @fields = split /\s+/, $_;
71 my @accessions = @fields[9..$#fields];
72 $self->accessions(\
@accessions);
73 print STDERR
"ACCESSIONS: ".join("|", @accessions)."\n";
90 if (! $self->header() ) {
91 die "Header not seen. This file may have format problems.\n";
99 my $line = $self->next_line();
101 if (defined($line)) {
103 my ($chr, $position, $snp_id, $ref_allele, $alt_allele, $qual, $filter, $info, $format, @snps) = split /\t/, $line;
104 #print STDERR "Processing $snp_id\n";
105 my $snps = CXGN
::SNPs
->new( );
109 $snps->position($position);
110 $snps->ref_allele($ref_allele);
111 $snps->alt_allele($alt_allele);
113 $snps->filter($filter);
115 $depth =~ s/DP=(\d+)/$1/i;
116 if ($depth eq ".") { $depth=0; }
117 $snps->depth($depth);
119 $snps->format($format);
120 $snps->accessions($self->accessions());
121 $snps->valid_accessions($self->accessions());
122 #print STDERR "ACCESSIONS: ".(join ",", @{$self->{accessions}})."\n";
123 my %snp_objects = ();
124 for(my $n=0; $n<@snps; $n++) {
125 my $snp = CXGN
::Genotype
::SNP
->new( { id
=>$snp_id, format
=> $format, vcf_string
=> $snps[$n] } );
127 my $accession = $self->accessions()->[$n]."\n";
129 #print "ACCESSION: $accession\n";
130 #if ($accession =~ m/1002:250060174/) { print STDERR "Saw accession 1002:250060174" }
131 $snp->accession($accession);
132 $snp_objects{$accession} = $snp;
134 #print STDERR Dumper(\%snp_objects);
135 $snps->snps(\
%snp_objects);
139 #print STDERR "LINE NOT DEFINED.\n";
149 sub total_accessions
{
151 return scalar(@
{$self->accessions});
155 __PACKAGE__
->meta->make_immutable;