Parsing Fasta Sequence From File
2
0
Entering edit mode
12.6 years ago
Jane ▴ 30

Hello,

I am using perl and not bioperl because my professor has not shown us how yet. I have to extract a FASTA sequence attached to a user accession number input. E.g, If the user enters YP_02030404.1, the script should get the sequence attached to it. like this:

>gi|170079675|ref|YP_001728995.1|  [Escherichia coli str. K-12 substr. DH10B]   
MRVSWLESKCDTPFANNLSFISSGSSSSSSFTLASTACRNSCLCSSSIFFQVLRRNCSSNCCSISNVDIS  
LSAFSFNRFETSSKMARYNLPCPRSLLAILSPPKCCNSPAISCQLRRCCSGCPSIDLNSSLRISTLERRV 
LPFSLWVSNRAKFANCSSLQC
fasta sequence homework • 3.0k views
ADD COMMENT
0
Entering edit mode

And where is this sequence to be "extracted" from? A local database? A remote database? I suggest you use your initiative and started reading the Bioperl HOW-TOs: http://www.bioperl.org/wiki/HOWTOs. What you want to do is very easy.

ADD REPLY
0
Entering edit mode

Can you only do what your prof. has shown you, or are you an independent mind?

ADD REPLY
3
Entering edit mode
12.6 years ago

so you are asking us to do your homework? strange place to ask for it. but if you are really trying to learn perl, and as I hate discouraging people from starting off, then I'll suggest you try learning

  1. how to accept text input
  2. how to read lines
  3. how to store data in hashes (the accession line would be the key, the concatenated-lines-sequence would be the value), and finally
  4. how to iterate through hash keys doing some basic pattern matching.

so if accession entered matches any of the hash keys, then you return its value. this is the answer to your question, although you'll have to find out how to build up these 3 steps using perl.

ADD COMMENT
0
Entering edit mode

or sorry..i have code down..im just struggling..

!/usr/bin/perl -w

use strict;

my $filename; my $accessionid; my $sequenceid;

print "Please enter in the filename: "; chomp($filename = <STDIN>);

print "Please enter in the accessionID: "; chomp($accessionid = <STDIN>);

open(FILENAME, $filename) or die "cannot open file: $! "; while(<FILENAME>){ if($_ =~ /$accessionid/i) { $sequenceid = $; print "$sequenceid\n"; } my $seq = ''; foreach($) { last if ($ =~ />gi/);

print "$seq\n"; } }

ADD REPLY
0
Entering edit mode

i have code..sorry!!

!/usr/bin/perl -w

use strict;

my $filename; my $accessionid; my $sequenceid;

print "Please enter in the filename: "; chomp($filename = <STDIN>);

print "Please enter in the accessionID: "; chomp($accessionid = <STDIN>);

open(FILENAME, $filename) or die "cannot open file: $! "; while(<FILENAME>){ if($_ =~ /$accessionid/i) { $sequenceid = $; print "$sequenceid\n"; } my $seq = ''; foreach($) { last if ($ =~ />gi/);

print "$seq\n"; } }

ADD REPLY
0
Entering edit mode

!/usr/bin/perl -w

use strict;

my $filename; my $accessionid; my $sequenceid;

print "Please enter in the filename: "; chomp($filename = <STDIN>);

print "Please enter in the accessionID: "; chomp($accessionid = <STDIN>);

open(FILENAME, $filename) or die "cannot open file: $! ";

while(<FILENAME>){

if($_ =~ /$accessionid/i) { $sequenceid = $; print "$sequenceid\n"; } my $seq = '';

foreach($) { last if ($ =~ />gi/);

print "$seq\n"; } }

ADD REPLY
0
Entering edit mode
12.6 years ago
Jane ▴ 30

i have code sorry..

#!/usr/bin/perl -w
use strict;

my $filename;
my $accession_id;
my $sequence_id;

print "Please enter in the filename: ";
chomp($filename = <STDIN>);
print "Please enter in the accession_ID: ";
chomp($accession_id = <STDIN>);

open(FILENAME, $filename) or die "cannot open file: $! ";
while(<FILENAME>){
  if($_ =~ /$accession_id/i) {
  $sequence_id = $_;
  print "$sequence_id\n";
}

my $seq = '';
foreach($_) {
  last if ($_ =~ />gi/);
  print "$seq\n";
}
}
ADD COMMENT
0
Entering edit mode

Please indent code using 4 spaces to format it properly. I did it for you this time. Also, is this your answer? If not, remove it and add the code to your original question.

ADD REPLY
0
Entering edit mode

I'm so sorry. This is my first time on here. I apologize. Yes, that is my code. i posted.

ADD REPLY

Login before adding your answer.

Traffic: 2736 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6