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