This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
genetica:preproc_models [2013/05/15 11:38] osotolongo created |
genetica:preproc_models [2020/08/04 10:58] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
===== Corriendo los modelos ====== | ===== Corriendo los modelos ====== | ||
Line 6: | Line 6: | ||
< | < | ||
- | $ plink plink --bfile archivo --model --allow-no-sex --out archivo | + | $ plink --bfile archivo --model --allow-no-sex --out archivo |
</ | </ | ||
Line 26: | Line 26: | ||
</ | </ | ||
+ | ===== Calculando los odds ratio y demas ===== | ||
+ | |||
+ | Quiero extraer un determinado modelo (e.g.: recesivo -> REC) de estos archivos y calcular los //odds ratio//, //standard error// y // | ||
+ | |||
+ | Hice un scriptcillo para ayudarme, | ||
+ | |||
+ | <code perl models.pl> | ||
+ | # | ||
+ | |||
+ | # Copyright 2013 O. Sotolongo < | ||
+ | |||
+ | # This program is free software; you can redistribute it and/or modify | ||
+ | # it under the terms of the GNU General Public License as published by | ||
+ | # the Free Software Foundation; either version 2 of the License, or | ||
+ | # (at your option) any later version. | ||
+ | # | ||
+ | # This program is distributed in the hope that it will be useful, | ||
+ | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
+ | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
+ | # GNU General Public License for more details. | ||
+ | # | ||
+ | use strict; use warnings; | ||
+ | use File::Slurp qw(read_file); | ||
+ | use Text:: | ||
+ | |||
+ | my $plist = shift; | ||
+ | my $model = shift; | ||
+ | my $bimfile = shift; | ||
+ | die " | ||
+ | |||
+ | my $ofile = $plist; | ||
+ | $ofile =~ s/ | ||
+ | # cambiar a clustering con (?:PATTERN) | ||
+ | my %input_data = reverse map {/ | ||
+ | my %bim_data = map {/ | ||
+ | my %cells; | ||
+ | foreach my $marker (sort keys %input_data){ | ||
+ | (@{$cells{$marker}} {qw/chr allele1 allele2 affa1 affa2 unaffa1 unaffa2 chi2 df pval0/}) = $input_data{$marker} =~ / | ||
+ | if(exists($cells{$marker}{affa1}) && exists($cells{$marker}{affa2}) && exists($cells{$marker}{unaffa1}) && exists($cells{$marker}{unaffa2})){ | ||
+ | my $affa1 = $cells{$marker}{affa1}; | ||
+ | my $affa2 = $cells{$marker}{affa2}; | ||
+ | my $unaffa1 = $cells{$marker}{unaffa1}; | ||
+ | my $unaffa2 = $cells{$marker}{unaffa2}; | ||
+ | my $t1 = $affa1 + $affa2; | ||
+ | my $t2 = $affa1 + $unaffa1; | ||
+ | my $t3 = $t1 + $unaffa1 + $unaffa2; | ||
+ | $cells{$marker}{pvalue} = calculateStatistic(n11=> | ||
+ | $affa1 = 0.1 unless ($affa1); | ||
+ | $affa2 = 0.1 unless ($affa2); | ||
+ | $unaffa1 = 0.1 unless ($unaffa1); | ||
+ | $unaffa2 = 0.1 unless ($unaffa2); | ||
+ | $cells{$marker}{afreq} = $affa1/ | ||
+ | $cells{$marker}{ufreq} = $unaffa1/ | ||
+ | $cells{$marker}{oddsratio} = ($affa1*$unaffa2)/ | ||
+ | $cells{$marker}{stderr} = sqrt((1/ | ||
+ | } | ||
+ | } | ||
+ | |||
+ | my $head = " | ||
+ | open ODF, "> | ||
+ | print ODF " | ||
+ | |||
+ | foreach my $marker (sort {($cells{$a}-> | ||
+ | if(exists($bim_data{$marker})){ | ||
+ | print ODF " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | close ODF; | ||
+ | </ | ||
+ | |||
+ | La orden, | ||
+ | |||
+ | < | ||
+ | $ models.pl admurcia_model.model REC ../ | ||
+ | </ | ||
+ | |||
+ | extrae el modelo recesivo, calcula los valores deseados y los añade a los ya existentes en el archivo // | ||
+ | |||
+ | Para correr todas las DBs juntas hago, | ||
+ | < | ||
+ | $ for x in `ls *.model | grep -v recalc`; do models.pl $x REC ../ | ||
+ | </ | ||
+ | y | ||
+ | < | ||
+ | $ for x in `ls *.model | grep -v recalc`; do models.pl $x DOM ../ | ||
+ | </ | ||
+ | |||
+ | dado que me interesan solo los modelos dominate y recesivo. | ||
+ | ===== Meta analisis con plink ===== | ||
+ | Para terminar basta con correr plink sobre todas las bases procesadas, | ||
+ | < | ||
+ | $ a=$(ls *REC*); plink --meta-analysis $a + study --out recesivo | ||
+ | </ | ||
+ | y | ||
+ | < | ||
+ | $ a=$(ls *DOM*); plink --meta-analysis $a + study --out dominante | ||
+ | </ | ||
+ | |||
+ | Los resultados salen ordenados por cromosoma y SNP. Para ordenar por //p-value// puede hacerse, | ||
+ | |||
+ | < | ||
+ | $ sort -g -k7,7 dominante.meta > dominante.meta.sorted | ||
+ | </ | ||
+ | |||
+ | para cortar por un valor especifico de // | ||
+ | |||
+ | < | ||
+ | $ awk {' | ||
+ | </ | ||
+ | |||
+ | y si estamos interesados en algun SNP especifico, | ||
+ | |||
+ | < | ||
+ | $ echo "DB `head -n 1 ADNIimpQC2.REC.recalc.model`" | ||
+ | $ for x in *REC*; do echo " | ||
+ | </ | ||
+ | |||
+ | ====== Alternativa a Fisher: Barnard Test ====== | ||
+ | |||
+ | Como al blandengue no le gusta el test de Fisher, he buscado como hacer que el script me calcule los test de Barnard. No he encontrado ningun modulo en Perl pero como todo ya esta inventado en esta vida hay un paquete en R que lo calcula. Asi que lo que he hecho es usar el modulo **Statistics:: | ||
+ | |||
+ | Esto es un poco enredado pero se resume en sustituir la llamada al test de Fisher con, | ||
+ | |||
+ | <code perl> | ||
+ | my $shit = Statistics:: | ||
+ | $shit-> | ||
+ | $shit-> | ||
+ | $shit-> | ||
+ | $cells{$marker}{pvalue} = shit-> | ||
+ | </ | ||
+ | |||
+ | **OJO:** Esto demora muchisimo. Despues de 5 días de calculo sobre una base de datos y modelo dominate tuve que para la ejecucion. Lo lanzare cuando tenga tiempo y la base de datos a usar este definida. |