Bio::Tools::Alignment Consed
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::Tools::Alignment::Consed - A module to work with objects from consed .ace files
Package variables
Privates (from "my" definitions)
$current_base;
Included modules
Bio::Root::IO
Bio::Root::Root
Bio::Tools::Alignment::Trim
Dumpvalue qw ( dumpValue )
FileHandle
Inherit
Bio::Root::IO Bio::Root::Root
Synopsis
  # a report for sequencing stuff
  my $o_consed = new Bio::Tools::Alignment::Consed( 
      -acefile => "/path/to/an/acefile.ace.1",
      -verbose => 1);
  my $foo = $o_consed->set_reverse_designator("r");
  my $bar = $o_consed->set_forward_designator("f");

  # get the contig numbers
  my @keys = $o_consed->get_contigs();

  # construct the doublets
  my $setter_doublets = $o_consed->choose_doublets();

  # get the doublets
  my @doublets = $o_consed->get_doublets();
Description
Bio::Tools::Alignment::Consed provides methods and objects to deal
with the output from the Consed package of programs. Specifically,
Bio::Tools::Alignment::Consed takes in the name of in .ace file and
provides objects for the results.
A word about doublets: This module was written to accomodate a large
EST sequencing operation. In this case, EST's were sequenced from the
3' and from the 5' end of the EST. The objective was to find a
consensus sequence for these two reads. Thus, a contig of two is what
we wanted, and this contig should consist of the forward and reverse
reads of a getn clone. For example, for a forward designator of "F"
and a reverse designator of "R", if the two reads chad1F and chad1R
were in a single contig (for example Contig 5) it will be determined
that the consensus sequence for Contig 5 will be the sequence for
clone chad1.
Doublets are good!
This module parses .ace and related files. A detailed list of methods
can be found at the end of this document.
I wrote a detailed rationale for design that may explain the reasons
why some things were done the way they were done. That document is
beyond the scope of this pod and can probably be found in the
directory from which this module was 'made' or at
http://www.dieselwurks.com/bioinformatics/consedpm_documentation.pdf
Note that the pod in that document might be old but the original
rationale still stands.
Methods
BEGIN Code
newDescriptionCode
set_verbose
No description
Code
get_filenameDescriptionCode
count_sequences_with_grepDescriptionCode
get_pathDescriptionCode
get_contigsDescriptionCode
get_classDescriptionCode
get_quality_arrayDescriptionCode
get_quality_scalarDescriptionCode
freeze_hashDescriptionCode
get_membersDescriptionCode
get_members_by_nameDescriptionCode
get_contig_number_by_nameDescriptionCode
get_sequenceDescriptionCode
set_final_sequenceDescriptionCode
_read_fileDescriptionCode
set_reverse_designatorDescriptionCode
set_forward_designatorDescriptionCode
set_designator_ignore_caseDescriptionCode
set_trim_points_singlets_and_singletonsDescriptionCode
set_trim_points_doubletsDescriptionCode
get_trimmed_sequence_by_nameDescriptionCode
set_dash_present_in_sequence_nameDescriptionCode
set_doubletsDescriptionCode
set_singletsDescriptionCode
get_singletsDescriptionCode
set_quality_by_nameDescriptionCode
set_singlet_qualityDescriptionCode
set_contig_qualityDescriptionCode
get_multipletsDescriptionCode
get_all_membersDescriptionCode
sum_letsDescriptionCode
write_statsDescriptionCode
get_singletonsDescriptionCode
get_pairsDescriptionCode
get_nameDescriptionCode
_get_contig_nameDescriptionCode
get_doubletsDescriptionCode
dump_hashDescriptionCode
dump_hash_compactDescriptionCode
get_phredsDescriptionCode
parse_phdDescriptionCode
reverse_and_complementDescriptionCode
reverse_recurse($$)
No description
Code
show_missing_sequence()
No description
Code
Methods description
new()code    nextTop
 Title   : new(-acefile => $path_to_some_acefile, -verbose => "1")
 Usage   : $o_consed = Bio::Tools::Alignment::Consed->
              new(-acefile => $path_to_some_acefile, -verbose => "1");
 Function: Construct the Bio::Tools::Alignment::Consed object. Sets
	   verbosity for the following procedures, if necessary:
	   1. Construct a new Bio::Tools::Alignment::Trim object, to
	   handle quality trimming 2. Read in the acefile and parse it

 Returns : A reference to a Bio::Tools::Alignment::Consed object.
 Args    : A hash. (-acefile) is the filename of an acefile. If a full path
	   is not specified "./" is prepended to the filename and used from
	   instantiation until destruction. If you want 
           Bio::Tools::Alignment::Consed to be noisy during parsing of
           the acefile, specify some value for (-verbose).
get_filename()codeprevnextTop
 Title   : get_filename()
 Usage   : $o_consed->get_filename();
 Function: Returns the name of the acefile being used by the
	   Bio::Tools::Alignment::Consed object.
 Returns : A scalar containing the name of a file.
 Args    : None.
count_sequences_with_grep()codeprevnextTop
 Title   : count_sequences_with_grep()
 Usage   : $o_consed->count_sequences_with_grep();
 Function: Use /bin/grep to scan through the files in the ace project dir
	   and count sequences in those files. I used this method in the
	   development of this module to verify that I was getting all of the
	   sequences. It works, but it is (I think) unix-like platform
	   dependent.
 Returns : A scalar containing the number of sequences in the ace project
	   directory.
 Args    : None.
 Notes   : If you are on a non-UNIX platform, you really do not have to use
	   this. It is more of a debugging routine designed to address very
	   specific problems.

           This method was reimplemented to be platform independent with a 
           pure perl implementation.  The above note can be ignored.
