[30231] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1474 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 25 16:26:29 2008

Date: Fri, 25 Apr 2008 13:26:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 25 Apr 2008     Volume: 11 Number: 1474

Today's topics:
    Re: Help: Print lines <noreply@gunnar.cc>
    Re: Help: Print lines <noreply@gunnar.cc>
    Re: Help: Print lines <RedGrittyBrick@SpamWeary.foo>
    Re: Help: Print lines <RedGrittyBrick@SpamWeary.foo>
    Re: Help: Print lines <january.weiner@gmail.com>
    Re: Help: Print lines <RedGrittyBrick@SpamWeary.foo>
    Re: Help: Print lines <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 24 Apr 2008 09:44:37 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help: Print lines
Message-Id: <67arvpF2o6k8hU1@mid.individual.net>

Amy Lee wrote:
> My file is like is 
> 
>> CT1
> XY0002658-96
> 0000222541
>> CT2
> XY0002688-55
> 0000254147
>> CT5
> ZZ0004854-00
> 0000475568
> ...........
> 
> And I hope when some conditions match 'CT1', then can print its contents 'XY0002658-96 
> 0000222541', if match 'CT2' print 'XY0002688-55 0000254147'.

C:\home>type test.pl
while ( <DATA> ) {
     if ( /CT2/ ) {
         print scalar <DATA>;
         print scalar <DATA>;
     }
}

__DATA__
 >CT1
XY0002658-96
0000222541
 >CT2
XY0002688-55
0000254147
 >CT5
ZZ0004854-00
0000475568

C:\home>test.pl
XY0002688-55
0000254147

C:\home>

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Thu, 24 Apr 2008 10:54:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help: Print lines
Message-Id: <67b02kF2mejaiU1@mid.individual.net>

Amy Lee wrote:
> On Thu, 24 Apr 2008 09:44:37 +0200, Gunnar Hjalmarsson wrote:
>> Amy Lee wrote:
>>> My file is like is 
>>>
>>>> CT1
>>> XY0002658-96
>>> 0000222541
>>>> CT2
>>> XY0002688-55
>>> 0000254147
>>>> CT5
>>> ZZ0004854-00
>>> 0000475568
>>> ...........
>>>
>>> And I hope when some conditions match 'CT1', then can print its contents 'XY0002658-96 
>>> 0000222541', if match 'CT2' print 'XY0002688-55 0000254147'.
>> C:\home>type test.pl
>> while ( <DATA> ) {
>>      if ( /CT2/ ) {
>>          print scalar <DATA>;
>>          print scalar <DATA>;
>>      }
>> }
>>
>> __DATA__
>>  >CT1
>> XY0002658-96
>> 0000222541
>>  >CT2
>> XY0002688-55
>> 0000254147
>>  >CT5
>> ZZ0004854-00
>> 0000475568
>>
>> C:\home>test.pl
>> XY0002688-55
>> 0000254147
>>
>> C:\home>
> 
> Thank you very much. But I just have Learning Perl this book and I didn't 
> find out what "print scalar" is.

Assuming you know what print() is, please check out

     perldoc -f scalar

> And if the content dose not just contain 
> 2 lines, multi lines, what should I do?

Then the above approach isn't sufficient. Something like this might do:

     while ( <DATA> ) {
         if ( /CT2/ ) {
             while ( <DATA> ) {
                 last if /^>/;
                 print;
             }
         }
     }

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Thu, 24 Apr 2008 11:43:03 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Help: Print lines
Message-Id: <4810643b$0$26085$db0fefd9@news.zen.co.uk>

Amy Lee wrote:
> On Thu, 24 Apr 2008 09:44:37 +0200, Gunnar Hjalmarsson wrote:
> 
>> Amy Lee wrote:
>>> My file is like is 
>>>
>>>> CT1
>>> XY0002658-96
>>> 0000222541
>>>> CT2
>>> XY0002688-55
>>> 0000254147
>>>> CT5
>>> ZZ0004854-00
>>> 0000475568
>>> ...........
>>>
>>> And I hope when some conditions match 'CT1', then can print its contents 'XY0002658-96 
>>> 0000222541', if match 'CT2' print 'XY0002688-55 0000254147'.
>> C:\home>type test.pl
>> while ( <DATA> ) {
>>      if ( /CT2/ ) {
>>          print scalar <DATA>;
>>          print scalar <DATA>;
>>      }
>> }
>>
>> __DATA__
>>  >CT1
>> XY0002658-96
>> 0000222541
>>  >CT2
>> XY0002688-55
>> 0000254147
>>  >CT5
>> ZZ0004854-00
>> 0000475568
>>
>> C:\home>test.pl
>> XY0002688-55
>> 0000254147
>>
>> C:\home>
> 
> Thank you very much. But I just have Learning Perl this book and I didn't
> find out what "print scalar" is. 

It isn't "print scalar" it is "print X" where X is "scalar <DATA>"

perldoc -f scalar

> And if the content dose not just contain
> 2 lines, multi lines, what should I do?

perldoc -q paragraph

