annotate Perl/generateConfig.pl @ 15:dbde253606c5 draft default tip

Uploaded
author dereeper
date Wed, 11 Dec 2024 08:25:06 +0000
parents 5a5c9a6b047b
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 use warnings;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
5 use YAML qw(DumpFile);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
6
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
7 use Cwd;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
8 my $dir = getcwd;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 my $zip = $ARGV[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 my $list = $ARGV[1];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 my $out = $ARGV[2];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 my $zip_fasta = $ARGV[3];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16 $list =~s/NZ_//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17 my @list_ids = split(/,/,$list);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19 my %data = ();
14
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
20 # case list of accessions
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
21 if ($list ne 'None'){
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
22 foreach my $id(@list_ids){
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
23 push @{$data{"ids"}}, "$id";
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
24 }
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 # case fasta+gff
14
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
27 elsif ($zip ne "None" && $zip_fasta ne "None"){
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 system("rm -rf $zip.genomeszip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 mkdir("$zip.genomeszip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 chdir("$zip.genomeszip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 system("cp -rf $zip ./genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 system("cp -rf $zip_fasta ./fasta_genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 system("unzip fasta_genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 system("unzip genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 unlink("fasta_genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 unlink("genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 open(LS,"ls *gff |");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 while(my $line = <LS>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 chomp($line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 my $concat = "$zip.genomeszip/".$line;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 if ($line =~/(.*)\.gff/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 my $name = $1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 if ($concat =~/\w+/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 $data{"input_genomes"}{"$name"}{"gff3"} = "$concat";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 $data{"input_genomes"}{"$name"}{"name"} = "$name";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 close(LS);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 open(LS,"ls *fasta |");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 while(my $line = <LS>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 chomp($line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 my $concat = "$zip.genomeszip/".$line;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 if ($line =~/(.*)\.fasta/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 my $name = $1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 if ($concat =~/\w+/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 $data{"input_genomes"}{"$name"}{"fasta"} = "$concat";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 close(LS);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 elsif ($zip ne "None"){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 system("rm -rf $zip.genomeszip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 mkdir("$zip.genomeszip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 chdir("$zip.genomeszip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 my $head = `head -1 $zip`;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70 if ($head =~/LOCUS/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71 push @{$data{"input_genbanks"}}, "$zip";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 else{
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 system("cp -rf $zip ./genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75 system("unzip genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 unlink("genomes.zip");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 open(LS,"ls |");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 while(my $line = <LS>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 chomp($line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80 my $concat = "$zip.genomeszip/".$line;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81 if ($concat =~/\w+/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82 push @{$data{"input_genbanks"}}, "$concat";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85 close(LS);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
88 #else{
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
89 # push @{$data{"input_genbanks"}}, "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
90 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
91 chdir($dir);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
92
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
93 DumpFile($out, \%data);