get_path()codeprevnextTop
 Title   : get_path()
 Usage   : $o_consed->get_path();
 Function: Returns the path to the acefile this object is working with.
 Returns : Scalar. The path to the working acefile.
 Args    : None.
get_contigs()codeprevnextTop
 Title   : get_contigs()
 Usage   : $o_consed->get_contigs();
 Function: Return the keys to the Bio::Tools::Alignment::Consed object.
 Returns : An array containing the keynames in the
           Bio::Tools::Alignment::Consed object.
 Args    : None.
 Notes   : This would normally be used to get the keynames for some sort of
	   iterator. These keys are worthless in general day-to-day use because
	   in the Consed acefile they are simply Contig1, Contig2, ...
get_class($contig_keyname)codeprevnextTop
 Title   : get_class($contig_keyname)
 Usage   : $o_consed->get_class($contig_keyname);
 Function: Return the class name for this contig
 Returns : A scalar representing the class of this contig.
 Args    : None.
 Notes   :
get_quality_array($contig_keyname)codeprevnextTop
 Title   : get_quality_array($contig_keyname)
 Usage   : $o_consed->get_quality_array($contig_keyname);
 Function: Returns the quality for the consensus sequence for the given
	   contig as an array. See get_quality_scalar to get this as a scalar.
 Returns : An array containing the quality for the consensus sequence with
	   the given keyname.
 Args    : The keyname of a contig. Note: This is a keyname. The key would
	   normally come from get_contigs.
 Notes   : Returns an array, not a reference. Is this a bug?  No.
	   Well, maybe.
	   Why was this developed like this? I was using FreezeThaw for object
	   persistence, and when it froze out these arrays it took a long time
	   to thaw it. Much better as a scalar.
See get_quality_scalar()
get_quality_scalar($contig_keyname))codeprevnextTop
 Title   : get_quality_scalar($contig_keyname)
 Usage   : $o_consed->get_quality_scalar($contig_keyname);
 Function: Returns the quality for the consensus sequence for the given
	   contig as a scalar. See get_quality_array to get this as an array.
 Returns : An scalar containing the quality for the consensus sequence with
           the given keyname.
 Args    : The keyname of a contig. Note this is a _keyname_. The key would
	   normally come from get_contigs.
 Notes   : Why was this developed like this? I was using FreezeThaw for object
	   persistence, and when it froze out these arrays it took a coon's age
	   to thaw it. Much better as a scalar.
See get_quality_array()
freeze_hash()codeprevnextTop
 Title   : freeze_hash()
 Usage   : $o_consed->freeze_hash();

 Function: Use Ilya's FreezeThaw module to create a persistent data
	   object for this Bio::Tools::Alignment::Consed data
	   structure. In the case of AAFC, we use
	   Bio::Tools::Alignment::Consed to pre-process bunches of
	   sequences, freeze the structures, and send in a harvesting
	   robot later to do database stuff.
 Returns : 0 or 1;
 Args    : None.
 Notes   : This procedure was removed so Consed.pm won't require
	   FreezeThaw.
get_members($contig_keyname)codeprevnextTop
 Title   : get_members($contig_keyname)
 Usage   : $o_consed->get_members($contig_keyname);
 Function: Return the _names_ of the reads in this contig.
 Returns : An array containing the names of the reads in this contig.
 Args    : The keyname of a contig. Note this is a keyname. The keyname
	   would normally come from get_contigs.
See get_contigs()
get_members_by_name($some_arbitrary_name)codeprevnextTop
 Title   : get_members_by_name($some_arbitrary_name)
 Usage   : $o_consed->get_members_by_name($some_arbitrary_name);
 Function: Return the names of the reads in a contig. This is the name given
	   to $contig{key} based on what is in the contig. This is different
	   from the keys retrieved through get_contigs().
 Returns : An array containing the names of the reads in the contig with this
	   name.
 Args    : The name of a contig. Not a key, but a name.
 Notes   : Highly inefficient. use some other method if possible.
See get_contigs()
get_contig_number_by_name($some_arbitrary_name)codeprevnextTop
 Title   : get_contig_number_by_name($some_arbitrary_name)
 Usage   : $o_consed->get_contig_number_by_name($some_arbitrary_name);
 Function: Return the names of the reads in a contig. This is the name given
	   to $contig{key} based on what is in the contig. This is different
	   from the keys retrieved through get_contigs().
 Returns : An array containing the names of the reads in the contig with this
	   name.
 Args    : The name of a contig. Not a key, but a name.
See get_contigs()
get_sequence($contig_keyname)codeprevnextTop
 Title   : get_sequence($contig_keyname)
 Usage   : $o_consed->get_sequence($contig_keyname); 
 Function: Returns the consensus sequence for a given contig.
 Returns : A scalar containing a sequence.
 Args    : The keyname of a contig. Note this is a key. The key would
	   normally come from get_contigs.
See get_contigs()
set_final_sequence($some_sequence)codeprevnextTop
 Title   : set_final_sequence($name,$some_sequence)
 Usage   : $o_consed->set_final_sequence($name,$some_sequence);
 Function: Provides a manual way to set the sequence for a given key in the
	   contig hash. Rarely used.
 Returns : 0 or 1;
 Args    : The name (not the keyname) of a contig and an arbitrary string.
 Notes   : A method with a questionable and somewhat mysterious origin. May
	   raise the dead or something like that.
