PEP 257
authorDimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
Wed, 17 Jul 2013 13:15:34 +0200
changeset 292 bb11a190f109
parent 291 dce1255ccd02
child 293 7b637a322eb2
PEP 257
ccplugin.py
importers/abide.py
importers/helpers.py
importers/imagen.py
importers/localizer.py
views/xcede.py
--- a/ccplugin.py	Fri Jul 05 17:52:22 2013 +0200
+++ b/ccplugin.py	Wed Jul 17 13:15:34 2013 +0200
@@ -32,7 +32,7 @@
 
 
 def copy_file(old_fpath, new_fpath, logger=None):
-    """ Safe copy of a file from one path to another
+    """Safe copy of a file from one path to another
     """
     if osp.isfile(old_fpath):
         if logger:
@@ -45,7 +45,7 @@
             raise
 
 def update_ident_fpath(session, subject_eid, uuid, delete=False, logger=None):
-    """ Update the identifier and paths of a subject
+    """Update the identifier and paths of a subject
     """
     if logger:
         logger.info('update_ident_fpath: processing subject %d...\n' % subject_eid)
@@ -100,11 +100,10 @@
 
 
 class BrainomicsRemakeUidCommand(Command):
-    """ Change subjects uids for anonymization.
+    """Change subjects uids for anonymization.
 
     <instance>
       the identifier of the instance to connect.
-
     """
     name = 'remake-uid'
     arguments = '<instance>'
--- a/importers/abide.py	Fri Jul 05 17:52:22 2013 +0200
+++ b/importers/abide.py	Wed Jul 17 13:15:34 2013 +0200
@@ -14,6 +14,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
+
 import csv
 import sys
 import os
@@ -35,7 +36,7 @@
 ### GROUPS AND SCORES #########################################################
 ###############################################################################
 def create_groups_and_categories(session):
-    """ Create groups and categories """
+    """Create groups and categories"""
     groups = {}
     groups[1] = store.create_entity('Group', identifier=u'abide_autism', name=u'Diagnostic group Autism').eid
     groups[2] = store.create_entity('Group', identifier=u'abide_control', name=u'Diagnostic group Control').eid
@@ -126,7 +127,7 @@
 ### QUESTIONNAIRES ############################################################
 ###############################################################################
 def create_adi_questionnaire(store):
-    """ Create a questionnaire for adi """
+    """Create a questionnaire for adi"""
     questionnaire_eid = store.create_entity('Questionnaire',
                                             name=u'Autism Diagnostic Interview-Revised (ADI)',
                                             identifier=u'abide_adi', type=u'behavioral').eid
@@ -169,7 +170,7 @@
     return questionnaire_eid, questions
 
 def create_ados_questionnaire(store):
-    """ Create a questionnaire for ados """
+    """Create a questionnaire for ados"""
     questionnaire_eid = store.create_entity('Questionnaire',
                                             name=u'Autism Diagnostic Observation Schedule Module (ADOS)',
                                             identifier=u'abide_ados', type=u'behavioral').eid
@@ -247,7 +248,7 @@
     return questionnaire_eid, questions
 
 def create_srs_questionnaire(store):
-    """ Create a questionnaire for srs """
+    """Create a questionnaire for srs"""
     questionnaire_eid = store.create_entity('Questionnaire',
                                             name=u'Social Responsiveness Scale Version',
                                             identifier=u'avide_srs', type=u'behavioral').eid
@@ -304,7 +305,7 @@
     return questionnaire_eid, questions
 
 def create_vineland_questionnaire(store):
-    """ Create a questionnaire for vineland """
+    """Create a questionnaire for vineland"""
     questionnaire_eid = store.create_entity('Questionnaire',
                                             name=u'Vineland Adaptive Behavior Scales',
                                             identifier=u'avide_vineland', type=u'behavioral').eid
@@ -417,7 +418,7 @@
     return questionnaire_eid, questions
 
 def create_wisc_iv_questionnaire(store):
-    """ Create a questionnaire for wisc_iv """
+    """Create a questionnaire for wisc_iv"""
     questionnaire_eid = store.create_entity('Questionnaire', name=u'WISC-IV',
                                             identifier=u'avide_wisc_iv', type=u'behavioral').eid
     questions = {}
--- a/importers/helpers.py	Fri Jul 05 17:52:22 2013 +0200
+++ b/importers/helpers.py	Wed Jul 17 13:15:34 2013 +0200
@@ -13,6 +13,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
+
 import csv
 import json
 import pickle
@@ -22,7 +23,7 @@
 
 
 def get_image_info(image_path, get_tr=True):
-    """ Return the image info readed from the image using Nibabel """
+    """Return the image info readed from the image using Nibabel"""
     img = nb.load(image_path)
     data = {}
     data['voxel_res_x'] = float(img.get_header()['pixdim'][1])
@@ -48,7 +49,7 @@
     return data
 
 def import_genes(ref_chr_path, ref_gene_path):
-    """ Import genes """
+    """Import genes"""
     chromosomes = json.load(open(ref_chr_path))
     ref_gene = []
     for row in csv.reader(open(ref_gene_path), delimiter='\t'):
@@ -63,7 +64,7 @@
     return ref_gene
 
 def import_chromosomes(ref_chr_path):
-    """ Import chromosomes """
+    """Import chromosomes"""
     chromosomes = json.load(open(ref_chr_path))
     chrs = []
     for chr_id in chromosomes:
@@ -74,7 +75,7 @@
     return chrs
 
 def import_snps(ref_chr_path, ref_snp_path):
-    """ Import snps """
+    """Import snps"""
     chromosomes = json.load(open(ref_chr_path))
     snps = []
     for row in csv.reader(open(ref_snp_path), delimiter='\t'):
--- a/importers/imagen.py	Fri Jul 05 17:52:22 2013 +0200
+++ b/importers/imagen.py	Wed Jul 17 13:15:34 2013 +0200
@@ -1,12 +1,13 @@
 # -*- coding: utf-8 -*-
 
-"""
-Classes for importing data from Imagen XNAT server
+"""Classes for importing data from Imagen XNAT server
+
 Expects XML dumps for metadata and raw images and genetic data
 Find additionnal data from FU2 processings
 
 Only the information about F-maps or contrast is kept
 """
