Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • bioenvisage
    Member
    • Oct 2009
    • 40

    sort

    can any one help me , how to sort a file to have only unique reads, the format is the following

    >HWI-EAS373:1:1:10:1119#0/1
    GGAGCATTGCGACATTTAGCTNATTCAGCGGCATGGAAGG
    >HWI-EAS373:1:1:10:1119#0/2
    GGAATAAGCAGAGTGAGCATAAGAGAAGATGNCTTCATGC
    >HWI-EAS373:1:1:11:1157#0/1
    CGGGAATCCGGGACTTGAAAANATTCAGAACACTTTTCAG
    >HWI-EAS373:1:1:11:1157#0/2
    GATCCAGTTAAGGCAGAGATTGAGAGTTCACNGGAGAGTA
    >HWI-EAS373:1:1:11:986#0/1
    GTTTCCTCATACTAGACAACANATTCATGGTGTTTGAAGC
    >HWI-EAS373:1:1:11:986#0/2
    CCGGATGAGAGAAAAAGGGCTGCTGCAGCCANGGTTGAGC
    >HWI-EAS373:1:1:11:1274#0/1
    CGTCCTCCTCTCCTCCTGTCGNCTCCAGCGCACCA
  • alex_kozik
    Junior Member
    • Dec 2008
    • 3

    #2
    I am using combination of Unix 'sort' and 'uniq' commands to generate non-redundant fasta file, details are here:

    Comment

    • simonandrews
      Simon Andrews
      • May 2009
      • 870

      #3
      Note that there weren't any repeated sequences in your example dataset, but something like this should pull out unique sequences. It will be a bit memory heavy since it needs to keep all unique sequences in memory but there's no getting around that really.

      Code:
      #!/usr/bin/perl
      use warnings;
      use strict;
      
      my %kept;
      my %rejected;
      
      while(my $header = <>) {
        chomp $header;
        my $seq = <>;
        chomp $seq;
        next if (exists $rejected{$seq});
        if (exists $kept{$seq}) {
          delete $kept{$seq};
          $rejected{$seq} = 1;
        }
        else {
          $kept{$seq} = $header;
        }
      }
      
      foreach (keys %kept) {
        print $kept{$_},"\n",$_,"\n";
      }
      
      warn "Rejected ".(scalar keys %rejected)." sequences\n";

      Comment

      • cariaso
        Member
        • Jan 2008
        • 31

        #4
        grep -v '>' myfasta | sort -u

        is a short solution. But perhaps you need fasta? with or without original ids?

        Comment

        • Dave S.
          Junior Member
          • Jan 2010
          • 5

          #5
          Originally posted by simonandrews View Post
          Note that there weren't any repeated sequences in your example dataset, but something like this should pull out unique sequences. It will be a bit memory heavy since it needs to keep all unique sequences in memory but there's no getting around that really.
          Using a combination of Bio::SeqIO and Digest::MD5 you can generate signatures for all the sequences traversed and only keep the MD5 signatures in memory. Works best when the average sequence is much longer than the MD5 signature.

          The code is left as a homework exercise for bioenvisage.

          Comment

          • Fabien Campagne
            Member
            • Feb 2010
            • 39

            #6
            We've implemented an efficient two-pass algorithm in Goby (see my other post). Here's how to proceed once you have downloaded the tool:

            If you have a fasta/fastq format, first convert to compact format:
            java -Xmx3g -jar goby.jar -m fasta-to-compact with-redundancy.fasta
            (The file with-redundancy.compact-reads should have been created.)
            Use the tally-reads mode to calculate how many times each sequence appears in the input:
            java -Xmx3g -jar goby.jar -m tally-reads with-redundancy.compact-reads -f myfilter
            Tally reads leverages sequence digests and works in two passes to minimize memory usage. Input files can contain tens of millions of reads.
            Convert back to fasta, excluding sequences that appear more than once:
            java -Xmx3g -jar goby.jar -m compact-to-fasta -i with-redundancy.compact-reads -f myfilter-keep.filter -o unique-reads.fa

            See our wiki for nicer formatting and other options:
            Last edited by Fabien Campagne; 02-02-2010, 02:24 PM.

            Comment

            • flxlex
              Moderator
              • Nov 2008
              • 412

              #7
              awk will do a much faster job than sort | uniq -c (which I used a lot before I discovered awk). First, use grep to get the lines not starting with '>', then use awk. Same as with @simonandrews solution: it will store all unique reads in memory.

              grep -v '>' INFILE | awk '{r[$0]=1}END{for (x in r){print x}}'

              Comment

              Latest Articles

              Collapse

              • SEQadmin2
                Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                by SEQadmin2



                Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                ...
                07-09-2026, 11:10 AM
              • SEQadmin2
                Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                by SEQadmin2



                Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                07-08-2026, 05:17 AM
              • GATTACAT
                Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                by GATTACAT
                Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
                07-01-2026, 11:43 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, 07-13-2026, 10:26 AM
              0 responses
              20 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-09-2026, 10:04 AM
              0 responses
              30 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-08-2026, 10:08 AM
              0 responses
              17 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-07-2026, 11:05 AM
              0 responses
              34 views
              0 reactions
              Last Post SEQadmin2  
              Working...