Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zapages
    Member
    • Oct 2012
    • 98

    #1

    Adding counting Contig number at the start of Fasta Sequences

    I am trying to add Prefix to a list of Fasta sequences (30K+ which I have de-novo assembled) in a fasta file at the same time.

    I know from the past that have been able to add it at the end of the sequences. But I am getting a bit confused on how should I do it for the start of the Fasta sequence.

    For the end of sequence.
    Code:
    awk '/^>/{$0=$0"_Contig_"(++i)}1' input_file.fasta > output_file.fasta
    This will change something like this in the fasta file:

    From:
    >Sequence_header
    ATAGCATA
    To:
    >Sequences_header_Contig_1
    ATAGCATA
    ...
    >Sequences_header_Contig_n
    ATAGCATA


    I hope to do something like this:

    >Sequence_header
    ATAGCATA
    To:
    >Contig_1_Sequences_header
    ATAGCATA
    ...
    >Contig_n_Sequences_header
    ATAGCATA


    Code:
    awk '/^>/{"Contig_"(++i)"_"$0=$0}1' input_file.fasta > output_file.fasta
    Unfortunately I receive a synthax error.

    If someone could kindly show what I am doing wrong. I would greatly appreciate it.

    Many thanks.
    Last edited by Zapages; 05-09-2015, 05:02 PM.
  • pmiguel
    Senior Member
    • Aug 2008
    • 2328

    #2
    Sorry, I don't speak awk.
    Code:
    perl -pe 'next unless /^>/; $i++; s/>(\S+)/>Contig_${i}_$1/' input_file.fasta > output_file.fasta
    seems to work.

    --
    Phillip

    Comment

    • GenoMax
      Senior Member
      • Feb 2008
      • 7142

      #3
      How about this?

      Code:
      $  awk '{if (/^>/) print ">Contig_"(++i)"_" substr($0,2); else print $0;}'  your_file > new_file

      Comment

      • Zapages
        Member
        • Oct 2012
        • 98

        #4
        Thank you Phillip and Genomax. Both of the strategies work.

        Really appreciate all the help.

        Many Thanks,

        Zapages

        Comment

        Latest Articles

        Collapse

        • SEQadmin2
          16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
          by SEQadmin2




          NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification, detection...
          Today, 06:46 AM
        • 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

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, 10-28-2026, 09:57 AM
        0 responses
        22 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-28-2026, 09:51 AM
        0 responses
        15 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-22-2026, 11:13 AM
        0 responses
        68 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-22-2026, 10:48 AM
        0 responses
        48 views
        0 reactions
        Last Post SEQadmin2  
        Working...