_read_file()codeprevnextTop
 Title   : _read_file();
 Usage   : _read_file();
 Function: An internal subroutine used to read in an acefile and parse it
	   into a Bio::Tools::Alignment::Consed object.
 Returns : 0 or 1.
 Args    : Nothing.
 Notes   : This routine creates and saves the filhandle for reading the
	   files in {fh}
set_reverse_designator($some_string)codeprevnextTop
 Title   : set_reverse_designator($some_string)
 Usage   : $o_consed->set_reverse_designator($some_string);
 Function: Set the designator for the reverse read of contigs in this
	   Bio::Tools::Alignment::Consed object. Used to determine if
           contigs containing two reads can be named.
 Returns : The value of $o_consed->{reverse_designator} so you can check
	   to see that it was set properly.
 Args    : An arbitrary string.
 Notes   : May be useful only to me. 
set_forward_designator($some_string)codeprevnextTop
 Title   : set_forward_designator($some_string)
 Usage   : $o_consed->set_forward_designator($some_string);
 Function: Set the designator for the forward read of contigs in this
	   Bio::Tools::Alignment::Consed object. Used to determine if
           contigs containing two reads can be named.
 Returns : The value of $o_consed->{forward_designator} so you can check
	   to see that it was set properly.
 Args    : An arbitrary string.
 Notes   : May be useful only to me. 
set_designator_ignore_case("yes")codeprevnextTop
 Title   : set_designator_ignore_case("yes")
 Usage   : $o_consed->set_designator_ignore_case("yes");
 Function: Deprecated.
 Returns : Deprecated.
 Args    : Deprecated.
 Notes   : Deprecated. Really. Trust me.
set_trim_points_singlets_and_singletons()codeprevnextTop
 Title   : set_trim_points_singlets_and_singletons()
 Usage   : $o_consed->set_trim_points_singlets_and_singletons();
 Function: Set the trim points for singlets and singletons based on
	   quality.  Uses the Bio::Tools::Alignment::Trim object. Use
	   at your own risk because the Bio::Tools::Alignment::Trim
	   object was designed specifically for me and is mysterious
	   in its ways. Every time somebody other then me uses it a
	   swarm of locusts decends on a small Central American
	   village so do not say you weren't warned.
 Returns : Nothing.
 Args    : None.
 Notes   : Working on exceptions and warnings here.
See Bio::Tools::Alignment::Trim for more information
set_trim_points_doublets()codeprevnextTop
 Title   : set_trim_points_doublets()
 Usage   : $o_consed->set_trim_points_doublets();
 Function: Set the trim points for doublets based on quality. Uses the
	   Bio::Tools::Alignment::Trim object. Use at your own risk because
           the Bio::Tools::Alignment::Trim object was designed specifically
           for me and is mysterious in its ways. Every time somebody other
           then me uses it you risk a biblical plague being loosed on your
           city.
 Returns : Nothing.
 Args    : None.
 Notes   : Working on exceptions here.
See Bio::Tools::Alignment::Trim for more information
get_trimmed_sequence_by_name($name)codeprevnextTop
 Title   : get_trimmed_sequence_by_name($name)
 Usage   : $o_consed->get_trimmed_sequence_by_name($name);
 Function: Returns the trimmed_sequence of a contig with {name} eq $name.
 Returns : A scalar- the trimmed sequence.
 Args    : The {name} of a contig.
 Notes   :
set_dash_present_in_sequence_name("yes")codeprevnextTop
 Title   : set_dash_present_in_sequence_name("yes")
 Usage   : $o_consed->set_dash_present_in_sequence_name("yes");
 Function: Deprecated. Part of an uncompleted thought. ("Oooh! Shiny!")
 Returns : Nothing.
 Args    : "yes" to set {dash_present_in_sequence_name} to 1
 Notes   :
set_doublets()codeprevnextTop
 Title   : set_doublets()
 Usage   : $o_consed->set_doublets();
 Function: Find pairs that have similar names and mark them as doublets
	   and set the {name}.
 Returns : 0 or 1.
 Args    : None.
 Notes   : A complicated subroutine that iterates over the
	   Bio::Tools::Alignment::Consed looking for contigs of 2. If the
           forward and reverse designator are removed from each of the reads
           in {'member_array'} and the remaining reads are the same, {name}
           is set to that name and the contig's class is set as "doublet".
           If any of those cases fail the contig is marked as a "pair".
set_singletscodeprevnextTop
 Title   : set_singlets
 Usage   : $o_consed->set_singlets();
 Function: Read in a singlets file and place them into the
	   Bio::Tools::Alignment::Consed object.
 Returns : Nothing.
 Args    : A scalar to turn on verbose parsing of the singlets file.
 Notes   :
get_singlets()codeprevnextTop
    
 Title   : get_singlets()
 Usage   : $o_consed->get_singlets();
 Function: Return the keynames of the singlets.
 Returns : An array containing the keynames of all 
           Bio::Tools::Alignment::Consed sequences in the class "singlet".
 Args    : None.
 Notes   :
set_quality_by_name($name,$quality)codeprevnextTop
 Title   : set_quality_by_name($name,$quality)
 Usage   : $o_consed->set_quality_by_name($name,$quality);
 Function: Deprecated. Make the contig with {name} have {'quality'} $quality.
           Probably used for testing.
 Returns : Nothing.
 Args    : The name of a contig and a scalar for its quality.
 Notes   : Deprecated.
