Unconfigured Ad

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

    #1

    perl script

    Hai .I need a perl script can anybody help me ...I did an alignment of illumina paired reads,I need a script to extract only those reads in which both mates are not placed.
    example of the file which i need to extract

    HWI-EAS373:1:1:10:1119#0/1 GGAGCATTGCGACATTTAGCTNATTCAGCGGCATGGAAGG abbbbbbbbbaaa^aaa`aa^D[_`a_[_^__Z_a\G[__ NF
    HWI-EAS373:1:1:10:1119#0/2 GGAATAAGCAGAGTGAGCATAAGAGAAGATGNCTTCATGC a^WW_^`a`W^YXS[T\^M[YH[\_VY_]]^D[^^YPY]` NF
    HWI-EAS373:1:1:10:948#0/1 CTGGTCTTCCTCGATTCTCCCNATGGAGCCACTTTCTTCA abb`bbabbbbaa[a_abba^DP__[TX_^UIT[[___^U NF
    HWI-EAS373:1:1:11:1578#0/1 GGCAGGGTGAGGCTCCAGTCANTTGTCACACCCTTAACGG aaXababUbabb`\``[\^]VDWXOV]__]_`\MSKKa\Y NF

    The last two reads are NF (no match found), but their mate pair is aligned , so i need to extract only the reads in which both mates are not placed (NF)..

    thanks
  • jnfass
    Member
    • Aug 2008
    • 88

    #2
    perl one-liners to pull pairs of unmapped reads

    I often use perl on the *nix command line to solve problems like this. For this example (assuming the file you gave an example of is named "export.txt", you could:

    cat export.txt | perl -ane 'print if ($F[3] eq "NF")' | cut -f1 -d\# | sort | uniq -c | grep " 2 " | perl -ne 'm/(HWI.*)$/; print ">".$1."\n"' > pairedIds.txt

    That should give you the id's (without the "#0/1" or "/2", but with prepended ">") of the reads that appear twice as "NF" ... you can then pull these from the two s_?_?_sequence.txt files with:

    grep -A3 -F -f pairedIds.txt s_?_1_sequence.txt | grep -v ^-- > F.txt
    grep -A3 -F -f pairedIds.txt s_?_2_sequence.txt | grep -v ^-- > R.txt

    These are big grep's; they'll take a while. Note that grep can introduce separator lines of only two dashes when it finds consecutive blocks matching the pattern; the grep -v is intended to take those.

    Also, the above is 'off the cuff' ... you might have to debug a little

    Comment

    • simonandrews
      Simon Andrews
      • May 2009
      • 870

      #3
      Assuming you want the full lines for the entries which were not found, and that the sequence pairs come immediately after one another then something like this should work:

      Code:
      #!/usr/bin/perl
      use warnings;
      use strict;
      
      my $last_line;
      my $last_id = '';
      
      while(<>) {
      
        # Ignore any lines for sequences which were found
        next unless (/NF$/);
      
        # Extract the id minus the strand
        my $id;
        if (/^([^\/]+)/) {
          $id = $1;
        }
        else {
          die "Couldn't get id from $_";
        }
      
        # If this line has the same id as the last one then
        # both were not found so print them out
        if ($id eq $last_id) {
          print $last_line,$_;
        }
      
        # If not then store this line in case the next one
        # forms a pair which we'll print later.
        else {
          $last_line = $_;
          $last_id = $id;
        }
      }
      This will read any data passed on stdin or filenames passed as an argument and will output on stdout.

      Comment

      • bioenvisage
        Member
        • Oct 2009
        • 40

        #4
        hi thanks for the scripts ..the second script from simon andrews is very fast ..

        Comment

        • bioenvisage
          Member
          • Oct 2009
          • 40

          #5
          perl script

          ................
          Last edited by bioenvisage; 02-02-2010, 12:53 AM.

          Comment

          • simonandrews
            Simon Andrews
            • May 2009
            • 870

            #6
            I see you've posted another 'perl script' thread on the forum with another related question. I don't mean to sound harsh, but this isn't a place to come to get work done for you - though I'm sure there are people here who have consultancy services.

            I don't mind proving occasional scripts when people get stuck - and I'm more than happy to help sort out problems with scripts people have tried writing for themselves, but there's a limit to how much you can expect without at least showing what you've tried to sort this out yourself.

            If you're going to be doing this sort of work then I'd strongly recommend finding a local Perl course. I'm sure you'd find that a lot more productive than repeatedly posting to get canned answers. Using scripts you got from a forum without completely understanding what they do isn't going to be able to give you much confidence in your analysis results.

            If you've tried to modify the previously posted script and couldn't get it to work please feel free to post that and I'm sure you'll get help to make it work.

            Comment

            Latest Articles

            Collapse

            • SEQadmin2
              Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
              by SEQadmin2



              CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

              Despite this, “CRISPR helped turn genome editing from a specialized technique into
              ...
              07-31-2026, 11:01 AM
            • SEQadmin2
              Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
              by SEQadmin2


              Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

              The systematic characterization of the human proteome has
              ...
              07-20-2026, 11:48 AM
            • 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

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, Today, 07:41 AM
            0 responses
            9 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 08-03-2026, 10:13 AM
            0 responses
            25 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 07-31-2026, 02:55 AM
            0 responses
            38 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 07-24-2026, 12:17 PM
            0 responses
            25 views
            0 reactions
            Last Post SEQadmin2  
            Working...