Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Print entire line

by Loops (Curate)
on Nov 06, 2014 at 11:44 UTC ( #1106359=note: print w/replies, xml ) Need Help??


in reply to Re^2: Print entire line
in thread Print entire line

ok,

my $filename = '/Users/Pabli/Desktop/do_human_mapping.gmt'; my $match = 'DOID:2055'; open(my $file, '<', $filename) or die "open: $!"; while (<$file>){ my ($name,$id,@genes) = split /\t/; print join("\n",@genes) if $id eq $match; }

The answer to your question then, is to use the assignment idiom above, to name the first two fields, and then use an array to slurp up all the genes that follow on the line. Because the name and id never get lumped into the @genes array, you don't have to go through contortions when it comes time to print.

Replies are listed 'Best First'.
Re^4: Print entire line
by pabla23 (Novice) on Nov 06, 2014 at 11:59 UTC
    Thanks so so so much!!! It works!!!!!!

    Paola

Re^4: Print entire line
by pabla23 (Novice) on Nov 06, 2014 at 13:49 UTC
    Sorry and if i want for example to search all the genes associated to different "DOID". My file is:

    parasitic helminthiasis infectious disease DOID:883 IL4 IL5

    female reproductive organ cancer DOID:120 BARD1 MAN1B1 SLC12A7 AMHR2 IL4 SLC12A6 SLC12A4

    My input is "IL4" and i want:

    DOID:883

    DOID:120

    I have to compare string? Thank a lot Paola

      It's essentially the same program, with a different comparison:

      my $filename = '/Users/Pabli/Desktop/do_human_mapping.gmt'; my $match = 'IL4'; open(my $file, '<', $filename) or die "open: $!"; while (<$file>){ my ($name,$id,@genes) = split /\t/; print $id,$/ if grep/^$match$/, @genes; }

      Happy to help, but the hope is that you're working towards being able to construct these lil programs for yourself!

        Thanks a lot "Loops" you are amazing!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1106359]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2022-05-20 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (73 votes). Check out past polls.

    Notices?