Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yao_licr
    Junior Member
    • Jul 2014
    • 7

    #1

    substitution using sed or awk

    Hi all,
    I just start to use sed and awk. I would like to change the following fastq file

    @SRR391606.9.1 1 length=50
    AGCACCGCGAGGGCGGAGCTGCGTTCTCCTCTGCACAGCTTTCGGTGGTA
    +SRR391606.9.1 1 length=50
    @9@?<<AA:3>7A/;@?B57@6;++4=4<,=6=+++17/)1?%%%%%%%%
    @SRR391606.10.1 2 length=50
    GTTGCGTTCTCCTCAGCACAGACCCGGAGAGCACCGCGAGGGCGGAGCTG
    +SRR391606.10.1 2 length=50
    ?BB?BA?AABAB>->ABB=99<AAB++35)137<>:37=<735(2-9492

    into following fastq file:

    @SRR391606.9 1 length=50
    AGCACCGCGAGGGCGGAGCTGCGTTCTCCTCTGCACAGCTTTCGGTGGTA
    +SRR391606.9 1 length=50
    @9@?<<AA:3>7A/;@?B57@6;++4=4<,=6=+++17/)1?%%%%%%%%
    @SRR391606.10 2 length=50
    GTTGCGTTCTCCTCAGCACAGACCCGGAGAGCACCGCGAGGGCGGAGCTG
    +SRR391606.10 2 length=50
    ?BB?BA?AABAB>->ABB=99<AAB++35)137<>:37=<735(2-9492

    Basically, it is a task to remove the ".1" on every other line. As I have a huge fastq file around 30 Gb, I only put the 9th and 10th reads out of it.

    Does anyone know how to do it using sed or awk? Please also explain the script in detail as I am a beginner.

    Thanks a lot!

    Yao
  • dschika
    Member
    • Mar 2010
    • 56

    #2
    This command should do the job:

    Code:
    awk '{if ($1 ~ /SRR/) {split($0, T, ".1 "); print T[1], T[2]}  else print $0}' YOURINPUT.fastq
    Since you mentioned sed and awk I assume you know that $1 = first field, $2 = second field (fields separated by whitespaces if not defined otherwise by FS) and $0 = whole line.

    The command checks if in the first field SRR is present ("if ($1 ~ /SRR/)"). If yes, it splits the content of the first line by ".1 " and stores the result in T. In this case ".1 " can be found only once in each line with SRR. Therefore, printing of T[0] and T[1] results in the line without ".1 ".

    If the line does not contain SRR (i.e., we are at a line with sequence or quality values) print the whole line.

    Comment

    • yao_licr
      Junior Member
      • Jul 2014
      • 7

      #3
      Thanks for the detailed explanation. It works well.

      Comment

      • dschika
        Member
        • Mar 2010
        • 56

        #4
        No problem, I just realized, that I was thinking way to complicated:

        sed 's/\.1 / /g' YOURINPUT.fastq > out.fastq

        Just replace ".1 " with " " and escape the "." with a backslash.

        Comment

        • yao_licr
          Junior Member
          • Jul 2014
          • 7

          #5
          Sorry, ".1" is the pattern to be replace by " ", so why do you put an empty space after 1? I mean the empty space in "/\.1 /" .

          Thanks!

          Comment

          • yao_licr
            Junior Member
            • Jul 2014
            • 7

            #6
            I got it now, as I have .1.1 in the first read; if there is no empty space after "\.1", both of them will be replaced. In your script, ".1 " is the pattern but not ".1" .

            Thanks!

            Comment

            • dschika
              Member
              • Mar 2010
              • 56

              #7
              Correct, you're welcome!

              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
              16 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, Yesterday, 10:48 AM
              0 responses
              15 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-15-2026, 10:52 AM
              0 responses
              35 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...