File Coverage

blib/lib/Proch/Seqfu.pm
Criterion Covered Total %
statement 32 59 54.2
branch 7 22 31.8
condition n/a
subroutine 9 13 69.2
pod 8 8 100.0
total 56 102 54.9


line stmt bran cond sub pod time code
1             package Proch::Seqfu;
2             #ABSTRACT: Helper module to support Seqfu tools
3              
4 3     3   2144 use 5.014;
  3         20  
5 3     3   15 use warnings;
  3         6  
  3         96  
6 3     3   34 use Carp qw(confess);
  3         15  
  3         214  
7 3     3   1273 use Data::Dumper;
  3         14463  
  3         192  
8 3     3   1982 use Term::ANSIColor qw(:constants);
  3         28522  
  3         5758  
9             require Exporter;
10              
11             $Proch::Seqfu::VERSION = '1.6.1';
12             $Proch::Seqfu::fu_linesize = 0;
13             $Proch::Seqfu::fu_verbose = 0;
14              
15             our @ISA = qw(Exporter);
16             our @EXPORT = qw(rc fu_printfasta fu_printfastq verbose has_seqfu seqfu_version);
17             our @EXPORT_OK = qw($fu_linesize $fu_verbose); # symbols to export on request
18              
19              
20             sub fu_printfasta {
21 0     0 1 0 my ($name, $comment, $seq) = @_;
22 0         0 my $print_comment = '';
23 0 0       0 if (defined $comment) {
24 0         0 $print_comment = ' ' . $comment;
25             }
26              
27 0         0 say '>', $name, $print_comment;
28 0         0 print split_string($seq);
29             }
30              
31             sub fu_printfastq {
32 0     0 1 0 my ($name, $comment, $seq, $qual) = @_;
33 0         0 my $print_comment = '';
34 0 0       0 if (defined $comment) {
35 0         0 $print_comment = ' ' . $comment;
36             }
37              
38 0         0 say '@', $name, $print_comment;
39 0         0 print split_string($seq) , "+\n", split_string($qual);
40             }
41              
42              
43             # Print verbose info
44             sub verbose {
45 0 0   0 1 0 if ($Proch::Seqfu::fu_verbose) {
46 0         0 say STDERR " - ", $_[0];
47             }
48             }
49              
50              
51             sub rc {
52 1     1 1 84 my $sequence = reverse($_[0]);
53 1 50       3 if (is_seq($sequence)) {
54 1 50       4 if ($sequence =~ /U/i) {
55 0         0 $sequence =~ tr/ACGURYSWKMBDHVacguryswkmbdhv/UGCAYRSWMKVHDBugcayrswmkvhdb/;
56             } else {
57 1         3 $sequence =~ tr/ACGTRYSWKMBDHVacgtryswkmbdhv/TGCAYRSWMKVHDBtgcayrswmkvhdb/;
58             }
59 1         3 return $sequence;
60             }
61             }
62              
63              
64             sub is_seq {
65 3     3 1 537 my $string = $_[0];
66 3 100       15 if ($string =~/[^ACGTRYSWKMBDHVNU]/i) {
67 1         7 return 0;
68             } else {
69 2         10 return 1;
70             }
71             }
72              
73              
74             sub split_string {
75 0     0 1 0 my $input_string = $_[0];
76 0         0 my $formatted = '';
77 0         0 my $line_width = $Proch::Seqfu::fu_linesize; # change here
78 0 0       0 return $input_string. "\n" unless ($line_width);
79 0         0 for (my $i = 0; $i < length($input_string); $i += $line_width) {
80 0         0 my $frag = substr($input_string, $i, $line_width);
81 0         0 $formatted .= $frag."\n";
82             }
83 0         0 return $formatted;
84             }
85              
86              
87             sub seqfu_version {
88 2     2 1 88 my $cmd = '';
89 2         7 eval {
90 2         4237 $cmd = `seqfu version`;
91             };
92 2         190 chomp($cmd);
93 2 50       78 if (length($@) > 0) {
    50          
94 0         0 return -2;
95             } elsif ($cmd =~/^(\d+)\.(\d+)\.?(\d+)?$/) {
96 0         0 return $cmd;
97             } else {
98 2         72 return "-" . $cmd;
99             }
100             }
101              
102              
103             sub has_seqfu {
104 1     1 1 25 my $ver = seqfu_version();
105 1 50       29 if (substr($ver, 0, 1) eq '-') {
    0          
106 1         20 return 0
107             } elsif (length($ver) > 0) {
108 0           return 1
109             } else {
110 0           return undef;
111             }
112             }
113             1;
114              
115             =pod
116              
117             =encoding UTF-8
118              
119             =head1 NAME
120              
121             Proch::Seqfu - Helper module to support Seqfu tools
122              
123             =head1 VERSION
124              
125             version 1.5.8
126              
127             =head1 Proch::Seqfu
128              
129             a legacy module for Seqfu utilities
130              
131             =head2 fu_printfasta(name, comment, seq)
132              
133             This function prints a sequence in fasta format
134              
135             =head2 fu_printfastq(name, comment, seq, qual)
136              
137             This function prints a sequence in FASTQ format
138              
139             =head2 verbose(msg)
140              
141             Print a text if $fu_verbose is set to 1
142              
143             =head2 rc(dna)
144              
145             Return the reverse complement of a string [degenerate base not supported]
146              
147             =head2 is_seq(seq)
148              
149             Check if a string is a DNA sequence, including degenerate chars.
150              
151             =head2 split_string(dna)
152              
153             Add newlines using $Proch::Seqfu::fu_linesize as line width
154              
155             =head2 seqfu_version()
156              
157             Check if a `seqfu` binary is present and returns its version if found.
158             Note this will require SeqFu > 1.13
159              
160             =head2 has_seqfu()
161              
162             If SeqFu is detected returns 1, 0 otherwise, I when detection of SeqFu version fails.
163              
164             =head1 AUTHOR
165              
166             Andrea Telatin
167              
168             =head1 COPYRIGHT AND LICENSE
169              
170             This software is Copyright (c) 2018-2023 by Andrea Telatin.
171              
172             This is free software, licensed under:
173              
174             The MIT (X11) License
175              
176             =cut
177              
178             __END__