$faa = $ARGV[0];
$feature = $ARGV[1];

open (FEATURE, "< $feature");

while (<FEATURE>) {
    if (/^CDS/) {
        @a = split /\t/;
	$chromosomeOrPlasmid = $a[4];
	$start = $a[7];
	$end = $a[8];
	$accession = $a[10];

	if ($chromosomeOrPlasmid eq "chromosome") {
	    $position{$accession} = $start;
	}
    }
}
close (FEATURE);
open (FAA, "< $faa");

while (<FAA>) {
    if (/^>(\S+)/) {
        $accession = $1;

	if ($position{$accession}) {
	    print ">$position{$accession}\n";
	    $sequence = 1;
	}
	else {
	    $sequence = 0;
	}
    }
    elsif ($sequence == 1) {
        print $_;
    }
}
close (FAA);

