Skip to content
Snippets Groups Projects
Select Git revision
  • 4e2a19d557d4222dffe911c06d9d5cff421e334c
  • master default protected
  • exponential-backoff-login
  • v1.10.0
  • v1.9.2
  • v1.9.0
  • v1.8.8
  • v1.8.7
  • v1.8.5
  • v1.8.4
  • v1.8.2
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0.1
  • v1.0
  • v0.2.80
  • v0.2.79
23 results

tokens.py

Blame
  • Script2.1_create_data_file.py 1.71 KiB
    
    # -*- coding: utf-8 -*-
    """
    Created on Wed May 17 17:20:09 2017
    
    @author: apolline
    """
    
    import sys
    import os
    from rpy2 import robjects
    r = robjects.r
    
    ###############################################################################
    # Get the arguments from the batch command
    [pipeline_directory , analysis_directory, genotypes_file, summaryFile, i, SNP1, SNP2] = sys.argv[1:8]
    
    phenotypes_file   = analysis_directory + '/phenotypes_for_analysis.txt'
    covariates_file   = analysis_directory + '/covariates.txt'
    temp_directory    = analysis_directory + '/tmp'
    results_directory = analysis_directory + '/results_per_block'
    log_file          = analysis_directory + '/log_Script2.txt'
    
    # Import R script to run CMS
    r.source(pipeline_directory + '/others/Script2.2_run_CMS.R')
    
    # Define temporary data file and result file for this block
    temp_genotypes_file = temp_directory + '/temp_genotypes_' + i + '.txt'
    results_file = results_directory+'/results_' + i + '.txt'
    
    
    ###############################################################################
    # Create temporary data file by cutting the block from the genotype file
    k = int(SNP1) # start at SNP1
    command = 'cut -f2' # get second column (ID)
    
    while(k < (int(SNP2) + 1)): # end at SNP2
        command = command + ',' + str(k + 6) # get each SNP column between SNP1 and SNP2
        k = k + 1
    
    command = command + ' -d " " ' + genotypes_file + ' > ' + temp_genotypes_file # create the temporary file
    os.system(command)
    
    ###############################################################################
    # Launch the R script to run CMS on the created temporary file
    r.CMS_analysis(pipeline_directory, phenotypes_file, summaryFile, covariates_file, temp_genotypes_file, results_file)
    
    os.remove(temp_genotypes_file)