set_singlet_quality()codeprevnextTop
 Title   : set_singlet_quality()
 Usage   : $o_consed->set_singlet_quality();
 Function: For each singlet, go to the appropriate file in phd_dir and read
           in the phred quality for that read and place it into {'quality'}
 Returns : 0 or 1.
 Args    : None.
 Notes   : This is the next subroutine that will receive substantial revision
           in the next little while. It really should eval the creation of
           Bio::Tools::Alignment::Phred objects and go from there.
set_contig_quality()codeprevnextTop
 Title   : set_contig_quality()
 Usage   : $o_consed->set_contig_quality();
 Function: Deprecated.
 Returns : Deprecated.
 Args    : Deprecated.
 Notes   : Deprecated. Really. Trust me.
get_multiplets()codeprevnextTop
 Title   : get_multiplets()
 Usage   : $o_consed->get_multiplets();
 Function: Return the keynames of the multiplets.
 Returns : Returns an array containing the keynames of all 
           Bio::Tools::Alignment::Consed sequences in the class "multiplet".
 Args    : None.
 Notes   :
get_all_members()codeprevnextTop
  Title   : get_all_members()
  Usage   : @all_members = $o_consed->get_all_members();
  Function: Return a list of all of the read names in the 
            Bio::Tools::Alignment::Consed object.
  Returns : An array containing all of the elements in all of the
            {'member_array'}s.
  Args    : None.
  Notes   :
sum_lets($total_only)codeprevnextTop
 Title   : sum_lets($total_only)
 Usage   : $statistics = $o_consed->sum_lets($total_only);
 Function: Provide numbers for how many sequences were accounted for in the
           Bio::Tools::Alignment::Consed object.
 Returns : If a scalar is present, returns the total number of
           sequences accounted for in all classes. If no scalar passed
           then returns a string that looks like this:
           Singt/singn/doub/pair/mult/total : 2,0,1(2),0(0),0(0),4
           This example means the following: There were 1 singlets.
           There were 0 singletons.  There were 1 doublets for a total
           of 2 sequences in this class.  There were 0 pairs for a
           total of 0 sequences in this class.  There were 0
           multiplets for a total of 0 sequences in this class.  There
           were a total of 4 sequences accounted for in the
           Bio::Tools::Alignment::Consed object.   
 Args : A scalar is optional to change the way the numbers are returned.  
 Notes:
write_stats()codeprevnextTop
 Title   : write_stats()
 Usage   : $o_consed->write_stats();
 Function: Write a file called "statistics" containing numbers similar to
	   those provided in sum_lets().
 Returns : Nothing. Write a file in $o_consed->{path} containing something
	   like this: 

           0,0,50(100),0(0),0(0),100

           Where the numbers provided are in the format described in the
	   documentation for sum_lets().
 Args    : None.
 Notes   : This might break platform independence, I do not know.
See sum_lets()
get_singletons()codeprevnextTop
 Title   : get_singletons()
 Usage   : @singletons = $o_consed->get_singletons();
 Function: Return the keynames of the singletons.
 Returns : Returns an array containing the keynames of all
	   Bio::Tools::Alignment::Consed sequences in the class "singleton".
 Args    : None.
 Notes   :
get_pairs()codeprevnextTop
 Title   : get_pairs()
 Usage   : @pairs = $o_consed->get_pairs();
 Function: Return the keynames of the pairs.
 Returns : Returns an array containing the keynames of all
           Bio::Tools::Alignment::Consed sequences in the class "pair".
 Args    : None.
 Notes   :
get_name($contig_keyname)codeprevnextTop
 Title   : get_name($contig_keyname)
 Usage   : $name = $o_consed->get_name($contig_keyname);
 Function: Return the {name} for $contig_keyname.
 Returns : A string. ({name})
 Args    : A contig keyname.
 Notes   :
_get_contig_name(\@array_containing_reads)codeprevnextTop
 Title   : _get_contig_name(\@array_containing_reads)
 Usage   : $o_consed->_get_contig_name(\@array_containing_reads);
 Function: The logic for the set_doublets subroutine.
 Returns : The name for this contig.
 Args    : A reference to an array containing read names.
 Notes   : Depends on reverse_designator. Be sure this is set the way you
	   intend.
get_doublets()codeprevnextTop
 Title   : get_doublets()
 Usage   : @doublets = $o_consed->get_doublets();
 Function: Return the keynames of the doublets.
 Returns : Returns an array containing the keynames of all
           Bio::Tools::Alignment::Consed sequences in the class "doublet".
 Args    : None.
 Notes   :
dump_hash()codeprevnextTop
 Title   : dump_hash()
 Usage   : $o_consed->dump_hash();
 Function: Use dumpvar.pl to dump out the Bio::Tools::Alignment::Consed
           object to STDOUT.
 Returns : Nothing.
 Args    : None.
 Notes   : I used this a lot in debugging.
dump_hash_compact()codeprevnextTop
 Title   : dump_hash_compact()
 Usage   : $o_consed->dump_hash_compact();
 Function: Dump out the Bio::Tools::Alignment::Consed object in a compact way.
 Returns : Nothing.
 Args    : Nothing.
 Notes   : Cleaner then dumpValue(), dumpHash(). I used this a lot in
           debugging.
