Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akjones
    Member
    • Jun 2013
    • 24

    #1

    Code to split paired end MiSeq data?

    Hello all,

    I have some paired end MiSeq data that I have cleaned/trimmed. However the software I used to clean everything up requires that the paired end data files be concatenated into one fastq with all reads and their respective mates, and now I need to split them back into two fastq's each containing one read from a paired end set (R1 and R2).

    My fastq file with all paired end reads follows a typical fastq format, example from "head" of original fastq file:

    @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

    Where the bolded "1" or "2" indicate which member of the pair the read is, so I am trying to get all 1's into a separate file and all 2's into a separate file. I have a bit of perl code that a lab mate passed along to me that is supposed to split the reads in this way, and it runs and creates two separate files, but it is not splitting the data correctly based on the 1 and 2 in each header and I get a mixture in each file the program creates. I was wondering if anyone had any idea how to fix this? The code is below.

    Code:
    use strict;
    use warnings;
    
    my $readdata = $ARGV[0];
    open(FILE, "<$readdata") || die "cannot open $readdata\n"; 
    open(OUT1, ">$readdata\_1") || die "cannot open $readdata\_1\n"; 
    open(OUT2, ">$readdata\_2") || die "cannot open $readdata\_2\n";
    
    while(<FILE>){
    	chomp;
    	print OUT1 "$_\/1\n";
    	print OUT2 "$_\/2\n";
    	
    	my $newline = <FILE>; chomp($newline); 
    	print OUT1 substr($newline, 0, length($newline)/2)."\n";
    	print OUT2 substr($newline, length($newline)/2, length($newline)/2)."\n";
    	
    	$newline = <FILE>; chomp($newline); 
    	print OUT1 "$newline\/1\/n";
    	print OUT2 "$newline\/2\/n";
    	
    	$newline = <FILE>; chomp($newline);
    	print OUT1 substr($newline, 0, length($newline)/2)."\n";
    	print OUT2 substr($newline, length($newline)/2, length($newline)/2)."\n";
    	
    }
    
    close(FILE)
    Thanks so much for your help,

    ~Ana
  • dariober
    Senior Member
    • May 2010
    • 311

    #2
    Originally posted by akjones View Post
    Where the bolded "1" or "2" indicate which member of the pair the read is, so I am trying to get all 1's into a separate file and all 2's into a separate file.
    Hi Ana,

    This is not perl but it should work, assuming you are on a Linux/Unix machine:

    Code:
    paste - - - - < test.fq \
    | tee >(awk 'BEGIN{FS="\t"; OFS="\n"} {if (match($1, " 1:N")) print $1,$2,$3,$4}' > test.r1.fq ) \
    | awk 'BEGIN{FS="\t"; OFS="\n"} {if (match($1, " 2:N")) print $1,$2,$3,$4}' > test.r2.fq
    test.fq is your merged input file. test.r1.fq and test.r2.fq are the split files. I think the issue is to set the matching pattern to be specific enough to correctly separate read 1 from read 2 given the read name. Here I set the patterns to " 1:N" and " 2:N" for read 1 and 2 respectively.

    Loosely related to this question, take care that most programs expect the paired fastq files to have read 1 and read 2 in the same order (e.g. most aligners) and your pipeline above seems to break this requirement.

    All the best
    Dario

    Comment

    • akjones
      Member
      • Jun 2013
      • 24

      #3
      Hi Dario,

      Thanks very much, your code works! What do you mean by
      Loosely related to this question, take care that most programs expect the paired fastq files to have read 1 and read 2 in the same order (e.g. most aligners) and your pipeline above seems to break this requirement.
      are you referring to the direction of the reads (5'-3' or 3'-5') or the order of the reads themselves, as in read 1 followed by read 2 of a pair? Sorry if that is a silly question, I just want to make sure I am understanding you correctly.

      Thanks again,
      ~Ana

      Comment

      • dariober
        Senior Member
        • May 2010
        • 311

        #4
        Originally posted by akjones View Post
        Hi Dario,

        Thanks very much, your code works! What do you mean by are you referring to the direction of the reads (5'-3' or 3'-5') or the order of the reads themselves, as in read 1 followed by read 2 of a pair? Sorry if that is a silly question, I just want to make sure I am understanding you correctly.

        Thanks again,
        ~Ana
        Hi- The fastq files mate 1 should have the same number and order of reads as in the fastq for mate 2. So, if a read is missing from one file, its mate should be removed from the other file as well to keep the correct pairing.

        E.g. Say this is your file for mate 1:
        read_1.fq:
        Code:
        @read1 1:N
        ACTG
        +
        IIII
        @read2 1:N
        ACTG
        +
        IIII
        @read3 1:N
        ACTG
        +
        IIII
        This file for mate 2 would be ok:
        Code:
        @read1 2:N
        AAAA
        +
        IIII
        @read2 2:N
        TTTT
        +
        IIII
        @read3 2:N
        CCCC
        +
        IIII
        This file for mate 2 would be "wrong" as one read is missing:
        Code:
        @read1 2:N
        ACTG
        +
        IIII
        @read3 2:N
        ACTG
        +
        IIII
        Last edited by dariober; 12-04-2013, 09:18 AM. Reason: mate corrected

        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
        19 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...