1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib ("$FindBin::Bin/../PerlLib");
use Gene_obj;
use Fasta_reader;
use GFF3_utils;
use Carp;
use Nuc_translator;
use Getopt::Long qw(:config posix_default no_ignore_case bundling pass_through);
my $usage = <<__EOUSAGE__;
####################################################
#
# Required:
#
# --gff3 <string> gff3 file
#
# --fasta <string> fasta file corresponding to gff3 file
#
##
# Optional:
#
# --seqType <string> prot|CDS|cDNA|gene, default=prot
#
# --genetic_code <string> universal (default)
# Euplotes, Tetrahymena, Candida
# Acetabularia, Mitochondrial-Canonical
# Mitochondrial-Vertebrates, Mitochondrial-Arthropods
# Mitochondrial-Echinoderms, Mitochondrial-Molluscs
# Mitochondrial-Ascidians, Mitochondrial-Nematodes
# Mitochondrial-Platyhelminths,Mitochondrial-Yeasts
# Mitochondrial-Euascomycetes, Mitochondrial-Protozoans
#
###################################################
__EOUSAGE__
;
my $gff3_file;
my $fasta_db;
my $seq_type = 'prot';
my $genetic_code = '';
&GetOptions ( 'gff3=s' => \$gff3_file,
'fasta=s' => \$fasta_db,
'seqType=s' => \$seq_type,
'genetic_code=s' => \$genetic_code,
);
unless ($gff3_file && $fasta_db) {
die $usage;
}
unless ($seq_type =~ /^(prot|CDS|cDNA|gene)$/) {
die "Error, don't understand sequence type [$seq_type]\n\n$usage";
}
if ($genetic_code) {
&Nuc_translator::use_specified_genetic_code($genetic_code);
}
## read genome
my $fasta_reader = new Fasta_reader($fasta_db);
my %genome = $fasta_reader->retrieve_all_seqs_hash();
my $gene_obj_indexer_href = {};
## associate gene identifiers with contig id's.
my $contig_to_gene_list_href = &GFF3_utils::index_GFF3_gene_objs($gff3_file, $gene_obj_indexer_href);
foreach my $asmbl_id (sort keys %$contig_to_gene_list_href) {
my $genome_seq = $genome{$asmbl_id} or die "Error, no sequence for $asmbl_id";
my @gene_ids = @{$contig_to_gene_list_href->{$asmbl_id}};
foreach my $gene_id (@gene_ids) {
my $gene_obj_ref = $gene_obj_indexer_href->{$gene_id};
my %params;
if ($seq_type eq "gene") {
$params{unspliced_transcript} = 1;
}
$gene_obj_ref->create_all_sequence_types(\$genome_seq, %params);
my $counter = 0;
foreach my $isoform ($gene_obj_ref, $gene_obj_ref->get_additional_isoforms()) {
$counter++;
my $orientation = $isoform->get_orientation();
my ($model_lend, $model_rend) = sort {$a<=>$b} $isoform->get_model_span();
my ($gene_lend, $gene_rend) = sort {$a<=>$b} $isoform->get_gene_span();
my $isoform_id = $isoform->{Model_feat_name};
my $seq = "";
if ($seq_type eq "prot") {
$seq = $isoform->get_protein_sequence();
}
elsif ($seq_type eq "CDS") {
$seq = $isoform->get_CDS_sequence();
}
elsif ($seq_type eq "cDNA") {
$seq = $isoform->get_cDNA_sequence();
}
elsif ($seq_type eq "gene" && $counter == 1) {
$seq = $isoform->get_gene_sequence();
}
unless ($seq) {
print STDERR "-warning, no $seq_type sequence for $isoform_id\n";
next;
}
$seq =~ s/(\S{60})/$1\n/g; # make fasta format
chomp $seq;
my $com_name = $isoform->{com_name} || "";
if ($com_name eq $isoform_id) { $com_name = ""; } # no sense in repeating it
my $locus = $isoform->{pub_locus};
my $model_locus = $isoform->{model_pub_locus};
my $locus_string = "";
if ($model_locus) {
$locus_string .= $model_locus;
}
if ($locus) {
$locus_string .= " $locus";
}
if ($locus_string) {
$locus_string .= " "; # add spacer
}
#if ($seq_type eq 'prot' || $seq_type eq 'CDS') { # this was a bad idea, just use the original id.
# $isoform_id = "cds.$isoform_id";
#}
print ">$isoform_id $gene_id $locus_string $com_name $asmbl_id:$model_lend-$model_rend($orientation)\n$seq\n";
}
}
}
exit(0);
|