annotate PanExplorer_workflow/Perl/ConvertOrthofinderMatrix.pl @ 1:032f6b3806a3 draft

Uploaded
author dereeper
date Thu, 30 May 2024 11:16:08 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/bin/perl
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
3 use strict;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
4
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
5 my $indir = $ARGV[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
6 my $matrix = $ARGV[1];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
7 my $out = $ARGV[2];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
8 my $strain_names = $ARGV[3];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
9
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
10 my %strains_of_gb;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
11 open(F,$strain_names);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
12 while(<F>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
13 my $line = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
14 $line =~s/\n//g;$line =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
15 my ($gb,$strain) = split(/\t/,$line);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
16 $strains_of_gb{$gb} = $strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
17 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
18 close(F);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
19
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
20
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
21
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
22 my $cl_num = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
23 my $nb_strains = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
24 open(O,">$out");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
25 open(U,">$out.upsetr.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
26 open(M,">$out.accessory_01matrix.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
27 open(F,$matrix);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
28 my $firstline = <F>;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
29 $firstline =~s/\n//g;$firstline =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
30 my @infos = split(/\t/,$firstline);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
31 print O "ClutserID";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
32 print U "ClutserID";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
33 print M "Gene";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
34 for (my $j=1; $j <= $#infos; $j++){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
35 my $gbfile = $infos[$j];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
36 $gbfile =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
37 $gbfile =~s/\.gb\.filt//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
38 $gbfile =~s/\.gb\.rmdup//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
39 my $strain = $strains_of_gb{$gbfile};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
40 print O "\t".$strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
41 print U "\t".$strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
42 print M "\t".$strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
43 $nb_strains++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
44 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
45 print O "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
46 print U "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
47 print M "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
48 while(<F>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
49 $cl_num++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
50 my @infos = split(/\t/,$_);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
51 print O $cl_num;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
52 print U $cl_num;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
53 my $concat_accessory = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
54 for (my $i = 1; $i <= $#infos; $i++){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
55 my $val = $infos[$i];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
56 $val =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
57 $val =~s/\n//g;$val =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
58 if ($val =~/\w+/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
59 print U "\t1";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
60 $concat_accessory .= "\t1";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
61 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
62 else{
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
63 print U "\t0";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
64 $concat_accessory .= "\t0";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
65 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
66 my @genes = split(/, /,$val);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
67 my $concat = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
68 foreach my $gene(@genes){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
69 my $prot_id = $gene;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
70 $concat .= "$prot_id,"
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
71 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
72 chop($concat);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
73 if (scalar @genes == 0){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
74 $concat = "-";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
75 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
76 print O "\t".$concat;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
77 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
78 if ($concat_accessory =~/0/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
79 print M $cl_num.$concat_accessory."\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
80 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
81 print O "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
82 print U "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
83 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
84 close(F);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
85 close(O);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
86 close(U);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
87 close(M);