annotate chewBBACA.pl @ 2:872ed5ee7b98 draft default tip

Update to xml file
author iss
date Fri, 10 May 2019 07:04:48 -0400
parents a3b5bee8ae1b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
1 #!/usr/bin/env perl
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
2 ## A wrapper script to call chewBBACA.py and collect its output
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
3 use strict;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
4 use warnings;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
5 use Cwd;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
6 use English;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
7 use File::Copy;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
8 use File::Basename;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
9
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
10 # Parse arguments
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
11 my ($myFunction,
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
12 $input1,
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
13 $input1_names,
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
14 $output,
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
15 $python) = @ARGV;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
16
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
17 # Run program
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
18 my $abs_path = Cwd::abs_path($PROGRAM_NAME);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
19 my $scriptdir = dirname($abs_path);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
20
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
21 prepareEnvironment($input1,$input1_names,"input_dir");
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
22 runChewBBACA();
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
23 collectOutput();
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
24 exit(0);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
25
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
26 # Run chewBBACA
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
27 sub runChewBBACA {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
28 my $abs_path = Cwd::abs_path($PROGRAM_NAME);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
29 my $scriptdir = dirname($abs_path);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
30 my $createschemadir = "$scriptdir/createschema";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
31 my $allelecalldir = "$scriptdir/allelecall";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
32 my $SchemaEvaluatordir = "$scriptdir/SchemaEvaluator";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
33 my $utilsdir = "$scriptdir/utils";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
34 my $newpath = "PATH=$ENV{PATH}:$createschemadir:$allelecalldir:$SchemaEvaluatordir:$utilsdir";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
35 my $result = system("$newpath; $python");
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
36 return 0;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
37 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
38
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
39 # Run prepareEnvironment, create the directory $indir with symlinks to the files listed in $inlist
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
40 sub prepareEnvironment {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
41 my ($inlist, $inlist_names, $indir) = @_;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
42 if ($inlist ne "NULL") {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
43 mkdir($indir);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
44 my @inputs = split(',', $inlist);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
45 if ($inlist_names ne "NULL") {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
46 my @inputs_names = split(',', $inlist_names);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
47 for my $i ( 0 .. $#inputs ){
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
48 my $name = $inputs_names[$i];
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
49 $name =~ s/ /_/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
50 $name =~ s/\//_/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
51 $name =~ s/\(/_/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
52 $name =~ s/\)/_/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
53 $name =~ s/\[/_/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
54 $name =~ s/\]/_/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
55 $name =~ s/\{/_/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
56 $name =~ s/\}/_/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
57 symlink($inputs[$i], $indir . "/" . $name);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
58 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
59 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
60 else {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
61 foreach my $i (@inputs){
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
62 symlink($i, $indir . "/" . basename($i));
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
63 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
64 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
65 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
66 return 0;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
67 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
68
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
69 # Collect output
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
70 sub collectOutput{
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
71 # CreateSchema
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
72 if ($myFunction eq "CreateSchema") {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
73 my($dataname, $datadir, $datasuffix) = fileparse($output,qr/\.[^.]*/);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
74 my @fasta_files = glob "output_dir/*.fasta";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
75 my $dest_dir = $datadir . $dataname . "/";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
76 mkdir($dest_dir);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
77 open(my $fh1, '>', $output) or die "Could not open file '$output' $!";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
78 my $new_fasta_file = "";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
79 foreach my $fasta_file (@fasta_files) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
80 $new_fasta_file = $dest_dir . basename($fasta_file);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
81 print $fh1 "$new_fasta_file\n";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
82 move($fasta_file, $new_fasta_file) or die "Could not move $fasta_file: $!\n";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
83 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
84 close $fh1;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
85 my @short_fasta_files = glob "output_dir/short/*.fasta";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
86 my $short_dest_dir = $datadir . $dataname . "/short/";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
87 mkdir($short_dest_dir);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
88 foreach my $short_fasta_file (@short_fasta_files) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
89 move($short_fasta_file, $short_dest_dir) or die "Could not move $short_fasta_file: $!\n";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
90 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
91 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
92 # AlleleCall
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
93 if ($myFunction eq "AlleleCall") {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
94 my @outputs = split(',', $output);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
95 my @statistics = glob "output_dir/results_*/results_statistics.tsv";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
96 if (@statistics == 1) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
97 move($statistics[0], $outputs[0])
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
98 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
99 my @contigsinfo = glob "output_dir/results_*/results_contigsInfo.tsv";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
100 if (@contigsinfo == 1) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
101 move($contigsinfo[0], $outputs[1])
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
102 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
103 my @alleles = glob "output_dir/results_*/results_alleles.tsv";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
104 if (@alleles == 1) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
105 move($alleles[0], $outputs[2])
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
106 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
107 my @logginginfo = glob "output_dir/results_*/logging_info.txt";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
108 if (@logginginfo == 1) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
109 move($logginginfo[0], $outputs[3])
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
110 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
111 my @repeatedloci = glob "output_dir/results_*/RepeatedLoci.txt";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
112 if (@repeatedloci == 1) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
113 move($repeatedloci[0], $outputs[4])
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
114 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
115 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
116 # SchemaEvaluator
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
117 if ($myFunction eq "SchemaEvaluator") {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
118 my($dataname, $datadir, $datasuffix) = fileparse($output,qr/\.[^.]*/);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
119 my @output_files = glob "output_rms/*.*";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
120 my $dest_dir = $dataname . "/";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
121 mkdir($dest_dir);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
122 my $new_output_file = "";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
123 foreach my $output_file (@output_files) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
124 $new_output_file = $dest_dir . basename($output_file);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
125 move($output_file, $new_output_file) or die "Could not move $output_file: $!\n";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
126 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
127 open(my $fh2, '<', $dest_dir . "SchemaEvaluator.html") || die "File not found";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
128 my @lines = <$fh2>;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
129 close($fh2);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
130 my @newlines;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
131 foreach(@lines) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
132 $_ =~ s/\.\.\/\.\.\/\.\.\/.*?\/database\/files\/...\/dataset/dataset/g;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
133 push(@newlines,$_);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
134 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
135 # write the html to the Galaxy output file
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
136 #open($fh2, '>', $output) || die "File not found";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
137 #print $fh2 @newlines;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
138 #close($fh2);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
139 my @html_output_files = glob "output_rms/genes_html/*.*";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
140 my $html_dest_dir = $dest_dir . "genes_html/";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
141 mkdir($html_dest_dir);
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
142 foreach my $html_output_file (@html_output_files) {
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
143 move($html_output_file, $html_dest_dir) or die "Could not move $html_output_file: $!\n";
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
144 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
145 my $cmd = `tar -cpf $output $dest_dir`;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
146 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
147 return 0;
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
148 }
a3b5bee8ae1b Uploaded
iss
parents:
diff changeset
149