#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;  # include this to parse command line parameters

my $taxFile;    # fasta file to print results from
my $line; 	# holds each subsequent line one at a time

# Print usage info and exit if no command line parameters are passed
if (@ARGV < 1)  # if no command line arguments specified
{
 print "\nusage: trim.pl --file Taxonomic_Hierarchy_File \n";
 exit;
}

# Parse command line args by name and save as variable
GetOptions('file=s'  => \$taxFile );

# open the input file for reading
my $INPUT_FILE;
open ( $INPUT_FILE , '<' , $taxFile )
or die "Cannot open the input file: $taxFile: $!";


my @currLineArray;
my $outputString = "";

# iterating entirely through the taxonomic hierarchy input file...
while ( $line = <$INPUT_FILE> ) {
	
	# we only care about the tab-delimited lines within the file:
	if ( $line =~ m/\t/ ) {
		chomp $line; 	# remove newline character at end of line
		@currLineArray = split ( /\t/, $line );	# split line on tabs
		
		# if a zero occurs in any of the tab-delimited positions we can
		# ignore this line
		unless ( grep ( m/^0/i, @currLineArray ) ) {
		# unless ( $currLineArray[ 2 ] == 0 ) {
			$outputString .= $line."\n";
		}
	}
}
		
chomp $outputString;

my $OUTPUT_HANDLE;
my $outputFile = $taxFile;
$outputFile =~ s/.txt/2.txt/;

open ($OUTPUT_HANDLE , '>', $outputFile) 
or die "Cannot open the file: $outputFile: $!"."\n";

printf $OUTPUT_HANDLE $outputString;

close( $OUTPUT_HANDLE );
