This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bio::Phenotype::OMIM::OMIMparser - parser for the OMIM database

I am using Bio::Phenotype::OMIM::OMIMparser - parser for the OMIM database with following code.Result is printing in command shell but I want result to be write in a file. Please help me to solve this problem.

I want all the results in a text file.

use Bio::Phenotype::OMIM::OMIMparser;

# The OMIM database is available as textfile at:
# ftp://ncbi.nlm.nih.gov/repository/OMIM/omim.txt.Z
# The genemap is available as textfile at:
# ftp://ncbi.nlm.nih.gov/repository/OMIM/genemap

$omim_parser = Bio::Phenotype::OMIM::OMIMparser->new( -genemap  => "/path/to/genemap",
                                                      -omimtext => "/path/to/omim.txt" );

while ( my $omim_entry = $omim_parser->next_phenotype() ) {
  # This prints everything.
  print( $omim_entry->to_string() );
  print "\n\n";

  # This gets individual data (some of them object-arrays)
  # (and illustrates the relevant methods of OMIMentry).

  my $numb  = $omim_entry->MIM_number();                     # *FIELD* NO
  my $title = $omim_entry->title();                          # *FIELD* TI - first line
  my $alt   = $omim_entry->alternative_titles_and_symbols(); # *FIELD* TI - additional lines
  my $mtt   = $omim_entry->more_than_two_genes();            # "#" before title
  my $sep   = $omim_entry->is_separate();                    # "*" before title
  my $desc  = $omim_entry->description();                    # *FIELD* TX
  my $mm    = $omim_entry->mapping_method();                 # from genemap
  my $gs    = $omim_entry->gene_status();                    # from genemap
  my $cr    = $omim_entry->created();                        # *FIELD* CD
  my $cont  = $omim_entry->contributors();                   # *FIELD* CN
  my $ed    = $omim_entry->edited();                         # *FIELD* ED
  my $sa    = $omim_entry->additional_references();          # *FIELD* SA
  my $cs    = $omim_entry->clinical_symptoms_raw();              # *FIELD* CS
  my $comm  = $omim_entry->comment();                        # from genemap

  my $mini_mim   = $omim_entry->miniMIM();                   # *FIELD* MN

    # A Bio::Phenotype::OMIM::MiniMIMentry object.
    # class Bio::Phenotype::OMIM::MiniMIMentry
    # provides the following:
    # - description()
    # - created()
    # - contributors()
    # - edited()
    #
    # Prints the contents of the MINI MIM entry (most OMIM entries do
    # not have MINI MIM entries, though).

  print $mini_mim->description()."\n";
  print $mini_mim->created()."\n";
  print $mini_mim->contributors()."\n";
  print $mini_mim->edited()."\n";

  my @corrs      = $omim_entry->each_Correlate();            # from genemap

    # Array of Bio::Phenotype::Correlate objects.
    # class Bio::Phenotype::Correlate
    # provides the following:
    # - name()
    # - description() (not used)
    # - species() (always mouse)
    # - type() ("OMIM mouse correlate")
    # - comment()

  my @refs       = $omim_entry->each_Reference();            # *FIELD* RF

    # Array of Bio::Annotation::Reference objects.

  my @avs        = $omim_entry->each_AllelicVariant();       # *FIELD* AV

    # Array of Bio::Phenotype::OMIM::OMIMentryAllelicVariant objects.
    # class Bio::Phenotype::OMIM::OMIMentryAllelicVariant
    # provides the following:
    # - number (e.g ".0001" )
    # - title (e.g "ALCOHOL INTOLERANCE" )
    # - symbol (e.g "ALDH2*2" )
    # - description (e.g "The ALDH2*2-encoded protein has a change ..." )
    # - aa_ori  (used if information in the form "LYS123ARG" is found)
    # - aa_mut (used if information in the form "LYS123ARG" is found)
    # - position (used if information in the form "LYS123ARG" is found)
    # - additional_mutations (used for e.g. "1-BP DEL, 911T")

  my @cps        = $omim_entry->each_CytoPosition();         # from genemap

    # Array of Bio::Map::CytoPosition objects.

  my @gss        = $omim_entry->each_gene_symbol();          # from genemap

    # Array of strings.

  # do something ...

}
bioperl omim.txt

1 answer

Generally speaking, if you want to print to a file, you need to either state that in the command line when running the script using >file.txt or you need to use a file handler in your script.

Considering the second option, what you are looking for is the open command.

use strict;

# Your script here until your first print statement

my $textfile = "/path/to/file.txt";
open ($fh, ">", $textfile) or die "Cannot open $textfile\n";
print $fh "This is the text you want to add to your file\n";
close ($fh);

Log in to answer this question.