Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: match two files

by yueli711 (Sexton)
on Jun 05, 2020 at 02:09 UTC ( [id://11117708]=note: print w/replies, xml ) Need Help??


in reply to Re^3: match two files
in thread match two files

Hello jwkrahn, Thank you so much for your great help! The result is actually what I wanted except missing the first line. Thank you again and really appreciated! Best, Yue I wanted:

,,AAACCTGAGCGTTTAC-1,AAACCTGAGTCGCCGT-1,AAACCTGGTAGGACAC-1,AAACCTGGTGC +CTTGG-1,AAACCTGGTTCAGCGC-1 A1CF,ENSG00000148584,0,0,0,0,0 A4GNT,ENSG00000118017,0,0,0,0,0 AARD,ENSG00000205002,0,0,0,0,0 AARS1,ENSG00000090861,0,0,0,0,0 AATK,ENSG00000181409,0,1,0,1,0 ABCA1,ENSG00000165029,0,0,0,0,0 ABCA12,ENSG00000144452,0,0,0,0,0 ABCA13,ENSG00000179869,0,0,0,0,0 ABCA6,ENSG00000154262,0,0,0,0,0 ABCA8,ENSG00000141338,0,0,0,0,0 ABCA9,ENSG00000154258,0,0,0,0,0

Replies are listed 'Best First'.
Re^5: match two files
by jwkrahn (Abbot) on Jun 05, 2020 at 23:44 UTC

    This should do it:

    #!/usr/bin/perl use warnings; use strict; use Fcntl ':seek'; open my $CSV, '<', 'donor_82_01.csv' or die "Cannot open 'donor_82_01. +csv' because: $!"; open my $TAB, '<', 'tmp12' or die "Cannot open 'tmp12' because: $!"; open my $OUT, '>', 'tmp12_01' or die "Cannot open 'tmp12_01' because: +$!"; my $pos = tell $CSV; my %csv_data; while ( <$CSV> ) { my ( $first ) = split /,+/; print $OUT ",$_" unless length $first; push @{ $csv_data{ $first } }, $pos; $pos = tell $CSV; } while ( <$TAB> ) { my ( $first, $second ) = split or next; next unless exists $csv_data{ $second }; for my $pos ( @{ $csv_data{ $second } } ) { seek $CSV, $pos, SEEK_SET or die "Cannot seek on 'donor_82_01. +csv' because: $!"; print $OUT "$first,", scalar <$CSV>; } } close $CSV; close $TAB; close $OUT;

      Hello jwkrahn, Thank you so much for your great help! This works perfect! Thank you again and best! Yue

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-28 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found