Skip to content

Commit

Permalink
simplify_genbank_array
Browse files Browse the repository at this point in the history
  • Loading branch information
daisieh committed Mar 18, 2015
1 parent 6d75dd0 commit 624acfd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
23 changes: 21 additions & 2 deletions lib/Genbank.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BEGIN {
# Inherit from Exporter to export functions and variables
our @ISA = qw(Exporter);
# Functions and variables which are exported by default
our @EXPORT = qw(parse_genbank sequence_for_interval sequin_feature stringify_feature parse_feature_desc parse_interval parse_qualifiers within_interval write_sequin_tbl feature_table_from_genbank set_sequence get_sequence get_name write_features_as_fasta clone_features);
our @EXPORT = qw(parse_genbank sequence_for_interval sequin_feature stringify_feature parse_feature_desc parse_interval parse_qualifiers within_interval write_sequin_tbl feature_table_from_genbank set_sequence get_sequence get_name write_features_as_fasta clone_features simplify_genbank_array);
# Functions and variables which can be optionally exported
our @EXPORT_OK = qw();
}
Expand Down Expand Up @@ -99,6 +99,25 @@ sub parse_genbank {
return \@gene_array;
}

sub simplify_genbank_array {
my $gene_array = shift;

my @simplified_array = ();
foreach my $feat (@$gene_array) {
if ($feat->{'type'} =~ /gene|source/) {
my @newcontains = ();
foreach my $subfeat (@{$feat->{'contains'}}) {
if ($subfeat->{'type'} !~ /exon|intron|STS/) {
push @newcontains, $subfeat;
}
}
$feat->{'contains'} = \@newcontains;
push @simplified_array, $feat;
}
}
return \@simplified_array;
}

sub parse_feature_sequences {
my $gene_array = shift;

Expand Down Expand Up @@ -244,7 +263,7 @@ sub write_sequin_tbl {

sub feature_table_from_genbank {
my $gbfile = shift;
my $gene_array = Genbank::parse_genbank($gbfile);
my $gene_array = Genbank::simplify_genbank_array(Genbank::parse_genbank($gbfile));

my @feature_array = ();
foreach my $gene (@$gene_array) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Subfunctions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ sub blast_to_genbank {
my $gbfile = shift;
my $fastafile = shift;

my $gene_array = Genbank::parse_genbank($gbfile);
my $gene_array = Genbank::simplify_genbank_array(Genbank::parse_genbank($gbfile));
my $refseq = Genbank::get_sequence();
my ($ref_hash, $region_array) = Genbank::clone_features($gene_array);
my ($query_hash, $query_array) = parse_fasta($fastafile);
Expand Down
3 changes: 2 additions & 1 deletion parsing/genbank.pl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
$outfile = $gbfile;
}

my $gene_array = Genbank::parse_genbank($gbfile);
my $gene_array = Genbank::simplify_genbank_array(Genbank::parse_genbank($gbfile));


open FASTA_FH, ">", "$outfile.fasta";
print FASTA_FH Genbank::write_features_as_fasta ($gene_array);
Expand Down

0 comments on commit 624acfd

Please sign in to comment.