Randomising gene expression data
1
0
Entering edit mode
8.0 years ago
Tom ▴ 50

Hi all, I wanted to use the Fisher Yates permutation method to randomise this data set 10 times:

ID      Sub1    Sub2    Sub3    Sub4 
Creb    3.1     10.14   9.67    10.14  
Chchd6  11.25   10.74   10.80   11.07 
Arih1   9.91    9.25    10.20   9.34 
Prpf8   11.54   11.58   11.14   11.36 
Rfng    11.71   11.56   10.81   10.72
Rnf114  12.66   12.60   12.59   12.56

I originally wanted to write the code in python, and I tried writing various bits of code that would make 10 output files, each with one randomisation of the data using the Fisher Yates permutation method. One example of code I tried to write is below (in this case, just trying to print out each randomisation set to screen, followed by *, then I'll work out writing it to a file after):

import sys
   import itertools
   from itertools import permutations

   for i in range(10):
        for line in open(sys.argv[1]).readlines()[2:]:
            line = line.strip().split()
            gene_name = line[0]
            expression_values = line[1:]
            for shuffle in permutations(expression_values):
                print shuffle[:6]
            print "***"
    i +=1

Basically this, and all variants of this, are failing, and I just don't understand how to do it. I'm wondering if anyone knows of an alternative way of doing a fisher yates model to produce 10 randomisations of the data set? I couldn't seem to find an R package? Thanks.

randomisation gene expression python • 1.4k views
ADD COMMENT
0
Entering edit mode

Why do you want to use the Fisher Yates permutation instead of a standard permutation out of interest?

ADD REPLY
2
Entering edit mode
8.0 years ago

Here is my perl implementation:

=head2 shuffle
 Arg: array reference
 Description: Randomly shuffles the array using the Fisher-Yates algorithm.
 Returntype: array reference
=cut

sub shuffle {

  my $array = shift;
  my $i = @$array;
  while ($i--) {
    my $j = int rand ($i+1);
    next if $i == $j;
    @$array[$i,$j] = @$array[$j,$i];
  }
  return $array;
}

A python implementation (among others, including R) is available on Rosetta code where it also says there's a built in Python function for this: random.shuffle.
R has the fyshuffle() function in package fgpt.

ADD COMMENT

Login before adding your answer.

Traffic: 2106 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6