Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2014 16:43
Show Gist options
  • Save anonymous/10400852 to your computer and use it in GitHub Desktop.
Save anonymous/10400852 to your computer and use it in GitHub Desktop.
$ cat test.txt
MPLE MIR ABUNDANCE
sample1 mir1 30
sample1 mir3 100
sample1 mir4 120
sample2 mir1 40
sample2 mir2 200
sample3 mir1 190
sample3 mir1 400
sample4 mir4 20
sample5 mir1 19
$ perl -ane 'if ($. > 1){$r{$F[0].":".$F[1]}=$F[2];unless($F[0]~~@s){push @s,$F[0];}unless($F[1]~~@m){push @m,$F[1];}}END{print "Samples\t".join("\t",@s)."\n";for($i=0;$i<@m;$i++){print $m[$i];for($j=0;$j<@s;$j++){(not defined $r{$s[$j].":".$m[$i]})?print "\t".0:print"\t".$r{$s[$j].":".$m[$i]};}print "\n";}}' test.txt
Samples sample1 sample2 sample3 sample4 sample5
mir1 30 40 400 0 19
mir3 100 0 0 0 0
mir4 120 0 0 20 0
mir2 0 200 0 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment