|
0
|
1 # !/usr/bin/perl
|
|
|
2
|
|
|
3 #-----------------------------------#
|
|
|
4 # Author: Vincent #
|
|
|
5 # Script: mutspecSplit.pl #
|
|
|
6 # Last update: 01/07/14 #
|
|
|
7 #-----------------------------------#
|
|
|
8
|
|
|
9
|
|
|
10 use strict;
|
|
|
11 use warnings;
|
|
|
12 use Getopt::Long;
|
|
|
13
|
|
|
14 our $file="";
|
|
|
15 our $column="";
|
|
|
16 our $path="";
|
|
|
17 our $key="";
|
|
|
18
|
|
|
19
|
|
|
20 GetOptions('file|f=s' =>\$file,
|
|
|
21 'key|k=s' =>\$key,
|
|
|
22 'column|i=s' =>\$column,
|
|
|
23 'path|p=s' =>\$path);
|
|
|
24
|
|
|
25
|
|
|
26 mkdir ("outputFiles") or die ("Erreur creation repertoire\n");
|
|
|
27 # print $file,"\n", $key,"\n", $column,"\n", $path,"\n"; exit;
|
|
|
28
|
|
|
29 my %tab;
|
|
|
30 if ($column==0) {$column++;}
|
|
|
31 $column--;
|
|
|
32
|
|
|
33 open(FILE, "$file") or die "cannot open $file\n";
|
|
|
34
|
|
|
35 $_=<FILE>; #skip headers
|
|
|
36 chomp;
|
|
|
37 my @line = split(/\t/,$_);
|
|
|
38 my $headers = join("\t", @line[0..($column-1),($column+1)..$#line]);
|
|
|
39
|
|
|
40 while(<FILE>){
|
|
|
41 chomp;
|
|
|
42 my @line = split(/\t/,$_);
|
|
|
43 #if (!exists($tab{$line[$column]})) { $tab{$line[$column]}=[]; }
|
|
|
44 #push( @{ $tab{$line[$column]} }, join("\t", @line[0..($column-1),($column+1)..$#line]) );
|
|
|
45 my $tmp = join("\t", @line[0..($column-1),($column+1)..$#line]) ;
|
|
|
46 my $id = $line[$column];
|
|
|
47 push( @{ $tab{$id} }, $tmp);
|
|
|
48 }
|
|
|
49
|
|
|
50
|
|
|
51 while( my ($name,$lines) = each(%tab) ) {
|
|
|
52 my $output="outputFiles/$name";
|
|
|
53 #my $output="primary_$key" . "_$name" . "_visible_tabular";
|
|
|
54 # my $output=$name;
|
|
|
55 open(FILE, ">$output") or die "cannot create file $output \n";
|
|
|
56 print FILE $headers."\n";
|
|
|
57 foreach my $line (@{$lines}){
|
|
|
58 print FILE "$line\n";
|
|
|
59 }
|
|
|
60 close FILE;
|
|
|
61 }
|
|
|
62
|
|
|
63 my $list=`ls outputFiles/*`;
|
|
|
64 print ($list);
|