Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iMarcelo
    Junior Member
    • May 2016
    • 4

    #1

    How do I convert one file into several multifasta fasta files using perl

    Hi
    It's the first time I work with Perl then I don't know so much about the language.
    I need a script which converts multi-fasta file in several different fasta file.
    For example:

    In multi-fasta file contains:

    >seq1
    CTGACTGGGAGTACGAAGGCCGCCTGCACAAGACAACGGGGCAGCGAACCTTCTTCTGCACCGGCACGGA
    CGACGCCGAGATGCCTCGACCTGGAGAACCTCGGCCGCGGCGAACCGCTCGCCCATGT
    >seq2
    GACGTGCTGCTGGAGATCGCCACGCCGGGTCGCTCGTTCTGTAAGCGGATGTCGATATTGGTTGACTGAT
    AGCTGGCGCGCGGTAGCATCTCGAACATGCGTTCGAGACCAGAGACGGGGCATGTAGA
    >seq3
    CTGACTGGGAGTACGAAGGCCGCCTGCACAAGACAACGGGGCAGCGAACCTTCTTCTGCACCGGCACGGA
    CGACGCCGAGATGCCTCGACCTGGAGAACCTCGGCCGCGGCGAACCGCTCGCCCATGT

    I want to convert this multifasta file into several output files fasta:

    file1.fasta
    >seq1
    CTGACTGGGAGTACGAAGGCCGCCTGCACAAGACAACGGGGCAGCGAACCTTCTTCTGCACCGGCACGGA
    CGACGCCGAGATGCCTCGACCTGGAGAACCTCGGCCGCGGCGAACCGCTCGCCCATGT

    file2.fasta
    >seq2
    GACGTGCTGCTGGAGATCGCCACGCCGGGTCGCTCGTTCTGTAAGCGGATGTCGATATTGGTTGACTGAT
    AGCTGGCGCGCGGTAGCATCTCGAACATGCGTTCGAGACCAGAGACGGGGCATGTAGA

    file3.fasta
    >seq3
    CTGACTGGGAGTACGAAGGCCGCCTGCACAAGACAACGGGGCAGCGAACCTTCTTCTGCACCGGCACGGA
    CGACGCCGAGATGCCTCGACCTGGAGAACCTCGGCCGCGGCGAACCGCTCGCCCATGT

    Remembering: must be in perl
    Last edited by iMarcelo; 05-05-2016, 10:25 AM.
  • GenoMax
    Senior Member
    • Feb 2008
    • 7142

    #2
    Is this a homework assignment? If it is then you may want to show what you have done so far to get help.

    Comment

    • vivek_
      PhD Student
      • Jul 2012
      • 164

      #3
      Code:
      #!/usr/bin/env perl
      
      use strict;
      use warnings;
      use IO::File;
      
      my $usage = "\nUSAGE: perl $0 <Fasta>"."\n";
      print $usage and exit unless($ARGV[0]);
      my $fh  = IO::File->new("$ARGV[0]");
      my $out = "";
      
      
      while(my $line = $fh->getline)
      {
          chomp($line);
          if($line =~ /^>/)
          {
      	if($out ne "")
      	{
      	    $out->close;
      	}
      	$line =~ s/^>//;
      	$out  = IO::File->new("> $line.fa");
      	print $out ">".$line."\n";
          }
          else
          {
      	print $out $line."\n";
          }
      }
      
      $fh->close;
      $out->close;
      Last edited by vivek_; 05-06-2016, 06:37 AM. Reason: Reposted code

      Comment

      • GenoMax
        Senior Member
        • Feb 2008
        • 7142

        #4
        @vivek: This may be a homework assignment. In that case you don't want to provide ready code. @iMarcelo is not going to learn this way.

        Comment

        • vivek_
          PhD Student
          • Jul 2012
          • 164

          #5
          My bad, I thought it might be a technician struggling with a task. I'll remove it but if he is subscribed to e-mail notifications, he'll get the post in e-mail anyways.

          Comment

          • GenoMax
            Senior Member
            • Feb 2008
            • 7142

            #6
            That is ok. Your code used modules and a beginner student probably would not be expected to know that. iMarcelo may not be able to use that code, in that case.

            The part about it has to be perl is why I thought this may be homework.

            Comment

            • iMarcelo
              Junior Member
              • May 2016
              • 4

              #7
              No, it isn't a homework assignment. It's a task in my job. I have no knowledge in perl language,
              I have always done my tasks in Java or C, but the person who works with perl is on vacation, so my boss gave me this task to do. I am doing research on this, but still no success.
              So who can help me, thank you.

              Comment

              • GenoMax
                Senior Member
                • Feb 2008
                • 7142

                #8
                While @vivek puts his code back up you can use http://hgdownload.cse.ucsc.edu/admin...x86_64/faSplit utility from Jim Kent to do this very efficiently.

                If you know Java/C then the end result should be the same as using perl if you used one of those languages.

                Comment

                • vivek_
                  PhD Student
                  • Jul 2012
                  • 164

                  #9
                  Originally posted by iMarcelo View Post
                  No, it isn't a homework assignment. It's a task in my job. I have no knowledge in perl language,
                  I have always done my tasks in Java or C, but the person who works with perl is on vacation, so my boss gave me this task to do. I am doing research on this, but still no success.
                  So who can help me, thank you.
                  I have reposted the code.

                  Comment

                  • iMarcelo
                    Junior Member
                    • May 2016
                    • 4

                    #10
                    Originally posted by vivek_ View Post
                    I have reposted the code.
                    Thank you so much @vivek.

                    I have difficulty working with languages that I've never worked before, and I had to do this task for my boss urgently.

                    I will continue doing research on this language for me to learn more for future tasks.

                    Comment

                    • iMarcelo
                      Junior Member
                      • May 2016
                      • 4

                      #11
                      Originally posted by GenoMax View Post
                      While @vivek puts his code back up you can use http://hgdownload.cse.ucsc.edu/admin...x86_64/faSplit utility from Jim Kent to do this very efficiently.

                      If you know Java/C then the end result should be the same as using perl if you used one of those languages.
                      Yes, the end result is the same, but my boss wanted in Perl, I don't know why.

                      Thank you for your help.

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