+
 import logging
 import os
 from lxml import etree
@@ -245,7 +246,7 @@
     return None
 
 def format_filepath(filepath):
-    """ Correctly change the path, according to some user-defined conversions
+    """Correctly change the path, according to some user-defined conversions
     """
     if not filepath:
         return None
@@ -254,7 +255,7 @@
     return unicode(filepath)
 
 def iterate_external_resources(store, experiment, study_eid):
-    """ Iterate over all the possible external resources (resouce/file)
+    """Iterate over all the possible external resources (resouce/file)
     from an experiment node
     """
     added_files = set()
@@ -271,7 +272,7 @@
             yield {'name': filepath, 'filepath': filepath, 'related_study': study_eid}
 
 def iterate_investigators(node):
-    """ Iterate over the investigators of a node"""
+    """Iterate over the investigators of a node"""
     for assistant in node.findall('%sResearchAssistant' % IMAGEN):
         lastname = unicode(assistant.get('LastName'))
         # Cleanup lastname
@@ -280,7 +281,7 @@
             yield {'identifier': lastname, 'lastname': lastname}
 
 def iterate_score_value_infos(store, node, category, base_tag=XNAT):
-    """ Iterate possible score values over a node
+    """Iterate possible score values over a node
     """
     scores = []
     try:
@@ -299,7 +300,7 @@
 
 def build_score_value_infos(store, name, value, category=u'various',
                             unit=None, possible_values=None):
-    """ Build score value infos from a name and a value
+    """Build score value infos from a name and a value
     """
     try:
         _value = float(value)
@@ -354,7 +355,7 @@
 ### GENOMICS EXPERIMENT #######################################################
 ###############################################################################
 def import_genomics_scores(store, tree, experiment, study_eid, subject_eid, center_eid):
-    """ Import genomics scores
+    """Import genomics scores
     """
     # Create assessment
     measure_eid = import_generic_test_run(store, experiment, study_eid, subject_eid,
@@ -451,7 +452,7 @@
 def import_neuroimaging_raw_scan(store, tree, experiment, scan,
                                  assessment_eid, study_eid, subject_eid,
                                  center_eid, device_eid):
-    """ Import a raw scan with all the related entities
+    """Import a raw scan with all the related entities
     """
     # Classical case - Iterate over scans
     if not device_eid:
