comparison PGAP-1.2.1/Converter_finished.pl @ 0:83e62a1aeeeb draft

Uploaded
author dereeper
date Thu, 24 Jun 2021 13:51:52 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:83e62a1aeeeb
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Getopt::Std;
5
6 my %opt;
7 getopts('S:I:O:',\%opt);
8
9 my @usage=qq(
10 Version: 2016042201
11 Usage: perl Converter_finished.pl [options]
12
13 Options:
14
15 -S String Input the strains nickname,
16 If 2 or more, join them with '+',
17 For example: CT18+NC_011834+SPA
18 -I String Input file directory
19 -O String Output file directory
20 );
21
22 if (!scalar(keys %opt))
23 {
24 print join("\n",@usage)."\n";
25 exit;
26 }
27
28 my @sp;
29 if (exists($opt{"S"}))
30 {
31 @sp=split(/\+/,$opt{"S"});
32 }else
33 {
34 print "-S could not be empty!";
35 print join("\n",@usage)."\n";
36 exit;
37 }
38
39 my $output;
40 if (exists($opt{"O"}))
41 {
42 $output=$opt{"O"};
43 }else
44 {
45 print "-O could not be empty!";
46 print join("\n",@usage)."\n";
47 exit;
48 }
49
50 my $input;
51 if (exists($opt{"I"}))
52 {
53 $input=$opt{"I"};
54 }else
55 {
56 print "-I could not be empty!";
57 print join("\n",@usage)."\n";
58 exit;
59 }
60
61 my $sp;
62 my $line;
63 my @row;
64 my @tmp;
65 my %hash;
66 my $flag;
67 my $file;
68
69
70 if ((-e $output) and ((-d $output)))
71 {
72 }else
73 {
74 mkdir($output);
75 }
76
77 if ($input!~/\/$/)
78 {
79 $input=$input."/";
80 }
81
82
83 if ($output!~/\/$/)
84 {
85 $output=$output."/";
86 }
87
88
89 foreach $sp (@sp)
90 {
91 %hash=();
92 $file=$input.$sp.".faa";
93 open(F,$file) or die "could not open $file";
94 open(R,">$output$sp.pep");
95 while ($line=<F>)
96 {
97 if ($line=~/^>/)
98 {
99 @row=split(/\|/,$line);
100 print R ">$row[1]\n";
101 }else
102 {
103 print R $line;
104 }
105 }
106 close(F);
107 close(R);
108
109 $file=$input.$sp.".ptt";
110 open(F,"$file") or die "could not open $file";
111 open(R,">$output$sp.function");
112 $_=<F>;
113 $_=<F>;
114 $_=<F>;
115 while ($line=<F>)
116 {
117 chomp($line);
118 @row=split(/\t/,$line);
119 print R $row[3]."\t".$row[7]."\t".$row[8]."\n";
120 @tmp=split(/\.\./,$row[0]);
121 if ($row[1] eq "+")
122 {
123 $hash{$tmp[0]."-".$tmp[@tmp-1]}=$row[3];
124 }else
125 {
126 $hash{"c".$tmp[@tmp-1]."-".$tmp[0]}=$row[3];
127 }
128 }
129 close(R);
130 close(F);
131
132 $file=$input.$sp.".ffn";
133 open(F,"$file") or die "could not open $file";;
134 open(R,">$output/$sp.nuc");
135 while ($line=<F>)
136 {
137 if ($line=~/^>/)
138 {
139 my $key=&getKey($line);
140 if (exists($hash{$key}))
141 {
142 $flag=1;
143 print R ">$hash{$key}\n";
144 }else
145 {
146 $flag=0;
147 }
148 }else
149 {
150 if ($flag)
151 {
152 print R $line;
153 }
154 }
155 }
156 close(R);
157 close(F);
158 }
159
160 sub getKey()
161 {
162 (my $line)=@_;
163 my @tmp;
164 my $strand;
165 chomp($line);
166 @tmp=split(/ /,$line);
167 @tmp=split(/\:/,$tmp[0]);
168
169 if($tmp[@tmp-1]=~/c/)
170 {
171 $strand="-";
172 }else
173 {
174 $strand="+";
175 }
176 $_=$tmp[@tmp-1];
177 s/c//g;
178 s/ //g;
179 @tmp=split(/\,|-/,$_);
180 @tmp=sort{$a<=>$b} @tmp;
181 if($strand eq "-")
182 {
183 return "c".$tmp[@tmp-1]."-".$tmp[0];
184 }else
185 {
186 return $tmp[0]."-".$tmp[@tmp-1];
187 }
188 }