comparison HaplophyleInBatch.pl @ 0:6f11162b6fa2 draft

planemo upload commit 11382afe87364aaafb19973470d5066229a6e34f
author dereeper
date Tue, 14 Aug 2018 08:04:23 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6f11162b6fa2
1 #!/usr/bin/perl
2
3 use strict;
4 use Switch;
5 use Getopt::Long;
6 use Bio::SeqIO;
7
8 my $HAPLOPHYLE_EXE = "java -Xmx2048m -jar /usr/local/bioinfo/sniplay/Haplophyle/NetworkCreator_fat.jar";
9 my $NEATO_EXE = "neato";
10 my $CONVERT_EXE = "convert";
11 my $RSCRIPT_EXE = "/usr/local/bioinfo/R/default/bin/Rscript";
12
13 my $usage = qq~Usage:$0 <args> [<opts>]
14 where <args> are:
15 -i, --input <input>
16 <opts>
17 -r, --rscript <R scripts in zipfile>
18 ~;
19 $usage .= "\n";
20
21 my ($infile,$r_zip);
22
23
24 GetOptions(
25 "input=s" => \$infile,
26 "rscript=s" => \$r_zip
27 );
28
29
30 die $usage
31 if ( !$infile);
32
33
34 if (-e $r_zip)
35 {
36 system("unzip $r_zip");
37 }
38
39 my %inputs;
40 my $gene;
41 my $data = "";
42 open(my $I,$infile);
43 while(<$I>)
44 {
45 if (/===(.*)===/)
46 {
47 $gene = $1;
48 }
49 else
50 {
51 $inputs{$gene}.= $_;
52 }
53 }
54 close($I);
55
56
57 foreach my $gene(keys(%inputs))
58 {
59 open(F,">$gene.distinct_haplo.fas");
60 print F $inputs{$gene};
61 close(F);
62
63 my $input = "$gene.distinct_haplo.fas";
64 my $outfile = "$gene.network.dot";
65 my $out_png = "$gene.network.png";
66
67 my $command = "$HAPLOPHYLE_EXE -in $input -out $outfile >> $gene.haplophyle.log 2>&1";
68 system($command);
69
70
71
72
73 open(OUTFILE,"$outfile");
74 open(OUTFILE2,">$outfile.vis");
75 print OUTFILE2 "var nodes = [\n";
76 open(INFILE,"$input");
77 while(<INFILE>)
78 {
79 if (/>haplo(\d+)\|(\d+)/)
80 {
81 print OUTFILE2 "{id: $1, label: 'Haplo$1',shape:'image',radius:'$2'}\n";
82 }
83 }
84 close(INFILE);
85 print OUTFILE2 "];\n";
86 print OUTFILE2 "var edges = [\n";
87 my $n = 0;
88 while(<OUTFILE>)
89 {
90 my $line = $_;
91 if (/^haplo(\d+) -- haplo(\d+)/)
92 {
93 my $from = $1;
94 my $to = $2;
95
96 print OUTFILE2 "{from: $from, to: $to,length:'7',style: 'line',color:'black',},\n";
97 }
98
99 }
100 close(OUTFILE);
101 print OUTFILE2 "];\n";
102 close(OUTFILE2);
103 }
104
105 system("zip networks.zip *network.dot");
106 #system("zip pies.zip *pie.eps");
107