get_phreds()codeprevnextTop
 Title   : get_phreds()
 Usage   : @phreds = $o_consed->get_phreds();
 Function: For each doublet in the Bio::Tools::Alignment::Consed hash, go
           and get the phreds for the top and bottom reads. Place them into
           {top_phreds} and {bottom_phreds}.
 Returns : Nothing.
 Args    : Nothing.
 Notes   : Requires parse_phd() and reverse_and_complement(). I realize that
	it would be much more elegant to pull qualities as required but there
	were certain "features" in the acefile that required a bit more
	detailed work be done to get the qualities for certain parts of the
	consensus sequence. In order to make _sure_ that this was done
	properly I wrote things to do all steps and then I used dump_hash()
	and checked each one to ensure expected bahavior. I have never changed
	this, so there you are.
parse_phd($read_name)codeprevnextTop
 Title   : parse_phd($read_name)
 Usage   : $o_consed->parse_phd($read_name);
 Function: Suck in the contents of a .phd file.
 Returns : A reference to an array containing the quality values for the read.
 Args    : The name of a read.
 Notes   : This is a significantly weak subroutine because it was always
	   intended that these functions, along with the functions provided by
	   get_phreds() be put into the Bio::SeqIO:phd module. This is done
           now but the Bio::Tools::Alignment::Consed module has not be
           rewritten to reflect this change.
See Bio::SeqIO::phd for more information.
reverse_and_complement(\@source)codeprevnextTop
 Title   : reverse_and_complement(\@source)
 Usage   : $reference_to_array = $o_consed->reverse_and_complement(\@source);
 Function: A stub for the recursive routine reverse_recurse().
 Returns : A reference to a reversed and complemented array of phred data.
 Args    : A reference to an array of phred data.
 Notes   :
