annotate Perl/ConvertPanacotaMatrix.pl @ 8:f919ffe96425 draft

Uploaded
author dereeper
date Thu, 30 May 2024 14:31:04 +0000
parents e42d30da7a74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/bin/perl
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
2
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
3 use strict;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
4
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
5 my $indir = $ARGV[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
6 my $matrix = $ARGV[1];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
7 my $out = $ARGV[2];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
8 my $strain_names = $ARGV[3];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10 my %strains_of_gb;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 open(F,$strain_names);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15 my ($gb,$strain) = split(/\t/,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16 $strains_of_gb{$gb} = $strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 my @strains;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21 my %corr;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 open(D,"ls $indir/*pep |");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 while(<D>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 my $file = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 my $prot_num = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 my $strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 if ($file =~/\/([^\/]*).pep/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 $strain = $1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 $strain = $strains_of_gb{$strain};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 push(@strains,$strain);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 open(F,"$file");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 if (/>(.*)/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 my $prot_id = $1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 $prot_num++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 my $new_id = "$strain"."_".$prot_num;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 $corr{$new_id} = $prot_id;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 close(D);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 my $cl_num = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 my $nb_strains = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 open(O,">$out");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 open(U,">$out.upsetr.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 open(M,">$out.accessory_01matrix.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 open(F,$matrix);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 print O "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 print U "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 print M "Gene";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 my %hash_place_strains;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 my $num_cell = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 foreach my $strain(@strains){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 $num_cell++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 my @words = split(/_/,$strain);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 my $genus = $words[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 my $species = $words[1];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 my $shortname = substr($genus,0,3) . "_". substr($species,0,2);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 for (my $j = 2; $j <= $#words; $j++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 $shortname.="_".$words[$j];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 $shortname = substr($shortname,0,25);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 print O "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 print U "\t".$shortname;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 print M "\t".$shortname;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 $hash_place_strains{$strain} = $num_cell;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70 $nb_strains++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 print U "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 print M "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 $cl_num++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 my @infos = split(/ /,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80 my %cells;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81 for (my $i = 1; $i <= $#infos; $i++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82 my $new_id = $infos[$i];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 my $prot_id = $corr{$new_id};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84 my $strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85 if ($new_id =~/^(.*)_\d+$/){$strain=$1;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86 my $num_cell = $hash_place_strains{$strain};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 #print "$strain $num_cell $prot_id $new_id\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
88 $cells{$strain}.= $prot_id.",";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
89 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
90 print O $cl_num;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
91 print U $cl_num;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
92 my $concat_accessory = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
93 foreach my $strain(@strains){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
94 my $val;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
95 if ($cells{$strain}){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
96 $val = $cells{$strain};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
97 chop($val);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
98 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
99 else{
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
100 $val = "-";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
101 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
102 if ($val =~/\w+/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
103 print U "\t1";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
104 $concat_accessory .= "\t1";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
105 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
106 else{
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
107 print U "\t0";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
108 $concat_accessory .= "\t0";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
109 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
110 my $concat = $val;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
111 print O "\t".$concat;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
112 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
113 if ($concat_accessory =~/0/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
114 print M $cl_num.$concat_accessory."\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
115 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
116 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
117 print U "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
118 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
119 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
120 close(O);