------------------ 8< ------------------
#!/usr/bin/perl
#
use strict;
use warnings;

$/ = "\n >";
while (my $record = <DATA>) {
   if ($record=~/CT2\n(.*)\n/s) { print $1 }
}

__DATA__
  >CT1
XY0002658-96
0000222541
  >CT2
XY0002688-55
0000254147
  >CT5
ZZ0004854-00
0000475568
------------------ 8< ------------------





-- 
RGB


------------------------------

Date: Thu, 24 Apr 2008 11:52:24 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Help: Print lines
Message-Id: <4810666c$0$26085$db0fefd9@news.zen.co.uk>

RedGrittyBrick wrote:
> #!/usr/bin/perl
> #
> use strict;
> use warnings;
> 
> $/ = "\n >";
> while (my $record = <DATA>) {
>   if ($record=~/CT2\n(.*)\n/s) { print $1 }
> }

Or
   $/ = "\n >";
   while (<DATA>) {
     print $1 if /CT5\n(.*)\n/s;
   }

> 
> __DATA__
>  >CT1
> XY0002658-96
> 0000222541
>  >CT2
> XY0002688-55
> 0000254147
   3333333333
   4444444444
>  >CT5
> ZZ0004854-00
> 0000475568



-- 
RGB


------------------------------

Date: Thu, 24 Apr 2008 15:44:58 +0200 (CEST)
From: January Weiner <january.weiner@gmail.com>
Subject: Re: Help: Print lines
Message-Id: <fuq2sq$al7$1@sagnix.uni-muenster.de>

Amy Lee <openlinuxsource@gmail.com> wrote:
[snip]

Use bioperl to parse FASTA files :-)

j.



------------------------------

Date: Fri, 25 Apr 2008 14:59:17 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Help: Print lines
Message-Id: <4811e3b6$0$10634$fa0fcedb@news.zen.co.uk>

Amy Lee wrote:
> On Thu, 24 Apr 2008 11:52:24 +0100, RedGrittyBrick wrote:
> 
>> RedGrittyBrick wrote:
>>> #!/usr/bin/perl
>>> #
>>> use strict;
>>> use warnings;
>>>
>>> $/ = "\n >";
>>> while (my $record = <DATA>) {
>>>   if ($record=~/CT2\n(.*)\n/s) { print $1 }
>>> }
>> Or
>>    $/ = "\n >";
>>    while (<DATA>) {
>>      print $1 if /CT5\n(.*)\n/s;
>>    }
>>
>>> __DATA__
>>>  >CT1
>>> XY0002658-96
>>> 0000222541
>>>  >CT2
>>> XY0002688-55
>>> 0000254147
>>    3333333333
>>    4444444444
>>>  >CT5
>>> ZZ0004854-00
>>> 0000475568
> 
> Thank you. But there's a problem I can't understand. What if I hope create
> files like CT1 contains the CT1 label including; CT2 contains the CT2
> label including and so on. However, I think I should read the label.
> 
> How to accomplish that? 
> 

I'm not sure I understand what you mean - it would be clearer if you 
give an example of the data.

Did you mean
  >CT1
XY0002658-96
0000222541
CT1
4444444444
5555555555
  >CT2
XY0002688-55
0000254147
CT1
CT2
5555555555
6666666666
7777777777
  >CT5
ZZ0004854-00
0000475568
CT2
CT5
5555555555
6666666666

If so, my suggested script would split the records OK because it uses 
newline space greater-than as the record separator. It however would 
select the wrong records because the selector is now insufficiently 
precise. We want to match CT2 (say) only when occurs at the start of a 
record. You can use the ^ character to anchor an expression to the 
start. "/CT2.../" becomes "/^CT2.../"

Do read the documentation - you will be able to work a lot of this out 
yourself.

perldoc perlre
perldoc perlop (look for "m/PATTERN")

-- 
RGB


------------------------------

Date: Fri, 25 Apr 2008 14:19:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Help: Print lines
Message-Id: <Xns9A8B691BB7E0Fasu1cornelledu@127.0.0.1>

RedGrittyBrick <RedGrittyBrick@SpamWeary.foo> wrote in
news:4811e3b6$0$10634$fa0fcedb@news.zen.co.uk: 

> Amy Lee wrote:

 ...

>> Thank you. But there's a problem I can't understand. What if I hope
>> create files like CT1 contains the CT1 label including; CT2 contains
>> the CT2 label including and so on. However, I think I should read the
>> label. 
>> 
>> How to accomplish that? 
>> 
> 
> I'm not sure I understand what you mean - it would be clearer if you 
> give an example of the data.
> 

 ...

> Do read the documentation - you will be able to work a lot of this out
> yourself.

She seems to be here to get fish.

As January Weiner noted, apparently her data is domain specific. I do 
not know what FASTA files are but if the OP really is working with FASTA 
files, using BioPerl would indeed be the right thing to do instead of 
trying to re-write that functionality through piecemeal questions posted 
on clpmisc.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1474
***************************************


home help back first fref pref prev next nref lref last post