@@ -124,38 +124,53 @@ sub initialize {
124124 %opts = %{$opts_ref };
125125
126126 # This is the format that aln-manipulations expects by default
127- my $default_format = " clustalw " ;
127+ my $default_format = " fasta " ;
128128
129+ =begin
129130 # assume we're getting input from standard input
130-
131- # my $in_format = $opts{"input"} || $default_format ;
132- # my $in_format;
133- # use IO::Scalar ;
134- # my $s ;
135- # my ($guesser) ;
136- # if ($file eq "STDIN") {
137- # my $line_ct = 0;
138- # my $lines;
139- # while(<>) { $lines .= $_; $line_ct++; last if $line_ct >= 100 } # read the first 100 lines
140- # $guesser = Bio::Tools::GuessSeqFormat->new( -text => $lines );
141- # } else {
142- # open $ifh, "<", $file or die $!;
143- # $guesser = Bio::Tools::GuessSeqFormat->new( -file => $file );
144- # }
145- # $in_format = $guesser->guess();
146- # die "unknown file format. Try specify with -i flag.\n" unless $in_format;
131+ my $in_format = $opts{"input"} || $default_format;
132+ my $in_format;
133+ use IO::Scalar; this dependency breaks Vonda environment
134+ my $s ;
135+ my ($guesser) ;
136+ $file = shift @ARGV ;
137+ if ($file eq "STDIN") {
138+ my $line_ct = 0;
139+ my $lines;
140+ while(<>) { $lines .= $_; $line_ct++; last if $line_ct >= 100 } # read the first 100 lines
141+ $guesser = Bio::Tools::GuessSeqFormat->new( -text => $lines );
142+ } else {
143+ open my $ifh, "<", $file or die $!;
144+ $guesser = Bio::Tools::GuessSeqFormat->new( -fh => $file );
145+ }
146+ $in_format = $guesser->guess();
147+ die "unknown file format. Try specify with -i flag.\n" unless $in_format;
147148# seek (STDIN, 0, 0);
148- # warn "$in_format\n";
149+ warn "$in_format\n";
150+ =cut
149151
150- my $in_format = $opts {' input' } || ' clustalw ' ;
152+ my $in_format = $opts {' input' } || $default_format ;
151153 if ($opts {" concat" }) {
152154# foreach my $file (glob @ARGV) {
153155 while ($file = shift @ARGV ) {
154156# warn "reading $file\n";
155157# $guesser = Bio::Tools::GuessSeqFormat->new( -file => $file);
156- # $in_format = $guesser->guess;
157- $in = Bio::AlignIO-> new(-file => $file , -format => $in_format );
158- while ($aln =$in -> next_aln()) { push @alns , $aln }
158+ # $in_format = $guesser->guess;
159+
160+ open IN, " <" , $file ;
161+ my $ct_line = 1;
162+ my $first_line ;
163+ while (<>){
164+ chomp ;
165+ if ($ct_line == 1) {
166+ $first_line = $_ ;
167+ last ;
168+ }
169+ }
170+ close IN;
171+ $in_format = ' clustalw' if $first_line =~ / CLUSTAL/ ;
172+ $in = Bio::AlignIO-> new(-file => $file , -format => $in_format );
173+ while ($aln =$in -> next_aln()) { push @alns , $aln }
159174 }
160175 } else {
161176 $file = shift @ARGV || " STDIN" ; # If no more arguments were given on the command line
@@ -171,7 +186,30 @@ sub initialize {
171186 }
172187 } else { # would throw error if format guessed wrong
173188# $in = Bio::AlignIO->new(-format => $in_format, ($file eq "STDIN")? (-fh => \*STDIN) : (-file => $file));
174- # $in = Bio::AlignIO->new(-format => $in_format, -fh => $ifh);
189+ # $in = Bio::AlignIO->new(-format => $in_format, -fh => $ifh);
190+ my $ct_line = 1;
191+ my $first_line ;
192+ if ($file eq ' STDIN' ) {
193+ while (<>){
194+ chomp ;
195+ if ($ct_line == 1) {
196+ $first_line = $_ ;
197+ last ;
198+ }
199+ }
200+ } else {
201+ open IN, " <" , $file ;
202+ while (<IN>){
203+ chomp ;
204+ if ($ct_line == 1) {
205+ $first_line = $_ ;
206+ last ;
207+ }
208+ }
209+ close IN;
210+ }
211+ $in_format = ' clustalw' if $first_line =~ / ^CLUSTAL/ ;
212+
175213 $in = Bio::AlignIO-> new(-format => $in_format , ($file eq " STDIN" )? (-fh => \*STDIN ) : (-file => $file ) );
176214 $aln = $in -> next_aln()
177215 }
0 commit comments