Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, All, I would like my output in a easy to read format than they wy I have got now. I would be great to have your suggestions and pointers for this please.This is how I get my output at the moment:
Sample,Genotypes,Plex,rsids AWQ,A,W30123,rs123 AWQ,G,W30123,rs121 AWQ,C,W30123,rs1234 AWQ,N,W30123,rs122 AWQ,T,W30123,rs1213 AWQ,NN,W30122,rs1232 AWQ,NN,W30122,rs1222 AWQ,NN,W30122,rs1223 AWQ,NN,W30122,rs12121 AWQ,NN,W30122,rs12111 AWQ,NN,W30122,rs1 AWQ,G,W30121,rs143 AWQ,C,W30121,rs13 AWQ,C,W30121,rs125 AWQ,G,W30121,rs12453 AWQ,T,W30121,rs124763 AWQ,A,W30121,rs12343 AWP,T,W30123,rs123 AWP,C,W30123,rs121 AWP,C,W30123,rs1234 AWP,N,W30123,rs122 AWP,G,W30123,rs1213 AWP,G,W30122,rs1232 AWP,N,W30122,rs1222 AWP,A,W30122,rs1223 AWP,AG,W30122,rs12121 AWP,G,W30122,rs12111 AWP,C,W30122,rs1 AWP,T,W30121,rs143 AWP,G,W30121,rs13 AWP,T,W30121,rs125 AWP,C,W30121,rs12453 AWP,G,W30121,rs124763 AWP,C,W30121,rs12343



I want them in this format Which is more readable and doesn't run for +too many lines. Sample,rs123,rs121,rs1234,rs122,rs1213,rs1232,rs1222,rs1223,rs12121,rs +12111,rs1,rs143,rs13,rs125,rs12453,rs124763,rs12343 AWQ,A,G,C,N,T,NN,NN,NN,NN,NN,NN,G,C,C,G,T,A AWP,T,C,C,N,G,G,N,A,AG,G,C,T,G,T,C,G,C

my actual code:
use Getopt::Long; 4 use Benchmark; 5 use Config::Config qw(/nfs/users/nfs_a/aj6/CGP/Sequenom/perl/Seque +nom.ini); 6 use Database::Conn; 7 8 my $conn; 9 my $snp_list = {}; 10 my $ind_list = {}; 11 my $gen_list = {}; 12 eval { 13 14 $conn = Database::Conn->new('live'); 15 $conn->addConnection(DBI->connect('dbi:Oracle:SNP.world','snp','s +np', {RaiseError =>1 , AutoCommit=>0}),'snp'); 16 my $timestarted = Benchmark->new(); 17 my $snparray = $conn->executeArrRef('snp::Sequenom::getSnpsforPle +x'); 18 19 my $indsent = $conn->executeArrRef('snp::Sequenom::getIndForPlate +Sent'); 20 #=cut 21 foreach my $ind( @ {$indsent} ){ 22 23 foreach my $snp (@ {$snparray} ){ 24 25 my $genotype = $conn->executeArrRef('snp::Sequenom::getGenotyp +eCalls', $ind->[0], $snp->[0]); 26 27 foreach my $geno( @ {$genotype} ){ 28 #3my $i = 1; 29 if(defined $geno->[3]){ 30 31 32 print "$geno->[1],$geno->[3],$geno->[2],$geno->[4]\n"; 33 34 }#end of if loop to check the genotype defined 35 else{ 36 37 print "$geno->[1],NO,$geno->[2],$geno->[4]\n" 38 39 } 40 41 42 }#end of @$genotype 43 44 }#end of @$snpsent }#end of @$indsent
The points to note are:
1.The rsids fr each plex are unique.
2.The number of rsids in each plex may vary.
3.I get all the information from the database and it is for each sample and each snp.
Thanks every one for your help,

Replies are listed 'Best First'.
Re: Changing the format of output
by toolic (Bishop) on May 31, 2011 at 14:24 UTC
    One way is to collect the rs things in an array (@samples) and the AW things in a hash-of-arrays inside your nested for-loops, then print it all out after the loops. UNTESTED:
    my @samples; my %aws; foreach my $geno( @ {$genotype} ){ push @samples, $geno->[4]; if(defined $geno->[3]){ push @{ $aws{$geno->[1]} }, $geno->[3]; }#end of if loop to check the genotype defined else{ push @{ $aws{$geno->[1]} }, 'NO'; } }#end of @$genotype print 'Sample,'; print(join ',', @samples); print "\n"; for (keys %aws) { print "$_,"; print(join ',', @{ $aws{$_} }); print "\n"; }
Re: Changing the format of output
by Anonymous Monk on May 31, 2011 at 23:10 UTC
    my actual code:

    Every one of those line numbers is a syntax error