annotate Perl/ConvertPGAPMatrix.pl @ 13:152d7c43478b draft default tip

Uploaded
author dereeper
date Thu, 30 May 2024 20:07:55 +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(F,$matrix);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 my $firstline = <F>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 $firstline =~s/\n//g;$firstline =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 my @infos = split(/\t/,$firstline);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 print O "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 print U "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 print M "Gene";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 for (my $j=1; $j <= $#infos; $j++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 my $gbfile = $infos[$j];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 $gbfile =~s/\"//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 $gbfile =~s/\.gb\.filt//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 $gbfile =~s/\.gb\.rmdup//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 my $strain = $strains_of_gb{$gbfile};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 print O "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 print U "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 print M "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 $nb_strains++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 print O $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 close(O);