annotate Perl/ConvertOrthofinderMatrix.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
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 my $cl_num = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 my $nb_strains = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 open(O,">$out");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 open(U,">$out.upsetr.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 open(M,">$out.accessory_01matrix.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 open(F,$matrix);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 my $firstline = <F>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 $firstline =~s/\n//g;$firstline =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 my @infos = split(/\t/,$firstline);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 print O "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 print U "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 print M "Gene";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 for (my $j=1; $j <= $#infos; $j++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 my $gbfile = $infos[$j];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 $gbfile =~s/\"//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 $gbfile =~s/\.gb\.filt//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 $gbfile =~s/\.gb\.rmdup//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 my $strain = $strains_of_gb{$gbfile};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 print O "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 print U "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 print M "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 $nb_strains++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 print U "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 print M "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 $cl_num++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 my @infos = split(/\t/,$_);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 print O $cl_num;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 print U $cl_num;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 my $concat_accessory = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 for (my $i = 1; $i <= $#infos; $i++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 my $val = $infos[$i];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 $val =~s/\"//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 $val =~s/\n//g;$val =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 if ($val =~/\w+/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 print U "\t1";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 $concat_accessory .= "\t1";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 else{
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 print U "\t0";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 $concat_accessory .= "\t0";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 my @genes = split(/, /,$val);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 my $concat = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 foreach my $gene(@genes){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 my $prot_id = $gene;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70 $concat .= "$prot_id,"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 chop($concat);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 if (scalar @genes == 0){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 $concat = "-";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 print O "\t".$concat;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 if ($concat_accessory =~/0/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 print M $cl_num.$concat_accessory."\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82 print U "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85 close(O);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86 close(U);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 close(M);