comparison lib/CPT/Writer/Genomic.pm @ 1:f093e08f21f3 draft default tip

planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
author cpt
date Mon, 05 Jun 2023 02:47:24 +0000
parents
children
comparison
equal deleted inserted replaced
0:b8b8b52904a5 1:f093e08f21f3
1 package CPT::Writer::Genomic;
2 use Moose;
3 with 'CPT::Writer';
4
5 # Specific format of genomic writer
6 has 'format' => ( is => 'rw', isa => 'Str', default => 'Genbank');
7
8 sub process {
9 my ($self) = @_;
10 $self->processed_data( $self->data );
11 $self->processing_complete(1);
12 return 1;
13 }
14
15 sub write {
16 my ($self) = @_;
17 if ( $self->processing_complete ) {
18 $self->OutputFilesClass->extension( $self->suffix() );
19 my $next_output_file = $self->OutputFilesClass->get_next_file();
20 open( my $filehandle, '>', $next_output_file );
21
22 require Bio::SeqIO;
23 my $obj_type = ref $self->processed_data();
24 if(substr($obj_type,0,10) eq 'Bio::Seq::'){
25 my $outseq = Bio::SeqIO->new(
26 -fh => $filehandle,
27 -format => $self->format(),
28 );
29 $outseq->write_seq( $self->processed_data );
30 }elsif(substr($obj_type,0,10) eq 'Bio::SeqIO'){
31 my $outseq = Bio::SeqIO->new(
32 -fh => $filehandle,
33 -format => $self->format(),
34 );
35 while (my $inseq = $self->processed_data()->next_seq()) {
36 $outseq->write_seq($inseq);
37 }
38 }elsif(substr($obj_type,0,8) eq 'Bio::Seq'){
39 my $outseq = Bio::SeqIO->new(
40 -fh => $filehandle,
41 -format => $self->format(),
42 );
43 $outseq->write_seq( $self->processed_data );
44 }elsif(ref $self->processed_data eq 'ARRAY'){
45 # Assume array of genomes
46 my $outseq = Bio::SeqIO->new(
47 -fh => $filehandle,
48 -format => $self->format(),
49 );
50 foreach my $inseq(@{$self->processed_data}){
51 $outseq->write_seq($inseq);
52 }
53 }else{
54 print $filehandle $self->processed_data();
55 }
56 close($filehandle);
57 }
58 else {
59 warn
60 "Write called but processing was not marked as complete. Not writing";
61 }
62 }
63
64 sub suffix {
65 my ($self) = @_;
66 my %suffix_map = (
67 'abi' => 'abi',
68 'ace' => 'ace',
69 'agave' => 'agave',
70 'alf' => 'alf',
71 'asciitree' => 'txt',
72 'bsml' => 'bsml',
73 'bsml_sax' => 'bsml',
74 'chadoxml' => 'xml',
75 'chaos' => 'chaos',
76 'chaosxml' => 'xml',
77 'ctf' => 'ctf',
78 'embl' => 'emb',
79 'entrezgene' => 'asn1',
80 'excel' => 'xls',
81 'exp' => 'exp',
82 'fasta' => 'fa',
83 'fastq' => 'fastq',
84 'game' => 'xml',
85 'gcg' => 'gcg',
86 'genbank' => 'gbk',
87 'interpro' => 'xml',
88 'kegg' => 'kegg',
89 'largefasta' => 'lfa',
90 'lasergene' => 'lasergene',
91 'locuslink' => 'll_tmpl',
92 'phd' => 'phred',
93 'pir' => 'pir',
94 'pln' => 'pln',
95 'qual' => 'phred',
96 'raw' => 'txt',
97 'scf' => 'scf',
98 'seqxml' => 'xml',
99 'strider' => 'strider',
100 'swiss' => 'sp',
101 'tab' => 'tsv',
102 'tigr' => 'xml',
103 'tigrxml' => 'xml',
104 'tinyseq' => 'xml',
105 'ztr' => 'ztr',
106 );
107
108 if($suffix_map{lc($self->format())}){
109 return $suffix_map{lc($self->format())};
110 }else{
111 return 'unknown';
112 }
113 }
114
115 no Moose;
116 1;
117
118 __END__
119
120 =pod
121
122 =encoding UTF-8
123
124 =head1 NAME
125
126 CPT::Writer::Genomic
127
128 =head1 VERSION
129
130 version 1.99.4
131
132 =head1 AUTHOR
133
134 Eric Rasche <rasche.eric@yandex.ru>
135
136 =head1 COPYRIGHT AND LICENSE
137
138 This software is Copyright (c) 2014 by Eric Rasche.
139
140 This is free software, licensed under:
141
142 The GNU General Public License, Version 3, June 2007
143
144 =cut