annotate PanExplorer_workflow/Perl/ConvertPGAPMatrix.pl @ 2:97e4e3e818b6 draft

Uploaded
author dereeper
date Thu, 30 May 2024 11:48:09 +0000
parents 032f6b3806a3
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 my %corr;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
22 open(D,"ls $indir/*rmdup.gff |");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
23 while(<D>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
24 my $file = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
25 open(F,"$file");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
26 while(<F>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
27 my @infos = split(/\t/,$_);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
28 if ($infos[2] eq 'CDS' && /ID=([^;]*);.*protein_id=([^;]*);/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
29 my $id = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
30 my $protid = $2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
31 $corr{$id} = $protid;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
32 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
33 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
34 close(F);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
35 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
36 close(D);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
37
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
38 my $cl_num = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
39 my $nb_strains = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
40 open(O,">$out");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
41 open(F,$matrix);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
42 my $firstline = <F>;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
43 $firstline =~s/\n//g;$firstline =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
44 my @infos = split(/\t/,$firstline);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
45 print O "ClutserID";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
46 print U "ClutserID";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
47 print M "Gene";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
48 for (my $j=1; $j <= $#infos; $j++){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
49 my $gbfile = $infos[$j];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
50 $gbfile =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
51 $gbfile =~s/\.gb\.filt//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
52 $gbfile =~s/\.gb\.rmdup//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
53
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
54 my $strain = $strains_of_gb{$gbfile};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
55 print O "\t".$strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
56 print U "\t".$strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
57 print M "\t".$strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
58 $nb_strains++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
59 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
60 print O "\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
61 while(<F>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
62 print O $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
63 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
64 close(F);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
65 close(O);