#!/usr/bin/perl -w # Split a tab-delimited text files into n files, repeating # first column and shuffling columns. # Julien Textoris use strict; use warnings; open(IN, "$ARGV[0]"); my $n = $ARGV[1]; #Thanks to Q&A for this ! sub melange_fy { my $tab = shift; my $i; for($i = @$tab; --$i;) { my $j = int rand($i+1); next if ($i == $j); @$tableau[$i,$j] = @$tableau[$j,$i]; } } my $perm =0 ; my (@ind); while ( my $ligne = ) { $ligne =~ s/[\r\n]//g; my ($id,@elmt) = split(/\t/, $ligne); #make the permutation of tab indices only the first time unless($perm++) { @ind = (0..@elmt-1); melange_fy(\@ind); } my $w = int(scalar(@elmt)/$n+0.5); for(my $i = 0; $i < $n; $i++) { open (OUT, ">>$ARGV[0].$i"); my $d = $i*$w; my($f); if($i == $n-1) { $f = scalar(@elmt)-1; } else { $f = $d+$w-1; } print OUT join("\t",$id,@elmt[@ind[$d..$f]])."\n"; close(OUT); } } #### Genes setA setB setC setD setE setF setG g1 1 2 3 4 5 6 7 g2 1 2 3 4 5 6 7 g3 1 2 3 4 5 6 7