SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
extract data from fasta-files with perl?? anna_ Bioinformatics 20 02-17-2016 07:29 AM
vcf convert to fasta, the fasta file is not an alingment file wangxueqin Bioinformatics 1 09-04-2015 10:36 PM
consensus fasta and multifasta file of human genomes huma Asif Bioinformatics 8 09-05-2014 09:03 AM
[PERL] Compare two sequences from fasta file frenchcookie Bioinformatics 3 12-17-2012 07:59 AM
Perl: get specific base from FASTA file. njh_TO Bioinformatics 6 02-02-2012 05:34 AM

Reply
 
Thread Tools
Old 05-05-2016, 10:19 AM   #1
iMarcelo
Junior Member
 
Location: Manaus

Join Date: May 2016
Posts: 4
Default 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 at 10:25 AM.
iMarcelo is offline   Reply With Quote
Old 05-05-2016, 10:28 AM   #2
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,975
Default

Is this a homework assignment? If it is then you may want to show what you have done so far to get help.
GenoMax is offline   Reply With Quote
Old 05-05-2016, 10:30 AM   #3
vivek_
PhD Student
 
Location: Denmark

Join Date: Jul 2012
Posts: 164
Default

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 at 06:37 AM. Reason: Reposted code
vivek_ is offline   Reply With Quote
Old 05-05-2016, 10:32 AM   #4
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,975
Default

@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.
GenoMax is offline   Reply With Quote
Old 05-05-2016, 10:36 AM   #5
vivek_
PhD Student
 
Location: Denmark

Join Date: Jul 2012
Posts: 164
Default

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.
vivek_ is offline   Reply With Quote
Old 05-05-2016, 10:40 AM   #6
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,975
Default

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.
GenoMax is offline   Reply With Quote
Old 05-06-2016, 06:20 AM   #7
iMarcelo
Junior Member
 
Location: Manaus

Join Date: May 2016
Posts: 4
Default

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.
iMarcelo is offline   Reply With Quote
Old 05-06-2016, 06:31 AM   #8
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,975
Default

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.
GenoMax is offline   Reply With Quote
Old 05-06-2016, 06:38 AM   #9
vivek_
PhD Student
 
Location: Denmark

Join Date: Jul 2012
Posts: 164
Default

Quote:
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.
vivek_ is offline   Reply With Quote
Old 05-06-2016, 07:47 AM   #10
iMarcelo
Junior Member
 
Location: Manaus

Join Date: May 2016
Posts: 4
Default

Quote:
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.
iMarcelo is offline   Reply With Quote
Old 05-06-2016, 07:54 AM   #11
iMarcelo
Junior Member
 
Location: Manaus

Join Date: May 2016
Posts: 4
Default

Quote:
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.
iMarcelo is offline   Reply With Quote
Reply

Tags
bioinfomatics, fasta file, perl

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 10:37 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO