Commit b82ff6c2 authored by Penom Nom's avatar Penom Nom
Browse files

No commit message

No commit message
parent 21811f95
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/nG6-current/core</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/nG6-meta2/core</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>
#
# Copyright (C) 2009 INRA
#
# 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 3 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. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__ = 'Plateforme genomique Midi Pyrenees'
__copyright__ = 'Copyright (C) 2009 INRA'
__license__ = 'GNU General Public License'
__version__ = '1.0'
__email__ = 'support.genopole@toulouse.inra.fr'
__status__ = 'beta'
import os, re, glob, sys
from optparse import *
from time import localtime, strftime
# Add a file to input_elements.
# @usage : add_element( elem, input_elements, casava_regexp )
# @param : elem string File path.
# @param : input_elements dictionary File list.
# @param : casava_regex string Regex describing the structure used for the path of output files of CASAVA usable by the casava option of FASTQC.
def add_element ( elem, input_elements, casava_regex ):
is_casava_file = re.search(casava_regex, elem)
# Set the key
if( is_casava_file ):
key = is_casava_file.group(1)
else:
key = os.path.basename(elem)
# If an other file for this read already exists
if( key in input_elements ):
input_elements[key]['files_path'] += " " + elem
input_elements[key]['fastqc_opt'] = "--casava"
# Otherwise
else:
input_elements[key] = {}
input_elements[key]['files_path'] = elem
input_elements[key]['fastqc_opt'] = ""
# Check mandatory parameters.
# @usage : check_parameters()
def check_parameters ():
# handle required arguments
if( not options.output_iter_list ):
sys.stderr.write( "No output defined.\n" )
sys.exit(1)
# at least one input type is required
if( not (options.input_file_list or options.input_file or options.input_directory) ):
sys.stderr.write( "No input defined.\n" )
sys.exit(1)
if( options.input_directory and not options.input_directory.endswith('/') ):
options.input_directory = options.input_directory + "/"
# Loads the informations of iteration on input_elements.
# @usage : gather_input_elements ( iterable_file_list, regexp )
# @param : iterable_file_list dictionary File list.
# @param : regexp string Regex describing the structure used for the path of output files of CASAVA usable by the casava option of FASTQC.
# @return : element_count int The file number.
def gather_input_elements ( iterable_file_list, regexp ):
element_count = 0
###
# All three input options can be used in tandem, so we check every one.
###
# Handle any input file lists
if ( options.input_file_list ):
#For each containing list file
for input_file_list in ( options.input_file_list.rsplit(',') ):
#If file list is compressed
if ( input_file_list.endswith( '.gz' ) or input_file_list.endswith( '.gzip' ) ):
sys.stderr.write( "Support unavailable for processing gzipped file lists.\n" )
sys.exit(1)
FH_InFileList = open(input_file_list, "r" )
#For each file lists in file
for line in FH_InFileList:
empty_line = re.search('^\s*$', line)
if ( not empty_line ):
line = line.rstrip()
add_element( line, input_elements, regexp )
element_count = element_count + 1
# Handle any directories
if ( options.input_directory ):
#For each directory
for input_directory in ( options.input_directory.rsplit(',') ):
dir_files = glob.glob( input_directory + '*' )
#For each element in directory
for one_file in dir_files:
# Only consider files
if( os.path.isfile(one_file) ):
# If the extension is defined, the file must match it
if ( (not options.input_directory_extension) or one_file.endswith( '.' + options.input_directory_extension ) ):
add_element( one_file, input_elements, regexp )
element_count = element_count + 1
# Handle any individual files
if ( options.input_file ):
#For each file
for input_file in ( options.input_file.rsplit(',') ):
add_element( input_file, input_elements, regexp )
element_count = element_count + 1
return element_count
if __name__ == '__main__':
##
# Manage options
##
parser = OptionParser(usage="%prog -o OUTPUT_FILE [-f INPUT_FILE] [-l INPUT_FILE_LIST] [-d INPUT_DIRECTORY [-e INPUT EXTENSION]] [-t]", description="Generates list file from various input sources of filenames. This script is used to accept a selection of inputs from either an input list, directory, file, or any combination thereof. Each of these options can also be specified using comma-separated lists.")
igroup = OptionGroup(parser, "options","")
igroup.add_option("-o", "--output_iter_list", help="Desired path to output iterator file.", dest="output_iter_list")
igroup.add_option("-f", "--input_file", help="The full path to an input file. this can also be a comma-separated list of input files.", dest="input_file")
igroup.add_option("-l", "--input_file_list", help="Plain text file containing the full paths to any number of files, one per line. This can also be a comma-separated list of input file lists.", dest="input_file_list")
igroup.add_option("-d", "--input_directory", help="The full path to an input directory. This can also be a comma-separated list of input directories.", dest="input_directory")
igroup.add_option("-e", "--input_directory_extension", help="To be used in conjuction with the input_directory option, this can be used to filter files by extension within any passed input directories.", dest="input_directory_extension")
igroup.add_option("-t", "--timestamp", help="Add timestamp to each output line.", dest="timestamp", action="store_true")
parser.add_option_group(igroup)
(options, args) = parser.parse_args()
check_parameters()
##
# Set variables
##
# Regex to identify the output files of CASAVA 1.8 (for 'casava' option in FASTQC)
casava_output_regexp = '.+\/([^\/]+_[^\/]+_[^\/]+_[^\/]+)_[^\/]+\.fastq\.gz'
# Play nicely
os.umask(0000)
# Structure like input_elements{file_id:{'files_path':files_path, 'fastqc_opt':fastqc_opt}}. It store output informations.
input_elements = {}
##
# Load informations on input_elements
##
input_element_count = gather_input_elements( input_elements, casava_output_regexp )
##
# Create output file
##
FH_output = open( options.output_iter_list, "w" )
# Header line
FH_output.write( '$;I_FILE_BASE$;' + "\t" + '$;FASTQC_OPT$;' + "\t" '$;I_FASTQC_FILES$;' )
# Timestamp
timestamp = ""
if( options.timestamp ):
FH_output.write( "\t" + '$;I_TIMESTAMP$;' )
timestamp = strftime("%b %d %Y %I:%H%p", localtime())
FH_output.write( "\n" )
# For each future iteration
for file_name in input_elements.keys():
FH_output.write( file_name + "\t" + input_elements[file_name]['fastqc_opt'] + "\t" + input_elements[file_name]['files_path'] )
if( options.timestamp ):
FH_output.write( "\t" + timestamp )
FH_output.write( "\n" )
FH_output.close
#
# Copyright (C) 2009 INRA
#
# 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 3 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. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__ = 'Plateforme genomique Midi Pyrenees'
__copyright__ = 'Copyright (C) 2009 INRA'
__license__ = 'GNU General Public License'
__version__ = '1.0'
__email__ = 'support.genopole@toulouse.inra.fr'
__status__ = 'beta'
import os, re, glob, sys
from optparse import *
from time import localtime, strftime
# Add a file to input_elements.
# @usage : add_element( elem, input_elements, casava_regexp )
# @param : elem string File path.
# @param : input_elements dictionary File list.
# @param : casava_regex string Regex describing the structure used for the path of output files of CASAVA usable by the casava option of FASTQC.
def add_element ( elem, input_elements, casava_regex ):
is_casava_file = re.search(casava_regex, elem)
# Set the key
if( is_casava_file ):
key = is_casava_file.group(1)
else:
key = os.path.basename(elem)
# If an other file for this read already exists
if( key in input_elements ):
input_elements[key]['files_path'] += " " + elem
input_elements[key]['fastqc_opt'] = "--casava"
# Otherwise
else:
input_elements[key] = {}
input_elements[key]['files_path'] = elem
input_elements[key]['fastqc_opt'] = ""
# Check mandatory parameters.
# @usage : check_parameters()
def check_parameters ():
# handle required arguments
if( not options.output_iter_list ):
sys.stderr.write( "No output defined.\n" )
sys.exit(1)
# at least one input type is required
if( not (options.input_file_list or options.input_file or options.input_directory) ):
sys.stderr.write( "No input defined.\n" )
sys.exit(1)
if( options.input_directory and not options.input_directory.endswith('/') ):
options.input_directory = options.input_directory + "/"
# Loads the informations of iteration on input_elements.
# @usage : gather_input_elements ( iterable_file_list, regexp )
# @param : iterable_file_list dictionary File list.
# @param : regexp string Regex describing the structure used for the path of output files of CASAVA usable by the casava option of FASTQC.
# @return : element_count int The file number.
def gather_input_elements ( iterable_file_list, regexp ):
element_count = 0
###
# All three input options can be used in tandem, so we check every one.
###
# Handle any input file lists
if ( options.input_file_list ):
#For each containing list file
for input_file_list in ( options.input_file_list.rsplit(',') ):
#If file list is compressed
if ( input_file_list.endswith( '.gz' ) or input_file_list.endswith( '.gzip' ) ):
sys.stderr.write( "Support unavailable for processing gzipped file lists.\n" )
sys.exit(1)
FH_InFileList = open(input_file_list, "r" )
#For each file lists in file
for line in FH_InFileList:
empty_line = re.search('^\s*$', line)
if ( not empty_line ):
line = line.rstrip()
add_element( line, input_elements, regexp )
element_count = element_count + 1
FH_InFileList.close
# Handle any directories
if ( options.input_directory ):
#For each directory
for input_directory in ( options.input_directory.rsplit(',') ):
dir_files = glob.glob( input_directory + '*' )
#For each element in directory
for one_file in dir_files:
# Only consider files
if( os.path.isfile(one_file) ):
# If the extension is defined, the file must match it
if ( (not options.input_directory_extension) or one_file.endswith( '.' + options.input_directory_extension ) ):
add_element( one_file, input_elements, regexp )
element_count = element_count + 1
# Handle any individual files
if ( options.input_file ):
#For each file
for input_file in ( options.input_file.rsplit(',') ):
add_element( input_file, input_elements, regexp )
element_count = element_count + 1
return element_count
if __name__ == '__main__':
##
# Manage options
##
parser = OptionParser(usage="%prog -o OUTPUT_FILE [-f INPUT_FILE] [-l INPUT_FILE_LIST] [-d INPUT_DIRECTORY [-e INPUT EXTENSION]] [-t]", description="Generates list file from various input sources of filenames. This script is used to accept a selection of inputs from either an input list, directory, file, or any combination thereof. Each of these options can also be specified using comma-separated lists.")
igroup = OptionGroup(parser, "options","")
igroup.add_option("-o", "--output_iter_list", help="Desired path to output iterator file.", dest="output_iter_list")
igroup.add_option("-f", "--input_file", help="The full path to an input file. this can also be a comma-separated list of input files.", dest="input_file")
igroup.add_option("-l", "--input_file_list", help="Plain text file containing the full paths to any number of files, one per line. This can also be a comma-separated list of input file lists.", dest="input_file_list")
igroup.add_option("-d", "--input_directory", help="The full path to an input directory. This can also be a comma-separated list of input directories.", dest="input_directory")
igroup.add_option("-e", "--input_directory_extension", help="To be used in conjuction with the input_directory option, this can be used to filter files by extension within any passed input directories.", dest="input_directory_extension")
igroup.add_option("-t", "--timestamp", help="Add timestamp to each output line.", dest="timestamp", action="store_true")
parser.add_option_group(igroup)
(options, args) = parser.parse_args()
check_parameters()
##
# Set variables
##
# Regex to identify the output files of CASAVA 1.8 (for 'casava' option in FASTQC)
casava_output_regexp = '.+\/([^\/]+_[^\/]+_[^\/]+_[^\/]+)_[^\/]+\.fastq\.gz'
# Play nicely
os.umask(0000)
# Structure like input_elements{file_id:{'files_path':files_path, 'fastqc_opt':fastqc_opt}}. It store output informations.
input_elements = {}
##
# Load informations on input_elements
##
input_element_count = gather_input_elements( input_elements, casava_output_regexp )
##
# Create output file
##
FH_output = open( options.output_iter_list, "w" )
# Header line
FH_output.write( '$;I_FILE_BASE$;' + "\t" + '$;FASTQC_OPT$;' + "\t" '$;I_FASTQC_FILES$;' )
# Timestamp
timestamp = ""
if( options.timestamp ):
FH_output.write( "\t" + '$;I_TIMESTAMP$;' )
timestamp = strftime("%b %d %Y %I:%H%p", localtime())
FH_output.write( "\n" )
# For each future iteration
for file_name in input_elements.keys():
FH_output.write( file_name + "\t" + input_elements[file_name]['fastqc_opt'] + "\t" + input_elements[file_name]['files_path'] )
if( options.timestamp ):
FH_output.write( "\t" + timestamp )
FH_output.write( "\n" )
FH_output.close
sys.exit(0)
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009 PF bioinformatique de Toulouse <>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project 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.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script 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. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
require_once(PATH_t3lib.'class.t3lib_befunc.php');
require_once(PATH_t3lib.'stddb/tables.php');
require_once(t3lib_extMgm::extPath('cms','ext_tables.php'));
require_once(PATH_t3lib.'class.t3lib_db.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_db.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_process.php');
/**
* Class 'tx_nG6_eid' for the 'nG6' extension.
* This class is in charge of all communication between the client and the server using AJAX
*
* @author PF bioinformatique de Toulouse <>
*/
class tx_nG6_eid {
/**
* The main function of the tx_nG6_eid, this function is the one called when using ajax
*/
function main() {
// Connect to the databse
tslib_eidtools::connectDB();
$type = trim(t3lib_div::_GP('type'));
$user_group = trim(t3lib_div::_GP('user_group'));
// If the type of data requested is project
if ($type == 'project') {
$project_id = trim(t3lib_div::_GP('id'));
// Select all runs linked to the project
$project_runs = tx_nG6_db::get_project_runs($user_group, $project_id, 'tx_nG6_run.date DESC');
// for each run
$html_tree = '';
foreach($project_runs as $run_id => $run_values) {
$html_tree .= '<li class="jstree-closed" name=\''.str_replace(array('###SPAN_NAME###', '###SPAN_DATE###'), array($run_values['name'], strftime('%d-%m-%y',$run_values['date'])), trim(t3lib_div::_GP('run_short_description'))).'\' id=\''.$run_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###', '###SPAN_DATE###', '###SPAN_NB_SEQ###', '###SPAN_SPECIES###'), array($run_values['name'], strftime('%d-%m-%y',$run_values['date']), $run_values['nb_sequences'], $run_values['species']), trim(t3lib_div::_GP('run_description'))).'</a></li>';
}
// Then all project analysis
$project_analysis = tx_nG6_db::get_project_analysis($user_group, $project_id, 'tx_nG6_analyze.name');
foreach($project_analysis as $analyse_id => $analyse_values) {
$html_tree .= '<li name=\''.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'\' id=\''.$analyse_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'</a></li>';
}
// Return the html_tree
print $html_tree;
// If the type of data requested is run
} else if ($type == 'run'){
$run_id = trim(t3lib_div::_GP('id'));
// Select all analysis linked to the run and the run information
$run_analysis = tx_nG6_db::get_run_analysis($user_group, $run_id, 'tx_nG6_analyze.name');
$run_info = tx_nG6_db::select_run($run_id);
// for each analysis
$html_tree = '';
$html_tree .= '<li name=\'run_'.$run_id.'_'.trim(t3lib_div::_GP("raw_data_description")).'\' id=\'data_'.$run_id.'\'> <a href=\'#\'>'.trim(t3lib_div::_GP("raw_data_description")).'</a></li>';
foreach($run_analysis as $analyse_id => $analyse_values) {
$html_tree .= '<li name=\'run_'.$run_id.'_'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'\' id=\''.$analyse_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'</a></li>';
}
// Return the html_tree
print $html_tree;
// If downloading data is requested
} else if ($type == 'download') {
$format = trim(t3lib_div::_GP('format'));
// If link in home directory
if ($format == 'home_link') {
$ids = trim(t3lib_div::_GP('ids'));
$data_folder = trim(t3lib_div::_GP('data_folder'));
$user_login = trim(t3lib_div::_GP('user_login'));
$user_pwd = trim(t3lib_div::_GP('user_pwd'));
$user_directory = trim(t3lib_div::_GP('user_directory'));
$retcode = $this->create_symbolic_links($user_group, $user_login, $user_pwd, $ids, $data_folder, $user_directory);
print $retcode;
// If a .tar.gz file
} else {
$ids = trim(t3lib_div::_GP('ids'));
$data_folder = trim(t3lib_div::_GP('data_folder'));
$tmp_folder = trim(t3lib_div::_GP('tmp_folder'));
$user_email = trim(t3lib_div::_GP('user_email'));
$title_email = trim(t3lib_div::_GP('title_email'));
$msg_email = trim(t3lib_div::_GP('msg_email'));
$archive_info = $this->create_archive_script($user_group, $ids, $data_folder, $tmp_folder, "tar.gz", $user_email, $title_email, $msg_email);
$process = new Process("tcsh ".$archive_info[0]);
print "pid=".$process->getPid()."&archive_path=".$archive_info[1];
}
// If asked to check a job status
} else if($type == 'check_status') {
$pid = trim(t3lib_div::_GP('pid'));
$archive_path = trim(t3lib_div::_GP('archive_path'));
$process = new Process();
$process->setPid($pid);
// If the job is done
if ($process->status()) {
print "pid=0&archive_path=".$archive_path;
// If the job is still runing
} else {
print "pid=".$process->getPid()."&archive_path=".$archive_path;
}
// If asked to hide a {project/run}
} else if ($type == 'hide') {
$ids = trim(t3lib_div::_GP('ids'));
// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
$tab_ids = explode(";",$ids);
$hide_level = trim(t3lib_div::_GP('hide_level'));
if ($hide_level == 'project') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::hide_project($value, $user_group);
}
} else if ($hide_level == 'run') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::hide_run($value, $user_group);
}
} else if ($hide_level == 'analysis') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::hide_analysis($value, $user_group);
}
}
// If asked to unhide a {project/run}
} else if ($type == 'unhide') {
$ids = trim(t3lib_div::_GP('ids'));
// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
$tab_ids = explode(";",$ids);
$unhide_level = trim(t3lib_div::_GP('unhide_level'));
if ($unhide_level == 'project') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::unhide_project($value, $user_group);
}
} else if ($unhide_level == 'run') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::unhide_run($value, $user_group);
}
} else if ($unhide_level == 'analysis') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::unhide_analysis($value, $user_group);
}
}
// If asked to delete a {project/run/analyze}
} else if ($type == 'delete') {
$ids = trim(t3lib_div::_GP('ids'));
// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
$tab_ids = explode(";",$ids);
$delete_level = trim(t3lib_div::_GP('del_level'));
$data_folder = trim(t3lib_div::_GP('data_folder'));
$user_login = trim(t3lib_div::_GP('user_login'));
$user_pwd = trim(t3lib_div::_GP('user_pwd'));
$res = 0;
// check login and password
if (isset($user_login) && isset($user_pwd) && $user_login != 'undefined' && $user_pwd != 'undefined') {
$res = 0;
$connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) { $res = 3; }
if (!ssh2_auth_password($connection, $user_login, $user_pwd)) { $res=2;}
} else {
$res = 3;
}
if ($res == 0) {
if ($delete_level == 'project') {
foreach($tab_ids as $id => $value) {
$res = tx_nG6_db::delete_project($user_group, $value, $user_login, $user_pwd, $data_folder);
if ($res != 0)