Hi
I have a fasta file containing a number of sequences.
I would like to extract only the sequences that are of a specific length (lets's say >10 nt).
The sequences are wrapped with new lines, so when trying to read into an array, each line becomes an element. How can I removed these? I have tried join, but it also removes the newline between sequences and puts all of it into single string. How do I separate each sequence into an element or string?
The file looks something like this:
>NM_001 Homo sapiens ADA2 (CECR1)
GATCCAA
>NM_002 Homo sapiens IKBKG
GGAGGTCTTTAGCTTTAGGGAAACCC
Output should be only the second sequence in this case.
#!/usr/bin/perl -w
#open the fastfile Genes.fasta
open (GENES, "Genes.fasta") or die "Could not open file";
chomp (@seq = <GENES>);
$seq = join ("\n", @seq);
$lengthseq = length $seq;
#min length of the seq
$minlength = 10;
#if length is over a certain size, print
if ($lengthseq > $minlength){
print $seq;
}
else {print "No sequence is over $minlength;"
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|