annotate Perl/ConvertPanarooMatrix.pl @ 5:4157f435fa89 draft

Uploaded
author dereeper
date Thu, 30 May 2024 12:11:25 +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 my %corr;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 open(D,"ls $indir/*rmdup.gff |");
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 open(F,"$file");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 my @infos = split(/\t/,$_);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 if ($infos[2] eq 'CDS' && /ID=([^;]*);.*protein_id=([^;]*);/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 my $id = $1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 my $protid = $2;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 $corr{$id} = $protid;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 close(D);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 my $cl_num = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 my $nb_strains = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 open(O,">$out");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 open(U,">$out.upsetr.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 open(M,">$out.accessory_01matrix.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 open(F,$matrix);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 my $firstline = <F>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 $firstline =~s/\n//g;$firstline =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 my @infos = split(/,/,$firstline);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 print O "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 print U "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 print M "Gene";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 for (my $j=14; $j <= $#infos; $j++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 my $gbfile = $infos[$j];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 $gbfile =~s/\"//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 $gbfile =~s/\.gb\.filt//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 $gbfile =~s/\.gb\.rmdup//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 my $strain = $strains_of_gb{$gbfile};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 print O "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 print U "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 print M "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 $nb_strains++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 print U "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 print M "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 $cl_num++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 my @infos = split(/,/,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70 print O $cl_num;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71 print U $cl_num;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 my $concat_accessory = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 for (my $i = 14; $i <= $#infos; $i++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 my $val = $infos[$i];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75 $val =~s/\"//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 if ($val =~/\w+/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 print U "\t1";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 $concat_accessory .= "\t1";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80 else{
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81 print U "\t0";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82 $concat_accessory .= "\t0";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84 my @genes = split(/;/,$val);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85 my $concat = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86 foreach my $gene(@genes){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 my $prot_id = $corr{$gene};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
88 if (!$prot_id){$prot_id = $gene;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
89 $concat .= "$prot_id,"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
90 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
91 chop($concat);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
92 if (scalar @genes == 0){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
93 $concat = "-";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
94 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
95 print O "\t".$concat;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
96 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
97 if ($concat_accessory =~/0/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
98 print M $cl_num.$concat_accessory."\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
99 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
100 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
101 print U "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
102 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
103 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
104 close(O);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
105 close(U);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
106 close(M);