hello, i have a hash table and i want transform this into an output which i could use in a R script. i use Text::table but i cant find a solution to have a good column separator (tab or pipe) this my code :

my %hash_sample_cds_genotype; my %hash_sample_cds_RT; my %hash_sample_cds_R1; my %hash_sample_cds_R2; #String des fichiers inputs foreach my $fichier (@fichiers) { my $sample_name; #alimentation du hash de resultat avec cette echatillon open(RESULTAT,"<$fichier") or die ("Cannot open $fichier\n"); while (defined(my $_ = <RESULTAT>)) { $sample_name = $fichier; my @attribut_name = split(m/out_/,$sample_name); $sample_name = $attribut_name[1]; my @resutat_infos = split(m/\t/,$_); next if ($_ =~ m/^CDS/); chomp($_); my $cds = $resutat_infos[0]; my $genotype = $resutat_infos[1]."/".$resutat_infos[2]; my $reads_p1 =$resutat_infos[3]; my $reads_p2 =$resutat_infos[4]; my $reads_totaux =$resutat_infos[6]; $hash_sample_cds_genotype{$sample_name}{$cds} = $genotype ; $hash_sample_cds_RT{$sample_name}{$cds} = $reads_p1 ; $hash_sample_cds_R1{$sample_name}{$cds} = $reads_p2 ; $hash_sample_cds_R2{$sample_name}{$cds} = $reads_totaux ; } close(RESULTAT); } #alimentation des fichier de resultats GENOTYPE my @cols1 = sort keys (%hash_sample_cds_genotype ); my @rows1 = sort keys % { { map { my $x = $_; map { $_ => undef } keys $hash_sample_cds_genotype{$x} } @cols1 } }; my $out1 = Text::Table->new(' ', @cols1); for my $r1 (@rows1) { $out1->add($r1, map $hash_sample_cds_genotype{$_}{$r1} // 'NA', @c +ols1); } print OUTPUT1 $out1;

Any idea ?


In reply to transform a hash table into R dataframe or matrix with tab separator by etricaen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.