@@ -554,7 +555,7 @@
     return measure.eid
 
 def import_neuroimaging(store, tree, experiment, study_eid, subject_eid, center_eid):
-    """ Import a neuroimaging assessment from an experiment node"""
+    """Import a neuroimaging assessment from an experiment node"""
     # Create assessment
     assessment_eid = create_assessment_for_experiment(store, experiment,
                                                       study_eid, subject_eid, center_eid)
@@ -623,14 +624,14 @@
 ### BEHAVIOURAL EXPERIMENT ####################################################
 ###############################################################################
 def iterate_behavioural_trials(experiment, xml_ns):
-    """ Iterate over the trials of a behavioural experiment
+    """Iterate over the trials of a behavioural experiment
     """
     for trial in experiment.findall('%(s)strials/%(s)strial' % {'s': xml_ns}):
         yield dict([(key, value) for key, value in trial.items()
                     if key not in XNAT_TAGS_SKIPPED or key == 'ID'])
 
 def import_behavioural(store, tree, experiment, study_eid, subject_eid, center_eid):
-    """ Import a behavioural (as a type of psytool experiment)
+    """Import a behavioural (as a type of psytool experiment)
     """
     # Create behavioural data
     behavioural_run_eid, behavioural_eid = import_pystool_experiment(store, tree,
@@ -741,7 +742,7 @@
     return experiment_run_eid, experiment_eid
 
 def build_question_answer_infos(store, experiment, questionnaire_eid, questionnaire_run_eid):
-    """ Iterate over questions and answers for a questionnaire
+    """Iterate over questions and answers for a questionnaire
     """
     _type = experiment.attrib['%stype' % XSI].replace('psytool:', '').split('_')[0]
     # Construct questions from children
@@ -817,7 +818,7 @@
 ### GENERIC ASSESSMENT / EXPERIMENT ###########################################
 ###############################################################################
 def import_generic_test_run(store, experiment, study_eid, subject_eid, _type=None):
-    """ Import a generic measure from an experiment node
+    """Import a generic measure from an experiment node
     """
     # Create the GenericTest if it does not exist
     _type = unicode(experiment.get('%stype' % XSI)) if not _type else _type
@@ -882,7 +883,7 @@
     return assessment_eid
 
 def import_quality_report(store, tree, experiment, study_eid, subject_eid, center_eid):
-    """ Import the quality report assessment from an experiment node
+    """Import the quality report assessment from an experiment node
     """
     measure_eid = import_generic_test_run(store, experiment, study_eid, subject_eid)
     assessment_eid = create_assessment_for_experiment(store, experiment,
@@ -897,7 +898,7 @@
     return assessment_eid
 
 def import_generic_subject_assessments(store, tree, experiment, study_eid, subject_eid, center_eid):
-    """ Import generic assessments infos for various data of a subject,
+    """Import generic assessments infos for various data of a subject,
     such as raw package, clinical rate, ... as Questionnaires
     """
     testrun_eid = import_questionnaire(store, tree, experiment, study_eid, subject_eid, center_eid)
@@ -1044,7 +1045,7 @@
     return entity.eid
 
 def import_demographics(store, tree, subject_eid):
-    """ Import subject demographics (excluding gender and handedness)
+    """Import subject demographics (excluding gender and handedness)
     """
     demographics = tree.getroot().findall('%sdemographics' % XNAT)
     if not demographics:
@@ -1056,7 +1057,7 @@
                 store.relate(subject_eid, 'related_infos', score_value_eid)
 
 def import_subject_additional_infos(store, experiment, study_eid, subject_eid, center_eid):
-    """ Import subject additional infos (e.g. cyclePhaseInfo)
+    """Import subject additional infos (e.g. cyclePhaseInfo)
     """
     name = experiment.get('project', u'additional_infos')
     for score_value_infos in iterate_score_value_infos(store, experiment, name):
--- a/importers/localizer.py	Fri Jul 05 17:52:22 2013 +0200
+++ b/importers/localizer.py	Wed Jul 17 13:15:34 2013 +0200
@@ -53,7 +53,7 @@
 ### MedicalExp entities #######################################################
 ###############################################################################
 def import_subject(data_dir):
-    """ Import a subject from a data dir """
+    """Import a subject from a data dir"""
     data, score_values = {}, []
     info = json.load(open('%s/subject.json' % data_dir))
     data['identifier'] = info['nip']
@@ -68,7 +68,7 @@
     return data, score_values
 
 def import_study(data_dir):
-    """ Import a study from a data dir """
+    """Import a study from a data dir"""
     data = {}
     data['data_filepath'] = osp.abspath(data_dir)
     data['name'] = u'localizer'
@@ -76,7 +76,7 @@
     return data
 
 def import_center(data_dir):
-    """ Import a center """
+    """Import a center"""
     data = {}
     info = json.load(open('%s/subject.json' % data_dir))
     data['identifier'] = info['site']
@@ -93,7 +93,7 @@
     return data
 
 def import_device(data_dir):
-    """ Import a device """
+    """Import a device"""
     data = {}
     info = json.load(open('%s/subject.json' % data_dir))
     if info['site'] == u'Neurospin':
@@ -109,7 +109,7 @@
     return data
 
 def import_assessment(data_dir, label, study_eid):
-    """ Import an assessment """
+    """Import an assessment"""
     info = json.load(open('%s/subject.json' % data_dir))
     data = {}
     data['identifier'] = u'%s_%s' % (info['nip'], label)
@@ -128,7 +128,7 @@
 ### Neuroimaging entities #####################################################
 ###############################################################################
 def import_neuroimaging(data_dir, dtype='anat', norm_prep=False):
-    """ Import a neuorimaging scan """
+    """Import a neuorimaging scan"""
     scan_data, mri_data = {}, {}
     info = json.load(open('%s/subject.json' % data_dir))
     # Label and id
@@ -173,7 +173,7 @@
     return scan_data, mri_data
 
 def import_maps(data_dir, dtype='c'):
-    """ Import c/t maps """
+    """Import c/t maps"""
     info = json.load(open('%s/subject.json' % data_dir))
     base_path = os.path.join(data_dir, '%s_maps' % dtype)
     for img_path in glob.iglob(os.path.join(base_path, '*.nii.gz')):
@@ -199,7 +199,7 @@
         yield scan_data, mri_data, ext_resource
 
 def import_mask(data_dir):
-    """ Import a mask """
+    """Import a mask"""
     scan_data, mri_data = {}, {}
     info = json.load(open('%s/subject.json' % data_dir))
     scan_data['identifier'] = u'%s_mask' % info['exam']
@@ -219,7 +219,7 @@
 ### Questionnaire entities ####################################################
 ###############################################################################
 def import_questionnaire(data_dir):
-    """ Import a questionnaire and its questions """
+    """Import a questionnaire and its questions"""
     questionnaire = {}
     questionnaire['name'] = u'localizer questionnaire'
     questionnaire['identifier'] = u'localizer_questionnaire'
@@ -242,7 +242,7 @@
     return questionnaire, questions
 
 def import_questionnaire_run(data_dir, questionnaire_id, questions_id):
-    """ Import a questionnaire run """
+    """Import a questionnaire run"""
     run = {}
     behave = json.load(open('%s/behavioural.json' % data_dir))
     sid = os.path.split(data_dir)[1]
@@ -279,7 +279,7 @@
 ###############################################################################
 # XXX These functions may be pushed in helpers, as they may be more general
 def import_genomic_measures(genetics_dir):
-    """ Import a genomic measures """
+    """Import a genomic measures"""
     measure_path = os.path.join(genetics_dir, 'sprintBack', 'bysubj')
     g_measures = {}
     for path in glob.glob(os.path.join(measure_path, '*.bim')):
--- a/views/xcede.py	Fri Jul 05 17:52:22 2013 +0200
+++ b/views/xcede.py	Wed Jul 17 13:15:34 2013 +0200
@@ -25,7 +25,7 @@
 ### BASE XCEDE VIEW ###########################################################
 ###############################################################################
 class XcedeView(XMLView):
-    """ Xcede import """
+    """Xcede import"""
     __regid__ = 'xcede'
     title = _('xcede export')
     templatable = False