Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Pseudocode for table data

by shabird (Sexton)
on Mar 17, 2020 at 17:29 UTC ( [id://11114393]=perlquestion: print w/replies, xml ) Need Help??

shabird has asked for the wisdom of the Perl Monks concerning the following question:

Hello guys, i am not very good at pseudocode can someone write pseudocode for this problem? The table below lists a number of genes, which names are specified in the left-most column, and their respective expression values in the remaining columns. That is, one row is for one gene and the values on this row are the expression values for that gene. From this table, calculate the mean expression value for each gene, i.e., for each row, calculate the mean of the values. The output should be a list of genes and their respective mean expression value. Thank you in advance.

GeneName E1 E2 E3 E4 ATA1 12 44 45 33 OSA2 100 79 85 83 DUA5 66 65 64 67 AXANT 4 4 6 2

Replies are listed 'Best First'.
Re: Pseudocode for table data
by stevieb (Canon) on Mar 17, 2020 at 17:33 UTC

    We do not do homework here, and we're not a free code-writing service either.

    You need to come up with the code yourself, then ask questions based on the specific issues you encounter along the way.

Re: Pseudocode for table data
by 1nickt (Canon) on Mar 17, 2020 at 20:58 UTC

    Hi,

    i am not very good at pseudocode

    Oh, dear. pseduocode == clear thinking. You're gonna need that.

    Try starting this way: on a piece of paper, using an analogue writing device, set down the steps you would take to solve the problem using math. Your problem definition has the skeleton answer already.

    (note use of BASIC line numbering to allow for inserted steps, lol)

    1. for each row, calculate the mean of the values.

    2. The output should be a list of genes and their respective mean expression value.
    Now fill in the sub-steps. To calculate the mean for a row, what do you have to do first? Maybe reading the row is a prerequisite to doing the calculation?

    (Possibly of interest: How to teach programming with a peanut butter and jelly sandwich)

    Hope this helps!


    The way forward always starts with a minimal test.
Re: Pseudocode for table data
by clueless newbie (Curate) on Mar 17, 2020 at 21:19 UTC

    Just for amusement:

    #!/usr/bin/env perl # 11114393 use Params::Validate(':all'); use 5.01800; use warnings; local $/; say <DATA>=~ s{^(.+)$}{with_mean($1)}gemr; exit; sub with_mean { my ($line)=validate_pos(@_,{ type=>SCALAR }); return $line if ($line =~ m{^GeneName}); my ($count,$sum); ()=$line=~ m{ (\d+)(?{ $count++; $sum+=$1; })}g; return "$line: @{[($sum+0.0)/$count]}"; }; __END__ GeneName E1 E2 E3 E4 ATA1 12 44 45 33 OSA2 100 79 85 83 DUA5 66 65 64 67 AXANT 4 4 6 2

    gives

    GeneName E1 E2 E3 E4 ATA1 12 44 45 33: 33.5 OSA2 100 79 85 83: 86.75 DUA5 66 65 64 67: 65.5 AXANT 4 4 6 2: 4
Re: Pseudocode for table data
by bliako (Monsignor) on Mar 18, 2020 at 09:01 UTC

    it's reassuring to see our bio-scientists are cracking on the vaccine case pretty hard. Queue King Crimson's Epitaph ("knowledge is a deadly friend").

    bw, bliako

Re: Pseudocode for table data
by BillKSmith (Monsignor) on Mar 18, 2020 at 22:36 UTC
    I am not sure what you mean by 'pseudocode'. I often start a small project such as this by writing a Perl program that is valid, but lacks important details. Here is a sample.
    use strict; use warnings; sub mean {...} my @genes = ( #'GeneName E1 E2 E3 E4', 'ATA1 12 44 45 33', 'OSA2 100 79 85 83', 'DUA5 66 65 64 67', 'AXANT 4 4 6 2', ); foreach (@genes) { my ($name, @values) = split; print $name, mean(@values); }

    It needs an implementation of the 'mean' function. It uses a hard coded array of strings rather than input. The output is unformatted. The default arguments of 'split' may not work as intended. Clearly, the highest priority is the function. I am not ashamed to use a module to do the heavy work.

    use List::Util qw(sum); ... sub mean { return sum(@_)/@_ }

    Now you should have a working program. Add input and output details until it meets your requirements. As a final step, you may want to replace the module with your own sum function.

    Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11114393]
Approved by 1nickt
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found