Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nposnien
    Member
    • May 2011
    • 13

    #1

    Sort and Split shuffled (interleaved) fastq file

    Hi all,

    I have a huge fastq file that contains paired reads (after trimming and quality filtering). The reads are shuffled cause they have been used for de-novo assembly with velvet/oases:

    @HTKZQN1:329:C09BUACXX:6:1101:1442:2235 2:N:0:
    TTTTGATTTCTACATTTCATCACTTTTCAGATAATACGATTTTTGAAGATTTTTTCAATGTTATTCGGGAATTATATTCCAA
    +
    +==A;B?DHHH>4+2CG:<IIA:AC>>C4ACHFEH<EF)CFHF*?1?*: DFG90@;=BCHGI4BFD824'-=EAE;.??;CC

    @HTKZQN1:329:C09BUACXX:6:1101:1575:2055 1:N:0:
    ATAATTTTGGGTGTTAATACAACAAGGAATCATGCTTTCATATTTGAAAAAATATAGATTAATTATAAAAAATACATTTAATTTGATATTAATGTATAAAA
    +
    @C@DFDFFHHFACFEHIIIHHIIIJIIJGGHIJJJJJJIIJJJJIIEHCBDFGGEGEIICGCCHGIEDHIHEB:??CBEE;AEEC@A>CCDDDCDADD@D>

    @HTKZQN1:329:C09BUACXX:6:1101:1735:2058 1:N:0:
    GTGAAGTATAGTAGTTCCATAGGGAATATAGTTAACAAAACACATAAAATCTATAAACTTCAATTTTTCTAGAGCAATAATGTCCCCTTGCAAAAATAAGT
    +
    @CCFFFFFHHHHHJJJJJHIIJJJGIJJJJJGIIJIJJJJIJJIJJJIJJJJJIIHIJIIJJGIJJJIJJIGHHIHIICHIGHIHHHFFFFFFF@AECEC3

    @HTKZQN1:329:C09BUACXX:6:1101:1701:2060 2:N:0:
    CTTTGCCATTTAATTCATAAACTGCATCATCAGCATCCCTGTAGTCATCAAATTCCACAAATCCAAAACCATTTTTAATAAGAATCTCTCGTATTTTCCCA
    +
    CCCFFFFFHGHHHJJJIJJIJJJJFHGJJJJJJJJJGIJJIJJJIIJIJJHIJJJJIIHIJJJJJJJJJCEHIJJJJJJJGHHHHHFFFFFCDEEEEEDDD
    Now I would like to reuse that file for mapping with Bowtie. The problem is that I would need the pairs in individual files. I tried several solutions like this or this script:

    Code:
    #!/usr/local/bin/perl -w
    # Daniel Brami
    # Util to split interlaced FASTQ files into pairs
     
    use strict;
     
    # Standard lib
    use IO::File;
    use File::Basename;
     
    my $INPUT=shift;
     
    if (!(defined ($INPUT)) || ($INPUT =~ '^\-')){
    die "Usage: $0 <interleaved paired FASTQ file>\n";
    }
     
    my ($name,$path,$suffix) = fileparse($INPUT, qw/fastq FASTQ txt TXT/);
     
    my $FH_IN = new IO::File($INPUT, "r") or die "could not open $INPUT: $!\n";
    my $FH_OUT1 = new IO::File($name."split1.$suffix", "w") or die "could not open $name.split1$suffix for writing: $!\n";
    my $FH_OUT2 = new IO::File($name."split2.$suffix", "w") or die "could not open $name.split2$suffix for writing: $!\n";
     
    my ($recs1, $recs2)= (0,0);
    my $flipflop = 1;
    my $counter = 0;
    my ($line, $TXT);
    while($line = $FH_IN->getline()){
    $TXT .= $line;
    $counter++;
    if($counter == 4){
     if($flipflop == 1){
      print $FH_OUT1 $TXT;
      ++$recs1;
     }else{
      print $FH_OUT2 $TXT;     
      ++$recs2;
     }
     $counter = 0;
     $TXT = '';
     $flipflop *= -1;
    }
    }
    $FH_IN->close();
    $FH_OUT1->close();
    $FH_OUT2->close();
     
    print STDERR "Processed $recs1 records for pair file 1 and $recs2 records for pair file 2.\n";
    if($recs1 != $recs2){
    print STDERR "The number of processed records does not match - check input data!";
    }exit;
    Problem is that those solutions seem to assume that the pairs are consecutive. Thus, I would need to sort the reads first to provide consecutive pairs and afterwards apply one of the above solutions to split the files.

    My question is now: How can I sort the fastq file?
    I would appreciate any hint!

    Thanks.
  • maubp
    Peter (Biopython etc)
    • Jul 2009
    • 1544

    #2
    There are many FASTQ de-interlacing scripts out there, and yes, most do assume sorting so that pairs are next to each other. But not all make this assumption - at the expense of needing to build an index or some similar technique.

    Don't you have the filtered and trimmed FASTQ files from before running Velvet?

    Comment

    • nposnien
      Member
      • May 2011
      • 13

      #3
      Thanks a lot for your reply!
      @Peter: Do you have a script in mind that would work with building an index? I would give it a try cause a collaborator did all the shuffling steps and the files are lost.
      Thanks a lot!

      Comment

      • maubp
        Peter (Biopython etc)
        • Jul 2009
        • 1544

        #4
        How many reads in this file? And how much RAM do you have? Some indexing is in-memory, but that may not be practical with your dataset and require a disk based index.

        Comment

        • nposnien
          Member
          • May 2011
          • 13

          #5
          33 Mio reads in the file and I have (locally) 16 GB RAM. This should work with a memory based approach. However, I will need to do this with other datasets (up to 170 Mio reads). Thus, a disc based method would be better I guess.

          Comment

          Latest Articles

          Collapse

          • SEQadmin2
            Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
            by SEQadmin2



            Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

            Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
            ...
            10-14-2026, 09:55 AM
          • SEQadmin2
            New Genomics Technologies Take Aim at Long-Standing Limits
            by SEQadmin2


            Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

            We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
            ...
            09-28-2026, 10:25 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by SEQadmin2, Yesterday, 11:13 AM
          0 responses
          17 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, Yesterday, 10:48 AM
          0 responses
          18 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-15-2026, 10:52 AM
          0 responses
          36 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-14-2026, 05:39 AM
          0 responses
          42 views
          0 reactions
          Last Post SEQadmin2  
          Working...