Commits

Edward Kirton  committed 55ff85c

fix molecular barcode autodiscovery

  • Participants
  • Parent commits 514eb4d

Comments (0)

Files changed (1)

File lib/iTagger/FastqDb.pm

 		$buffer[$i]->convert_qual_to_sanger if $convert_qual;
 		$buffer[$i]->qc($this->{qc_params});
 	}
-	$this->_init_barcodes;
+	$this->_init_barcodes(\@buffer);
 
 	# COUNT NUMBER OF GOOD READS IN BUFFER AND DETERMINE LENGTH DISTRIBUTION
 	my @read_lengths = ();
         } else
         {
             $this->{counter}->{pass} += 2;
+            if ( defined($this->{barcodes}) and $rec1->barcode )
+            {
+                if ( $rec1->barcode ne $rec2->barcode )
+                {
+                    if ( exists($this->{barcodes}->{$rec1->barcode}) )
+                    {
+                        $rec2->barcode($rec1->barcode);
+                    } elsif ( exists($this->{barcodes}->{$rec2->barcode}) )
+                    {
+                        $rec1->barcode($rec2->barcode);
+                    } else
+                    {
+                        # neither barcode good, let's at least make them the same
+                        $rec2->barcode($rec1->barcode);
+                    }
+                }
+                $this->{barcodes}->{$rec1->barcode} += 1;
+            }
         }
     } until ( $rec1 and $rec2 );
 	return [ $rec1, $rec2  ];
 {
 	my ($this, $buffer) = @_;
 	return unless $this->{qc_params}->{learn_barcodes} or (exists($this->{qc_params}->{barcodes_file}) and defined($this->{qc_params}->{barcodes_file}));
-	if ($this->{qc_params}->{learn_barcodes}) { $this->_learn_barcodes }
+	if ($this->{qc_params}->{learn_barcodes}) { $this->_learn_barcodes($buffer) }
 	else { $this->_load_barcodes }
 	# PROCESS BUFFERED SEQS
     for ( my $i=0; $i<=$#$buffer; $i++ )