#!/usr/bin/perl -w 
### extract fasta files which fasta name contain "mitochondri" key word
 
open TXT1 , "<./nt" or die "can't open file1:$!";;

$out_file_1 = "./nt_mito_fasta.txt";

system "rm $out_file_1";
open OUT1 , ">>./$out_file_1";

$j = 0;

while(<TXT1>)
{
	chomp;

	if($_=~/^\>/)
	{
		$m = 0;
		if($_=~/^\>.*mitochondri.*/ig)
		{

			$j = 1;	
			$m = 1;
			print OUT1 "$_\n";		
		}

	}else{$j = 0;}
	
	if($j == 0 && $m == 1)
	{
		print OUT1 "$_\n";	
	
	}

}

close TXT1;

### extract gi number from fasta files
 
open TXT2 , "<./nt_mito_fasta.txt" or die "can't open file1:$!";;

$out_file_2 = "./nt_mito_gi.sh";

system "rm $out_file_2";
open OUT2 , ">>./$out_file_2";

while(<TXT2>)
{
	chomp;

	if($_=~/^\>gi\|(\d+)\|.*/)
	{
		
		print OUT2 "efetch \-db nucleotide \-id $1 \-format gb \>\> flat_file.txt\n";		
		
	}
	
}

close TXT2;






