[Bioperl-l] Printing strings without return

Paulo Almeida paulo.david at netvisao.pt
Wed Mar 24 13:29:05 EST 2004


Hi Gyoergy,

You could use chomp(), or chop():

while ($seq=<FILE>)
{
chomp($seq);

...rest of your script...

chomp() gets rid of newlines at the end, while chop() gets rid of the 
final character, whatever it may be. You could also use a substitution:

while(<FILE>){
s/\s// unless />/;
print OUT;
}

I think that should work...


-Paulo

Gyoergy Abrusan wrote:

> Dear all
>
> (Beginners question nr. x...)
> I would like to ask how do I make one string from a Fasta file.
> In other words, from:
>
> >name
> actgtg
> tgctat
> accggg
> ...
>
> the following:
>
> >name
> actgtgtgctataccggg...
>
>
> I wrote a simple script:
>
> open FILE, "input.txt";
> open (OUT, ">$RESULTS.txt")or die "$0:ERROR: can't write report file\n";
>
> while ($seq=<FILE>)
> {
> if ($seq =~ />/)
> {
> print OUT "\n$seq";
> }
> else
> {
> print OUT "$seq";
> }
> }
>
>
> close OUT;
>
> The problem is that the lines in FASTA contain a RETURN at the end, so 
> the script doesn't change anything. Is there an option in perl to 
> print till the RETURN?
>
> Thanking you in advance.
> Kind regards,
>
> Gyorgy Abrusan 




More information about the Bioperl-l mailing list