]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/find_genes
added find_genes
[biopieces.git] / bp_bin / find_genes
1 #!/usr/bin/env perl
2
3 # Copyright (C) 2007-2009 Martin A. Hansen.
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 # http://www.gnu.org/copyleft/gpl.html
20
21
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
23
24 # Find genes in sequences in stream.
25
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27
28
29 use warnings;
30 use strict;
31 use Data::Dumper;
32 use Maasha::Common;
33 use Maasha::Biopieces;
34 use Maasha::Filesys;
35
36
37 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
38
39
40 my ( $options, $in, $out, $record, $tmp_dir, $tmp_file, $fh_out, $fh_in, $entry, $chunk, @lines, $line, $s_id, $type, $s_beg, $s_end, $strand, @fields );
41
42 $options = Maasha::Biopieces::parse_options();
43
44 $in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
45 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
46
47 $tmp_dir  = Maasha::Biopieces::get_tmpdir();
48 $tmp_file = "$tmp_dir/tmp.seq";
49 $fh_out   = Maasha::Filesys::file_write_open( $tmp_file );
50
51 while ( $record = Maasha::Biopieces::get_record( $in ) )
52 {
53     if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) {
54         Maasha::Fasta::put_entry( $entry, $fh_out );
55     }
56
57     Maasha::Biopieces::put_record( $record, $out );
58 }
59
60 Maasha::Common::run( "draft_prodigal.pl", "< $tmp_file > $tmp_file.out 2> /dev/null" );
61
62 $fh_in = Maasha::Filesys::file_read_open( "$tmp_file.out" );
63
64 $/ = "//\n";
65
66 while ( $chunk = <$fh_in> )
67 {
68     chomp $chunk;
69
70     @lines = split /\n/, $chunk;
71
72     $line = shift @lines;
73
74     if ( $line =~ /.*>(.+)/ )
75     {
76         $s_id = $1;
77
78         foreach $line ( @lines )
79         {
80             @fields = split " ", $line;
81
82             $type   = $fields[ 0 ];
83
84             if ( $fields[ 1 ] =~ /complement/ ) {
85                 $strand = "-"; 
86             } else {
87                 $strand = "+"; 
88             }
89
90             if ( $fields[ 1 ] =~ /(\d+)\.\.>?(\d+)/ )
91             {
92                 $s_beg = $1;
93                 $s_end = $2;
94             }
95             else
96             {
97                 Maasha::Common::error( qq(BAD locator: $line) );
98             }
99
100             $record = {
101                 S_ID   => $s_id,
102                 S_BEG  => $s_beg - 1,
103                 S_END  => $s_end - 1,
104                 Q_ID   => $type,
105                 STRAND => $strand,
106             };
107
108             Maasha::Biopieces::put_record( $record, $out );
109         }
110     }
111     else
112     {
113         Maasha::Commom::error( qq(BAD definition: $line) );
114     }
115 }
116
117 close $fh_in;
118
119 $/ = "\n";
120
121 Maasha::Biopieces::close_stream( $in );
122 Maasha::Biopieces::close_stream( $out );
123
124
125 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
126
127
128 BEGIN
129 {
130     Maasha::Biopieces::status_set();
131 }
132
133
134 END
135 {
136     Maasha::Biopieces::status_log();
137 }
138
139
140 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
141
142
143 __END__