Re: Concatenating line into array problem
Edward Wijaya wrote: Hi groups, Hello, I have a file which contain many many of this line (Fasta Format): YNL331C CAATATGCGAGGGACCTACATGTTGA CATGACAATGAATTCTATTGAA YKL071W ATAATTATTCCTGTTTCTTTAACCTG GTGTACAAACACTTAAGC What I would like to do is to concatenate the line below into one single string. Such as the output would be: CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC The current code I created now seem to work but doesn't gie the result I want. Since it concatenates all into 1 single line. I thought there must be a very simple way to do this. But I can't seem to figure out how to achieve that. #---My Code -- while () { if (/^/) { next; } chomp; $line .= $_; } push (@crseq, $line); print join(\n, @crseq), \n; This should do what you want: $/ = ''; while ( ) { next unless s/\s+\S.*//; chomp; tr/\n//d; print $_\n; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Concatenating line into array problem
John W. Krahn wrote: This should do what you want: $/ = ''; while ( ) { next unless s/\s+\S.*//; chomp; tr/\n//d; print $_\n; } After seeing your data file change that to: $/ = ''; while ( ) { next unless s/\S+.*\n//; chomp; tr/\n//d; print $_\n; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Concatenating line into array problem
This works: ---BEGIN CODE--- #!/usr/bin/perl use warnings; use strict; $/ = ''; while (DATA) { s/(.*?\n.*?)\n/$1/s; print; } __DATA__ YNL331C CAATATGCGAGGGACCTACATGTTGA CATGACAATGAATTCTATTGAA YKL071W ATAATTATTCCTGTTTCTTTAACCTG GTGTACAAACACTTAAGC ---END CODE--- Please check your data for the first line: my line: CAATATGCGAGGGACCTACATGTTGACATGACAATGAATTCTATTGAA your line: CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA ^ An extra G has been inserted into your output would be line denoted by the ^ above and an A deleted from the end of the line. I think my line is correct but will not swear to it. :-) -ZO Edward Wijaya [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi groups, I have a file which contain many many of this line (Fasta Format): YNL331C CAATATGCGAGGGACCTACATGTTGA CATGACAATGAATTCTATTGAA YKL071W ATAATTATTCCTGTTTCTTTAACCTG GTGTACAAACACTTAAGC What I would like to do is to concatenate the line below into one single string. Such as the output would be: CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Concatenating line into array problem
This might be closer to what you want. Just push the line onto the array every time you come to the '' character. You'll get one empty line at the beginning, that's why I put the shift line in. while () { if (/^/) { push (@crseq, $line); next; } chomp; $line .= $_; } shift @crseq; print join(\n, @crseq), \n; -Original Message- From: Edward Wijaya [mailto:[EMAIL PROTECTED] Sent: Thursday, June 10, 2004 9:09 PM To: [EMAIL PROTECTED] Subject: Concatenating line into array problem snip What I would like to do is to concatenate the line below into one single string. Such as the output would be: CAATATGCGAGGGACCTACATGTTGAGCATGACAATGAATTCTATTGA ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC snip #---My Code -- while () { if (/^/) { next; } chomp; $line .= $_; } push (@crseq, $line); print join(\n, @crseq), \n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Concatenating line into array problem
On Thu, 10 Jun 2004 21:19:17 -0700, Tim Johnson [EMAIL PROTECTED] wrote: while () { if (/^/) { push (@crseq, $line); next; } chomp; $line .= $_; } shift @crseq; print join(\n, @crseq), \n; Thanks so much for your reply Tim. But the outoput it gives is CAATATGCGAGGGACCTACATGTTGACATGACAATGAATTCTATTGAA instead of: CAATATGCGAGGGACCTACATGTTGACATGACAATGAATTCTATTGAA and ATAATTATTCCTGTTTCTTTAACCTGGTGTACAAACACTTAAGC So it missed out second '' part of the fasta file. Any clue? Thanks again before hand. Regards Edward WIJAYA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Concatenating line into array problem
From: Edward Wijaya mailto:[EMAIL PROTECTED] wrote: : #---My Code -- : while () { : if (/^/) { : next; : } : chomp; : $line .= $_; : } : push (@crseq, $line); : print join(\n, @crseq), \n; How about: my @crseq; while ( ) { next unless/^[ACGT]/; chomp; push @crseq, $_ . scalar ; } print @crseq; HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Concatenating line into array problem
How about: my @crseq; while ( ) { next unless/^[ACGT]/; chomp; push @crseq, $_ . scalar ; } print @crseq; Hi Charles, Thanks for your reply. Your code works for my example in email, but not the file with more lines, (please see attached file). So sorry if I didn't give precise example. Regards, Edward WIJAYA YAP_up800.fasta Description: Binary data -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Concatenating line into array problem
From: Edward Wijaya mailto:[EMAIL PROTECTED] wrote: :: How about: :: :: my @crseq; :: while ( ) { :: next unless/^[ACGT]/; :: chomp; :: push @crseq, $_ . scalar ; :: } :: print @crseq; :: : : Hi Charles, : : Thanks for your reply. : : Your code works for my example in email, but not the file : with more lines, (please see attached file). : : So sorry if I didn't give precise example. Well, be that way! my @crseq; while ( ) { # start new line push @crseq, '' if /^/; # kill the line ending chomp; # concatenate current line # to the last array item $crseq[-1] .= $_ } print $_\n foreach @crseq; HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response