Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bioperl/bioperl-live
Browse files Browse the repository at this point in the history
  • Loading branch information
bosborne committed Jun 11, 2017
2 parents 1eb9fbc + e1ac582 commit 0feb41e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 45 deletions.
59 changes: 30 additions & 29 deletions Bio/SeqIO/pir.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#
# BioPerl module for Bio::SeqIO::PIR
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Aaron Mackey <amackey@virginia.edu>
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Copyright Aaron Mackey
#
Expand Down Expand Up @@ -43,15 +41,15 @@ of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Expand Down Expand Up @@ -110,39 +108,42 @@ sub next_seq {
my ($self) = @_;
local $/ = "\n>";
return unless my $line = $self->_readline;
if( $line eq '>' ) { # handle the very first one having no comment
return unless $line = $self->_readline;
if ( $line eq '>' ) { # handle the very first one having no comment
return unless $line = $self->_readline;
}
my ( $top, $desc, $seq ) = ( $line =~ /^(.+?)\n(.*?)\n([^>]*)/s )
or $self->throw("Cannot parse entry PIR entry [$line]");

my ( $type, $id );
if ( $top =~ /^>?(\S{2});(\S+)\s*$/ ) {
( $type, $id ) = ( $1, $2 );
if ( ! exists $VALID_TYPE{$type} ) {
$self->throw(
"PIR stream read attempted without proper two-letter sequence code [ $type ]"
);
}
} else {
$self->throw("Line does not match PIR format [ $line ]");
}
my ($top, $desc,$seq) = ( $line =~ /^(.+?)\n(.+?)\n([^>]*)/s ) or
$self->throw("Cannot parse entry PIR entry [$line]");

my ( $type,$id );
if ( $top =~ /^>?(\S{2});(\S+)\s*$/ ) {
( $type,$id ) = ($1, $2);
if (!exists $VALID_TYPE{$type} ) {
$self->throw("PIR stream read attempted without proper two-letter sequence code [ $type ]");
}
} else {
$self->throw("Line does not match PIR format [ $line ]");
}

# P - indicates complete protein
# F - indicates protein fragment
# not sure how to stuff these into a Bio object
# suitable for writing out.
$seq =~ s/\*//g;
$seq =~ s/[\(\)\.\/\=\,]//g;
$seq =~ s/\s+//g; # get rid of whitespace
$seq =~ s/\s+//g; # get rid of whitespace

my ($alphabet) = ('protein');

# TODO - not processing SFS data
return $self->sequence_factory->create
(-seq => $seq,
-primary_id => $id,
-id => $id,
-desc => $desc,
-alphabet => $alphabet
);
return $self->sequence_factory->create(
-seq => $seq,
-primary_id => $id,
-id => $id,
-desc => $desc,
-alphabet => $alphabet
);
}

=head2 write_seq
Expand Down
48 changes: 32 additions & 16 deletions t/SeqIO/pir.t
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
# -*-Perl-*- Test Harness script for Bioperl
# $Id$

use strict;

BEGIN {
use lib '.';
use lib '.';
use Bio::Root::Test;
test_begin(-tests => 9);
use_ok('Bio::SeqIO::pir');

test_begin( -tests => 12 );

use_ok('Bio::SeqIO::pir');
}

my $verbose = test_debug();

my $str = Bio::SeqIO->new(-file => test_input_file('seqfile.pir'),
-verbose => $verbose,
-format => 'pir');
my $in = Bio::SeqIO->new(
-file => test_input_file('seqfile.pir'),
-verbose => $verbose,
-format => 'pir'
);

ok ( defined $str, 'new instance is defined ');
isa_ok ($str, 'Bio::SeqIO');
ok( defined $in, 'new instance is defined ' );
isa_ok( $in, 'Bio::SeqIO' );

my $out = Bio::SeqIO->new(-format => 'pir',
-fh => \*STDOUT);
my $out = Bio::SeqIO->new(
-format => 'pir',
-fh => \*STDOUT
);

while (my $seq = $str->next_seq()) {
ok( $seq->length > 1, 'checked length');
$out->write_seq($seq) if $verbose > 0;
while ( my $seq = $in->next_seq() ) {
ok( $seq->length > 1, 'checked length' );
$out->write_seq($seq) if $verbose > 0;
}

# Empty description line
$in = Bio::SeqIO->new(
-file => test_input_file('seqfile-no-desc.pir'),
-verbose => $verbose,
-format => 'pir'
);
my $seq = $in->next_seq();
ok( $seq->seq =~ /^MGD/, 'Correct start' );
$seq = $in->next_seq();
ok( $seq->seq =~ /^GDV/, 'Correct start' );
$seq = $in->next_seq();
ok( $seq->seq =~ /^GDV/, 'Correct start' );
9 changes: 9 additions & 0 deletions t/data/seqfile-no-desc.pir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
>P1;CCHU

MGDVEKGKKIFIMKCSQCHTVEKGGKHKTGPNLHGLFGRKTGQAPGYSYTAANKNKGIIWGEDTLMEYLENPKKYIPGTKMIFVGIKKKEERADLIAYLKKATNE*
>P1;CCCZ

GDVEKGKKIFIMKCSQCHTVEKGGKHKTGPNLHGLFGRKTGQAPGYSYTAANKNKGIIWGEDTLMEYLENPKKYIPGTKMIFVGIKKKEERADLIAYLKKATNE*
>P1;CCST

GDVEK.GKKIF.VQKCAQCHTVEKGGKH.KTGPNLNGL.IGRKTGQAEGF.SYTEANKN.KGITWG.EETLM.EY.LENPKKY.IPGTKM.IF.AGIKKKAERADL.IAY.LKDATSK*

0 comments on commit 0feb41e

Please sign in to comment.