
%2014/09/03
%dlin5@tulane.edu
%Integrative analysis of multiple diverse omics datasets by sparse group multitask regression
%
%
clear all;
close all;
clc;

%load simulated discrete SNP data and phenotype
%Initial data sets
%data strcture
% Snpopts(SnpSetN)=struct('groupN',[],'groupK',[],'causalgene',[],'causalgeneN',[],'varsNIngene',[], ...
%                  'geneName',[],'groupInd',[],'Ind',[],'wgt_loss',[],'wgt_penalty',[]);
% Expopts(ExpSetN)=struct('groupN',[],'groupK',[],'causalgene',[],'causalgeneN',[],'varsNIngene',[], ...
%                  'geneName',[],'groupInd',[],'Ind',[],'wgt_loss',[],'wgt_penalty',[]);             
% strc_Snp(SnpSetN)=struct('datatype',[],'data',[],'causalsnp_orig',[],'pheno',[],'loca_causal',[],'causalbeta',[],'init',[],'opt',[]);
% strc_Exp(ExpSetN)=struct('datatype',[],'data',[],'causalsnp_orig',[],'pheno',[],'loca_causal',[],'causalbeta',[],'init',[],'opt',[]);
% 

load('sampledata.mat')
methodtype=[1,2];%1: sgl; 2:sgridge
len_method=length(methodtype);


for meth_Ind=1:len_method
    disp(strcat('methtype=',num2str(meth_Ind)));
    %calculate the max lambda value
    % lambda1;%group lasso 
    % lambda2;%lasso

    methtype=methodtype(meth_Ind);

    %first SNP dataset
    lambda2s=0.01*1000; 
    lambda1s=0.02*1000;
    tmplambda2s=lambda2s;
    tmplambda1s=lambda1s;
    strc_Input=strc_Snp(1);

    [x_11(meth_Ind),err_11(meth_Ind),Allopt_11{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);

     %second SNP dataset
%         tmplambda2s=tmplambda2s;
%         tmplambda1s=tmplambda1s;
    strc_Input=strc_Snp(2);
    [x_12(meth_Ind),err_12(meth_Ind),Allopt_12{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);

     %third SNP dataset
%          tmplambda2s=optlambda11_2;
%          tmplambda1s=optlambda11_1;
    strc_Input=strc_Snp(3);
    [x_13(meth_Ind),err_13(meth_Ind),Allopt_13{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);

    %

    %first EXP dataset
    lambda2s=0.2*50;
    lambda1s=0;
    tmplambda2s=lambda2s;
    tmplambda1s=lambda1s;
    strc_Input=strc_Exp(4);
    [x_21(meth_Ind),err_21(meth_Ind),Allopt_21{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);

    %Second EXP dataset
%          tmplambda2s=optlambda21_2;
%          tmplambda1s=optlambda21_1;
    strc_Input=strc_Exp(5);
    [x_22(meth_Ind),err_22(meth_Ind),Allopt_22{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);
    
    %Third EXP dataset
%          tmplambda2s=optlambda21_2;
%          tmplambda1s=optlambda21_1;
    strc_Input=strc_Exp(6);
    [x_23(meth_Ind),err_23(meth_Ind),Allopt_23{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);

    % %first SNP plus first EXP
    lambda2s=0.02*1000;
    lambda1s=0.03*1000;
    tmplambda2s=lambda2s;
    tmplambda1s=lambda1s;
    strc_Input=[strc_Snp(1),strc_Exp(4)];
    [x_3(:,meth_Ind),err_3(meth_Ind),Allopt_3{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);


    %All EXP datasets
    lambda2s=0.1*50;
    lambda1s=0.0*50;
    tmplambda2s=lambda2s;
    tmplambda1s=lambda1s;
    strc_Input=strc_Exp([4:6]);
    [x_4(:,meth_Ind),err_4(meth_Ind),Allopt_4{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);

    %All SNP datasets
    lambda2s=0.02*1000;
    lambda1s=0.02*1000;
    tmplambda2s=lambda2s;
    tmplambda1s=lambda1s;
    strc_Input=[strc_Snp(1:3)];
    [x_5(:,meth_Ind),err_5(meth_Ind),Allopt_5{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);

    %All SNP and EXP datasets
    lambda2s=0.01*350;
    lambda1s=0.05*350;
    tmplambda2s=lambda2s;
    tmplambda1s=lambda1s;
    strc_Input=[strc_Snp(1:3),strc_Exp(4:6)];
    [x_6(:,meth_Ind),err_6(meth_Ind),Allopt_6{meth_Ind}]=MultitaskRCD_both(methtype,strc_Input,[tmplambda1s tmplambda2s]);
end