Methods code
BEGINTop
BEGIN {
    %DEFAULTS = ( 'f_designator' => 'f',
		  'r_designator' => 'r');
}
newdescriptionprevnextTop
sub new {
    my ($class,%args) = @_;
    my $self = $class->SUPER::new(%args);

    $self->{'filename'} = $args{'-acefile'};
	# this is special to UNIX and should probably use catfile
if (!($self->{'filename'} =~ /\//)) { $self->{'filename'} = "./".$self->{'filename'}; } $self->{'filename'} =~ m/(.*\/)(.*)ace.*$/; $self->{'path'} = $1; $self->_initialize_io('-file'=>$self->{'filename'}); $self->{'o_trim'} = new Bio::Tools::Alignment::Trim(-verbose => $self->verbose()); $self->set_forward_designator($DEFAULTS{'f_designator'}); $self->set_reverse_designator($DEFAULTS{'r_designator'}); $self->_read_file(); return $self;
}
set_verbosedescriptionprevnextTop
sub set_verbose {
 (shift)->verbose(@_)
}
get_filenamedescriptionprevnextTop
sub get_filename {
    my $self = shift;
    return $self->{'filename'};
}
count_sequences_with_grepdescriptionprevnextTop
sub count_sequences_with_grep {
    my $self = shift;
    my ($working_dir,$grep_cli,@total_grep_sequences);
    # this should be migrated to a pure perl implementation ala
# Tom Christiansen's 'tcgrep'
# http://www.perl.com/language/ppt/src/grep/tcgrep
open(FILE, $self->{'filename'}) or do { $self->warn("cannot open file ".$self->{'filename'}. " for grepping"); return}; my $counter =0; while(<FILE>) { $counter++ if(/^AF/); } close FILE; opendir(SINGLETS,$self->{'path'}); foreach my $f ( readdir(SINGLETS) ) { next unless ($f =~ /\.singlets$/); open(FILE, $self->catfile($self->{'path'},$f)) or do{ $self->warn("cannot open file ".$self->catfile($self->{'path'},$f)); next }; while(<FILE>) { $counter++ if(/^>/) } close FILE; } return $counter; # Chad's platform implementation which required grep on the system
# I tried to cause graceful exiting if not on *ix here
# then i took platforms from Bioperl*/PLATFORMS here. Is that good?
# print("\$^O is $^O\n");
# if (!($^O =~ /dec_osf|linux|unix|bsd|solaris|darwin/i)) {
# $self->warn("Bio::Tools::Alignment::Consed::count_sequences_with_grep: This sub uses grep which is doesn't run on this operating system, AFAIK. Sorry .".$^O);
# return 1;
# }
# $grep_cli = `which grep`;
# if (!$grep_cli) {
# $self->warn("I couldn't see to find grep on this system, or the which command is broken. Bio::Tools::Alignment::Consed::count_sequences_with_grep requires grep and which to find grep.");
# return 1;
# }
# chomp $grep_cli;
# push(@total_grep_sequences, my @foo = `$grep_cli ^AF $self->{filename}`);
# my $cli = "$grep_cli \\> $self->{'path'}*.singlets";
# push(@total_grep_sequences, @foo = `$cli`);
# return scalar(@total_grep_sequences);
}
get_pathdescriptionprevnextTop
sub get_path {
	my $self = shift;
	return $self->{'path'};
}
get_contigsdescriptionprevnextTop
sub get_contigs {
    my ($self,$contig) = @_;
    my @keys = (sort keys %{$self->{'contigs'}});
    return @keys;
}
get_classdescriptionprevnextTop
sub get_class {
    my ($self,$contig) = @_;
    return $self->{contigs}->{$contig}->{class};
}
get_quality_arraydescriptionprevnextTop
sub get_quality_array {
    my ($self,$contig) = @_;
     my $quality =  $self->{contigs}->{$contig}->{quality};
          # chad, what is with the s/// ?
# my @qualities = split
# (' ',($self->{contigs}->{$contig}->{quality} =~ s/\s+//));
my @qualities = split (' ',$self->{contigs}->{$contig}->{quality}); return @qualities;
}
get_quality_scalardescriptionprevnextTop
sub get_quality_scalar {
    my ($self,$contig) = @_;
    return $self->{'contigs'}->{$contig}->{'quality'};
}
freeze_hashdescriptionprevnextTop
sub freeze_hash {
    my $self = shift;
	$self->warn("This method (freeze_hash) was removed from the bioperl consed.pm. Sorry.\n");
	if (1==2) {
	    $self->debug("Bio::Tools::Alignment::Consed::freeze_hash:\$ self->{path} is $self->{path}\n");
	    my $filename = $self->{'path'}."frozen";
	    my %contigs = %{$self->{'contigs'}};
	    my $frozen = freeze(%contigs);
	    umask 0001;
	    open (FREEZE,">$filename") or do {
		$self->warn( "Bio::Tools::Alignment::Consed could not freeze the contig hash because the file ($filename) could not be opened: $!\n");
		return 1;
	    };
	    print FREEZE $frozen;
	    close FREEZE;
	    return 0;
	}
}
get_membersdescriptionprevnextTop
sub get_members {
    my ($self,$contig) = @_;
    if (!$contig) {
	$self->warn("You need to provide the name of a contig to use Bio::Tools::Alignment::Consed::get_members!\n");
	return;
    }
    return @{$self->{'contigs'}->{$contig}->{'member_array'}};
}
get_members_by_namedescriptionprevnextTop
sub get_members_by_name {
    my ($self,$name) = @_;
	    # build a list to try to screen for redundancy
my @contigs_with_that_name; foreach my $currkey ( sort keys %{$self->{'contigs'}} ) { next if (!$self->{'contigs'}->{$currkey}->{'name'}); if ($self->{'contigs'}->{$currkey}->{'name'} eq "$name") { push @contigs_with_that_name,$currkey; } } my $count = @contigs_with_that_name; if ($count == 1) { my $contig_num = $contigs_with_that_name[0]; return @{$self->{'contigs'}->{$contig_num}->{'member_array'}}; }
}
get_contig_number_by_namedescriptionprevnextTop
sub get_contig_number_by_name {
    my ($self,$name) = @_;
    foreach my $currkey (sort keys %{$self->{'contigs'}}) {
	if ($self->{'contigs'}->{$currkey}->{'name'} && 
	    $self->{'contigs'}->{$currkey}->{'name'} eq "$name") {
	    return $currkey;
	}
    }
}
get_sequencedescriptionprevnextTop
sub get_sequence {
    my ($self,$contig) = @_;
    return $self->{'contigs'}->{$contig}->{'consensus'};
}
set_final_sequencedescriptionprevnextTop
sub set_final_sequence {
    my ($self,$name,$sequence) = @_;
    if (!$self->{'contigs'}->{$name}) {
	$self->warn("You cannot set the final sequence for $name because it doesn't exist!\n");
	return 1;
    }
    else {
	$self->{'contigs'}->{$name}->{'final_sequence'} = $sequence;
    }
    return 0;
}
_read_filedescriptionprevnextTop
sub _read_file {
    my ($self) = @_;
    my ($line,$in_contig,$in_quality,$contig_number,$top); 
    # make it easier to type $fhl
while (defined($line=$self->_readline()) ) { chomp $line; # check if there is anything on this line
# if not, you can stop gathering consensus sequence
if (!$line) { # if the line is blank you are no longer to gather consensus
# sequence or quality values
$in_contig = 0; $in_quality = 0; } # you are currently gathering consensus sequence
elsif ($in_contig) { if ($in_contig == 1) { $self->debug("Adding $line to consensus of contig number $contig_number.\n"); $self->{'contigs'}->{$contig_number}->{'consensus'} .= $line; } } elsif ($in_quality) { if (!$line) { $in_quality = undef; } else { # I wrote this in here because acefiles produced by cap3 do not have a leading space
# like the acefiles produced by phrap and there is the potential to have concatenated
# quality values like this: 2020 rather then 20 20 whre lines collide. Thanks Andrew for noticing.
if ($self->{'contigs'}->{$contig_number}->{'quality'} && !($self->{'contigs'}->{$contig_number}->{'quality'} =~ m/\ $/)) { $self->{'contigs'}->{$contig_number}->{'quality'} .= " "; } $self->{'contigs'}->{$contig_number}->{'quality'} .= $line; } } elsif ($line =~ /^BQ/) { $in_quality = 1; } # the line /^CO/ like this:
# CO Contig1 796 1 1 U
# can be broken down as follows:
# CO - Contig!
# Contig1 - the name of this contig
# 796 - Number of bases in this contig
# 1 - Number of reads in this contig
# 1 - number of base segments in this contig
# U - Uncomplemented
elsif ($line =~ /^CO/) { $line =~ m/^CO\ Contig(\d+)\ \d+\ \d+\ \d+\ (\w)/; $contig_number = $1; if ($2 eq "C") { $self->debug("Contig $contig_number is complemented!\n"); } $self->{'contigs'}->{$contig_number}->{'member_array'} = []; $self->{'contigs'}->{$contig_number}->{'contig_direction'} = "$2"; $in_contig = 1; } # 000713
# this BS is deprecated, I think.
# haha, I am really witty. <ew>
elsif ($line =~ /^BSDEPRECATED/) { $line =~ m/^BS\s+\d+\s+\d+\s+(.+)/; my $member = $1; $self->{'contigs'}->{$contig_number}->{$member}++; } # the members of the contigs are determined by the AF line in the ace file
elsif ($line =~ /^AF/) { $self->debug("I see an AF line here.\n"); $line =~ /^AF\ (\S+)\ (\w)\ (\S+)/; # push the name of the current read onto the member array for this contig
push @{$self->{'contigs'}->{$contig_number}->{'member_array'}},$1; # the first read in the contig will be named the "top" read
if (!$top) { $self->debug("\$top is not set.\n"); if ($self->{'contigs'}->{$contig_number}->{'contig_direction'} eq "C") { $self->debug("Reversing the order of the reads. The bottom will be $1\n"); # if the contig sequence is marked as the complement, the top becomes the bottom and$
$self->{'contigs'}->{$contig_number}->{'bottom_name'} = $1; $self->{'contigs'}->{$contig_number}->{'bottom_complement'} = $2; $self->{'contigs'}->{$contig_number}->{'bottom_start'} = $3; } else { $self->debug("NOT reversing the order of the reads. The top_name will be $1\n"); # if the contig sequence is marked as the complement, the top becomes the bottom and$
$self->{'contigs'}->{$contig_number}->{'top_name'} = $1; $self->{'contigs'}->{$contig_number}->{'top_complement'} = $2; $self->{'contigs'}->{$contig_number}->{'top_start'} = $3; } $top = 1; } else { # if the contig sequence is marked as the complement, the top becomes the bottom and the bottom becomes the top
if ($self->{'contigs'}->{$contig_number}->{'contig_direction'} eq "C") { $self->debug("Reversing the order of the reads. The top will be $1\n"); $self->{'contigs'}->{$contig_number}->{'top_name'} = $1; $self->{'contigs'}->{$contig_number}->{'top_complement'} = $2; $self->{'contigs'}->{$contig_number}->{'top_start'} = $3; } else { $self->debug("NOT reversing the order of the reads. The bottom will be $1\n"); $self->{'contigs'}->{$contig_number}->{'bottom_name'} = $1; $self->{'contigs'}->{$contig_number}->{'bottom_complement'} = $2; $self->{'contigs'}->{$contig_number}->{'bottom_start'} = $3; } $top = undef; } } } return 0;
}
set_reverse_designatordescriptionprevnextTop
sub set_reverse_designator {
    my ($self,$reverse_designator) = @_;
    $self->{'reverse_designator'} = $reverse_designator;
    $self->{'o_trim'}->set_reverse_designator($reverse_designator);
    return $self->{'reverse_designator'};
}				# end set_reverse_designator
}
set_forward_designatordescriptionprevnextTop
sub set_forward_designator {
    my ($self,$forward_designator) = @_;
    $self->{'forward_designator'} = $forward_designator;
    $self->{'o_trim'}->set_forward_designator($forward_designator);
    return $self->{'forward_designator'};
}				# end set_forward_designator
}
set_designator_ignore_casedescriptionprevnextTop
sub set_designator_ignore_case {
    my ($self,$ignore_case) = @_;
    if ($ignore_case eq "yes") {
	$self->{'designator_ignore_case'} = 1;
    }
    return $self->{'designator_ignore_case'};
}				# end set_designator_ignore_case
}
set_trim_points_singlets_and_singletonsdescriptionprevnextTop
sub set_trim_points_singlets_and_singletons {
    my ($self) = @_;
    $self->debug("Consed.pm :\$ self is $self\n");
    my (@points,$trimmed_sequence);
    if (!$self->{'doublets_set'}) {
        $self->debug("You need to set the doublets before you use set_trim_points_singlets_and_doublets. Doing that now.");
	$self->set_doublets();
    }
    foreach (sort keys %{$self->{'contigs'}}) {
	if ($self->{'contigs'}->{$_}->{'class'} eq "singlet") {
	    $self->debug("Singlet $_\n");
	    # this is what Warehouse wants
# my ($self,$sequence,$quality,$name) = @_;
# this is what Bio::Tools::Alignment::Trim::trim_singlet wants:
# my ($self,$sequence,$quality,$name,$class) = @_;
# the following several lines are to make the parameter passing legible.
my ($sequence,$quality,$name,$class); $sequence = $self->{'contigs'}->{$_}->{'consensus'}; if (!$self->{'contigs'}->{$_}->{'quality'}) { $quality = "unset"; } else { $quality = $self->{'contigs'}->{$_}->{'quality'}; } $name = $self->{'contigs'}->{$_}->{'name'}; $class = $self->{'contigs'}->{$_}->{'class'}; (@points) = @{$self->{'o_trim'}->trim_singlet($sequence,$quality,$name,$class)}; $self->{'contigs'}->{$_}->{'start_point'} = $points[0]; $self->{'contigs'}->{$_}->{'end_point'} = $points[1]; $self->{'contigs'}->{$_}->{'sequence_trimmed'} = substr($self->{contigs}->{$_}->{'consensus'},$points[0],$points[1]-$points[0]); } } $self->debug("Bio::Tools::Alignment::Consed::set_trim_points_singlets_and_singletons: Done setting the quality trimpoints.\n"); return; } # end set_trim_points_singlet
}
set_trim_points_doubletsdescriptionprevnextTop
sub set_trim_points_doublets {
    my $self = shift;
    my @points;
    $self->debug("Bio::Tools::Alignment::Consed::set_trim_points_doublets: Restoring zeros for doublets.\n");
    # &show_missing_sequence($self);
$self->debug("Bio::Tools::Alignment::Consed::set_trim_points_doublets: Setting doublet trim points.\n"); foreach (sort keys %{$self->{'contigs'}}) { if ($self->{'contigs'}->{$_}->{'class'} eq "doublet") { # my ($self,$sequence,$quality,$name,$class) = @_;
my @quals = split(' ',$self->{'contigs'}->{$_}->{'quality'}); (@points) = $self->{o_trim}->trim_doublet($self->{'contigs'}->{$_}->{'consensus'},$self->{'contigs'}->{$_}->{'quality'},$self->{'contigs'}->{$_}->{name},$self->{'contigs'}->{$_}->{'class'}); $self->{'contigs'}->{$_}->{'start_point'} = $points[0]; $self->{'contigs'}->{$_}->{'end_point'} = $points[1]; # now set this
$self->{'contigs'}->{$_}->{'sequence_trimmed'} = substr($self->{contigs}->{$_}->{'consensus'},$points[0],$points[1]-$points[0]); # 010102 the deprecated way to do things:
} } $self->debug("Bio::Tools::Alignment::Consed::set_trim_points_doublets: Done setting doublet trim points.\n"); return; } # end set_trim_points_doublets
}
get_trimmed_sequence_by_namedescriptionprevnextTop
sub get_trimmed_sequence_by_name {
    my ($self,$name) = @_;
    my $trimmed_sequence;
    my $contigname = &get_contig_number_by_name($self,$name);
    my $class = $self->{'contigs'}->{$contigname}->{'class'};
    # what is this business and who was smoking crack while writing this?
# if ($class eq "singlet") {
# send the sequence, the quality, and the name
# $trimmed_sequence = $self->{o_trim}->trim_singlet($self->{'contigs'}->{$contigname}->{consensus},$self->{'contigs'}->{$contigname}->{'quality'},$name);
# }
return $self->{'contigs'}->{$contigname}->{'sequence_trimmed'};
}
set_dash_present_in_sequence_namedescriptionprevnextTop
sub set_dash_present_in_sequence_name {
    my ($self,$dash_present) = @_;
    if ($dash_present eq "yes") {
	$self->{'dash_present_in_sequence_name'} = 1;
    }
    else {
	$self->{'dash_present_in_sequence_name'} = 0;
    }
    return $self->{'dash_present_in_sequence_name'};
}				# end set_dash_present_in_sequence_name
}
set_doubletsdescriptionprevnextTop
sub set_doublets {
    my ($self) = @_;
    # set the designators in the Bio::Tools::Alignment::Trim object
$self->{'o_trim'}->set_designators($self->{'reverse_designator'}, $self->{'forward_designator'}); #
foreach my $key_contig (sort keys %{$self->{'contigs'}}) { # if there is a member array (why would there not be? This should be a die()able offence
# but for now I will leave it
if ($self->{'contigs'}->{$key_contig}->{'member_array'}) { # if there are two reads in this contig
# i am pretty sure that this is wrong but i am keeping it for reference
# if (@{$self->{'contigs'}->{$key_contig}->{'member_array'}} == 2 || !$self->{'contigs'}->{$key_contig}->{'class'}) {
# <seconds later>
# <nod> WRONG. Was I on crack?
if (@{$self->{'contigs'}->{$key_contig}->{'member_array'}} == 2) { $self->{'contigs'}->{$key_contig}->{'num_members'} = 2; $self->debug("\tThere are 2 members! Looking for the contig name...\n"); my $name = _get_contig_name($self,$self->{'contigs'}->{$key_contig}->{'member_array'}); $self->debug("The name is $name\n") if defined $name; if ($name) { $self->{'contigs'}->{$key_contig}->{'name'} = $name; $self->{'contigs'}->{$key_contig}->{'class'} = "doublet"; } else { $self->debug("$key_contig is a pair.\n"); $self->{'contigs'}->{$key_contig}->{'class'} = "pair"; } } # this is all fair and good but what about singlets?
# they have one reads in the member_array but certainly are not singletons
elsif (@{$self->{'contigs'}->{$key_contig}->{'member_array'}} == 1) { # set the name to be the name of the read
$self->{'contigs'}->{$key_contig}->{name} = @{$self->{'contigs'}->{$key_contig}->{'member_array'}}[0]; # set the number of members to be one
$self->{'contigs'}->{$key_contig}->{num_members} = 1; # if this was a singlet, it would already belong to the class "singlet"
# so leave it alone
# if it is not a singlet, it is a singleton! lablel it appropriately
unless ($self->{'contigs'}->{$key_contig}->{'class'}) { $self->{'contigs'}->{$key_contig}->{'class'} = "singleton"; } } # set the multiplet characteristics
elsif (@{$self->{'contigs'}->{$key_contig}->{'member_array'}} >= 3) { $self->{'contigs'}->{$key_contig}->{'num_members'} = @{$self->{'contigs'}->{$key_contig}->{'member_array'}}; $self->{'contigs'}->{$key_contig}->{'class'} = "multiplet"; } $self->{'contigs'}->{$key_contig}->{'num_members'} = @{$self->{'contigs'}->{$key_contig}->{'member_array'}}; } } $self->{'doublets_set'} = "done"; return 0; } # end set_doublets
}
set_singletsdescriptionprevnextTop
sub set_singlets {
    # parse out the contents of the singlets file
my ($self) = @_;