CLIPSeqTools/App/export_bed.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 54 CC 6 SCAR 31.7
CC
6
Cov
0%
run
42.0
validate_args
2.0
BEGIN
2.0
CRAP 23.8
1 =head1 NAME
2  
3 CLIPSeqTools::App::export_bed - Export reads to a BED file.
4  
5 =head1 SYNOPSIS
6  
7 clipseqtools export_bed [options/parameters]
8  
9 =head1 DESCRIPTION
10  
11 Export reads to a BED file. Note that if the reads were collapsed in the
12 preprocessing step then the exported reads are also collapsed. In this case
13 the score field in the BED file corresponds to the copy number of the
14 collapsed reads e.g. if 5 reads were collapsed into 1 then the score field of
15 the BED file will be 5.
16  
17 =head1 OPTIONS
18  
19 Input options for library.
20 --driver <Str> driver for database connection (eg. mysql,
21 SQLite).
22 --database <Str> database name or path to database file for file
23 based databases (eg. SQLite).
24 --table <Str> database table.
25 --host <Str> hostname for database connection.
26 --user <Str> username for database connection.
27 --password <Str> password for database connection.
28 --records_class <Str> type of records stored in database.
29 --filter <Filter> filter library. May be used multiple times.
30 Syntax: column_name="pattern"
31 e.g. keep reads with deletions AND not repeat
32 masked AND longer than 31
33 --filter deletion="def"
34 --filter rmsk="undef"
35 --filter query_length=">31".
36 Operators: >, >=, <, <=, =, !=, def, undef
37  
38 Output
39 --o_prefix <Str> output path prefix. Script will create and add
40 extension to path. [Default: ./]
41  
42 Other options.
43 -v --verbose print progress lines and extra information.
44 -h -? --usage --help print help message
45  
46 =cut
47  
48  
49 package CLIPSeqTools::App::export_bed;
50 $CLIPSeqTools::App::export_bed::VERSION = '1.0.0';
51  
52 # Make it an app command
53 use MooseX::App::Command;
54 extends 'CLIPSeqTools::App';
55  
56  
57 #######################################################################
58 ####################### Load External modules #####################
59 #######################################################################
60 use Modern::Perl;
61 use autodie;
62 use namespace::autoclean;
63  
64  
65 #######################################################################
66 ########################## Consume Roles ##########################
67 #######################################################################
68 with
69 "CLIPSeqTools::Role::Option::Library" => {
70 -alias => { validate_args => '_validate_args_for_library' },
71 -excludes => 'validate_args',
72 },
73 "CLIPSeqTools::Role::Option::OutputPrefix" => {
74 -alias => { validate_args => '_validate_args_for_output_prefix' },
75 -excludes => 'validate_args',
76 };
77  
78  
79 #######################################################################
80 ######################## Interface Methods ########################
81 #######################################################################
82 sub validate_args {
83 my ($self) = @_;
84  
85 $self->_validate_args_for_library;
86 $self->_validate_args_for_output_prefix;
87 }
88  
89 sub run {
90 my ($self) = @_;
91  
92 warn "Starting analysis: export_bed\n";
93  
94 warn "Validating arguments\n" if $self->verbose;
95 $self->validate_args();
96  
97 warn "Creating reads collection\n" if $self->verbose;
98 my $reads_collection = $self->reads_collection;
99 $reads_collection->schema->storage->debug(1) if $self->verbose > 1;
100  
101 warn "Creating output path\n" if $self->verbose;
102 $self->make_path_for_output_prefix();
103  
104 warn "Exporting reads to BED file\n" if $self->verbose;
105 open (my $OUT, '>', $self->o_prefix.'exported_reads.bed');
106 $reads_collection->foreach_record_do( sub {
107 my ($rec) = @_;
108  
109 say $OUT join("\t",
110 $rec->rname, $rec->start, $rec->stop + 1, "-",
111 $rec->copy_number, $rec->strand_symbol);
112  
113 return 0;
114 });
115 close $OUT;
116 }
117  
118 1;