title: Bio Perl: code to split paired end data?
body: <p>I am a beginner with bioinformatics and I have been working on a little Bio Perl code to split my paired end MiSeq data (currently in 1 fastq file) into 2 files, each file containing one end of the pair. The different ends of the paired end reads can be distinguished by a <strong>1</strong> or a <strong>2</strong> after the space in the fastq header. The file follows a typical fastq format, example from using "head" in the command line:</p>
  
  <pre><code>@M00763:6:000000000-A1U80:1:1101:12620:1732 1:N:0:1
  TTATACTC
  +
  @A@AA@A@
  @M00763:6:000000000-A1U80:1:1101:12620:1732 2:N:0:1
  T
  +
  E
  </code></pre>
  
  <p>I have written a code trying to target the 1 or 2 in the header using a match. Although I am using Bio::SeqIO perl does not seem to be recognizing the fastq format, and I keep getting this error: </p>
  
  <pre><code>MSG: Could not guess format from file/fh
  STACK: Error::throw
  STACK: Bio::Root::Root::throw /sw/lib/perl5/5.12.3/Bio/Root/Root.pm:472
  STACK: Bio::SeqIO::new /sw/lib/perl5/5.12.3/Bio/SeqIO.pm:389
  STACK: SplitPairedEndReads.pl:7
  </code></pre>
  
  <p>Can someone help me find/fix my error? The information available from BioPerl website indicates that Bio::SeqIO should be able to recognize fastq format. </p>
  
  <p>Here is the code I have written: </p>
  
  <pre><code>#!/usr/bin/perl 
  
  use Bio::SeqIO;
  use Bio::SeqIO::fastq;
  
  
  $seqout1 = Bio::SeqIO-&gt;new(-file =&gt; "&gt;peread1.fastq" -format =&gt; "fastq",);
  $seqout2 = Bio::SeqIO-&gt;new(-file =&gt; "&gt;peread2.fastq" -format =&gt; "fastq",);
  
  $seqio_obj = Bio::SeqIO-&gt;new(-file =&gt; "AIS351_Strin1edit.fastq", -format =&gt; "fastq",
                           -alphabet =&gt; "dna" );
  $seq_obj = $seqio_obj-&gt;next_seq;
  
  while ($seq_obj = $seqio_obj-&gt;next_seq) { 
      $name = $seq_obj-&gt;desc; if($name=~ / 1:/) {$seqout1-&gt;write_seq($seq_obj);
       } else { $seqout2-&gt;write_seq($seq_obj); 
  
      }
  }
  </code></pre>
  
  <p>Thanks for your help and your patience with my beginner knowledge. </p>
  
  <p>~Al</p>
  
  <p>Question update: </p>
  
  <p>I have fixed the comma error in my <code>new</code> line and now I am getting this error when I run the code:</p>
  
  <pre><code>------------- EXCEPTION: Bio::Root::Exception -------------
  MSG: No description line parsed
  STACK: Error::throw
  STACK: Bio::Root::Root::throw /sw/lib/perl5/5.12.3/Bio/Root/Root.pm:472
  STACK: Bio::SeqIO::fastq::next_dataset /sw/lib/perl5/5.12.3/Bio/SeqIO/fastq.pm:71
  STACK: Bio::SeqIO::fastq::next_seq /sw/lib/perl5/5.12.3/Bio/SeqIO/fastq.pm:29
  STACK: samplesettrim.pl:10
  -----------------------------------------------------------
  </code></pre>
  
  <p>All of the reading I have done seems to indicate there are some problems with the FASTQ parser in BioPerl itself. I had hoped to get this code to work because I am a beginner and trying to improve my programming skills (I'm entirely self taught), and this is a problem where programming has a practical application for me. I agree with the comment about this being slow and probably not the best approach for working with a large FASTQ file.  </p>
  
  <p>In regards to the + descriptor, is that necessary for my file to be usable in other software programs (Ex: CLC) or could I fix the problem by removing that line in the FASTQ? The + doesn't actually contain any quality information for the read, correct? </p>
  
  <p>Thanks again for the input! </p>