script/compress-db.pl untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 108 CC 2 SCAR 9.3
CC
2
Cov
0%
BEGIN
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.5
1 #!/usr/bin/env perl
2 # PODNAME: compress-db.pl
3 # ABSTRACT: Post-process assembler for transcript enrichment using 42
4  
5 use Modern::Perl '2011';
6 use autodie;
7  
8 use Getopt::Euclid qw(:vars);
9 use Path::Class qw(file dir);
10  
11 ## no critic (RequireLocalizedPunctuationVars)
12 BEGIN{
13 $ENV{Smart_Comments} = $ARGV_verbosity
14 ? join q{ }, map { '#' x (2 + $_) } 1..$ARGV_verbosity
15 : q{}
16 ;
17 }
18 ## use critic
19  
20 use Smart::Comments -ENV;
21 use Config::Any;
22  
23 use Bio::MUST::Core;
24 use Bio::MUST::Drivers;
25 use aliased 'Bio::MUST::Core::Ali';
26 use aliased 'Bio::MUST::Core::Seq';
27 use aliased 'Bio::MUST::Core::SeqId';
28 use aliased 'Bio::MUST::Drivers::Cap3';
29 use aliased 'Bio::MUST::Apps::Debrief42';
30  
31  
32 # read configuration file
33 my $config = Config::Any->load_files( {
34 files => [ file($ARGV_config) ],
35 flatten_to_hash => 1,
36 use_ext => 1,
37 }
38 );
39  
40 # build Debrief42 object
41 my $debrief42 = Debrief42->new(
42 config => $config->{$ARGV_config},
43 report_dir => $ARGV_indir,
44 );
45  
46 ### Reading Tax-Reports...
47 my $run_report = $debrief42->run_report;
48 my @orgs = $run_report->all_orgs;
49  
50 # create output dir named after input dir and settings
51 my $dirname = dir($ARGV_indir)->stringify; # ignore trailing '/' if any
52 my $outdir = dir($dirname . '-compress' . "-o$ARGV_cap3_o" . "-p$ARGV_cap3_p");
53  
54 ### Creating outdir: $outdir->stringify
55 $outdir->mkpath();
56  
57 for my $org (@orgs) {
58  
59 ### Processing: $org
60 my $org_report = $run_report->org_report_for($org);
61  
62 my $ali = Ali->new;
63  
64 OUTFILE:
65 for my $new_seqs (sort $org_report->all_new_seqs_by_outfile) {
66 # TODO: try to avoid sort by making method deterministic (not easy)
67  
68 # collect new_seqs for current org and outfile
69 my $outfile;
70 my @seqs2cap;
71 for my $new_seq ( @{$new_seqs} ) {
72 $outfile //= $new_seq->outfile;
73 my $seq_id = SeqId->new( full_id => $new_seq->seq_id )->accession;
74 my $seq = $new_seq->seq;
75 push @seqs2cap, Seq->new( seq_id => $seq_id, seq => $seq );
76 }
77  
78 # proceed only for combos with at least two new_seqs
79 # otherwise add lone seq to database
80 if (@seqs2cap < 2) {
81 $ali->add_seq( shift @seqs2cap );
82 next OUTFILE;
83 }
84  
85 # try to cap new_seqs for current org and outfile
86 my $cap = Cap3->new(
87 seqs => \@seqs2cap,
88 cap3_args => { -o => $ARGV_cap3_o, -p => $ARGV_cap3_p },
89 );
90  
91 # add singlet seqs to database
92 my @singlets = $cap->all_singlets;
93 $ali->add_seq($_) for @singlets;
94  
95 # proceed only for combos with contigs of new_seqs
96 my @contigs = $cap->all_contigs;
97 next OUTFILE unless @contigs;
98  
99 ### $outfile
100 for my $contig (@contigs) {
101 my @ids = map { $_->full_id }
102 @{ $cap->seq_ids_for( $contig->full_id ) };
103 ### $contig
104 ### @ids
105 my $contig_id = shift(@ids) . '+' . @ids;
106 ### $contig_id
107 my $contig_seq = $contig->seq;
108 ### $contig_seq
109  
110 # add contig seq to database
111 $ali->add_seq(
112 Seq->new( seq_id => $contig_id, seq => $contig_seq )
113 );
114 }
115 }
116  
117 # store contig database for org
118 (my $outfile = $org) =~ tr/ /_/;
119 $outfile .= '_new_cap3.fasta';
120 $ali->store( file($outdir, $outfile) );
121 }
122  
123 __END__