Beispiel #1
0
def _project_experimentstable_experiments(dbs, confs, raw=True, where=False):
    """Return a list of experiments for a project."""
    conf = confs['configurations'][0]
    # Only return the experiment infos if this is an official project
    sql = """
select experiment_id,
       species_info.species,
       genome_files.genome,
       genome_files.location,
       genome_files.assembly,
       genome_files.gender,
       annotation_files.annotation,
       annotation_files.location,
       annotation_files.version,
       template_file,
       read_length,
       mismatches,
       exp_description,
       expDate,
       CellType,
       RNAType,
       Compartment,
       Bioreplicate,
       partition,
       annotation_version,
       lab,
       paired
from experiments,
     species_info,
     genome_files,
     annotation_files
"""
    if where:
        meta = get_experiment_dict(confs)
        sql = """%s
%s
and
""" % (sql, get_experiment_where(confs, meta))
    else:
        sql = """%s
where
    project_id = '%s'
and
""" % (sql, conf['projectid'])

    sql = """%s
      experiments.species_id = species_info.species_id
and
      experiments.genome_id = genome_files.genome_id
and
      experiments.annotation_id = annotation_files.annotation_id
""" % sql

    sql = """%s
%s""" % (sql, get_experiment_order_by(confs))

    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()
    experimentids = {}

    rna_extracts = get_rna_extract_display_mapping(dbs)
    cells = get_cell_display_mapping(dbs)
    localizations = get_localization_display_mapping(dbs)

    for row in rows:
        meta = {}
        meta['projectid'] = conf['projectid']
        meta['read_length'] = row[10]
        meta['cell'] = row[14]
        meta['rnaExtract'] = row[15]
        meta['localization'] = row[16]
        meta['bio_replicate'] = row[17]
        meta['partition'] = row[18]
        meta['annotation_version'] = row[19]
        meta['lab'] = row[20]
        meta['paired'] = row[21]
        if not meta['paired'] is None:
            meta['paired'] = ord(meta['paired'])
        meta['parameter_list'] = get_parameter_list(confs)
        meta['parameter_values'] = get_parameter_values(confs, meta)

        if not raw:
            get_experiment_labels(meta, rna_extracts, cells, localizations)

        if meta['parameter_values'] in experimentids:
            experimentids[meta['parameter_values']].append(meta)
        else:
            experimentids[meta['parameter_values']] = [meta]
    return experimentids
Beispiel #2
0
def replicate_info(dbs, confs):
    """Collect some general information about a replicate"""
    description = [('Read Length', 'number'),
                   ('Mismatches', 'number'),
                   ('Description', 'string'),
                   ('Date', 'string'),
                   ('Cell Type', 'string'),
                   ('RNA Type', 'string'),
                   ('Localization', 'string'),
                   ('Bio Replicate', 'string'),
                   ('Partition', 'string'),
                   ('Paired', 'number'),
                   ('Species', 'string'),
                   ('Annotation Version', 'string'),
                   ('Annotation Source', 'string'),
                   ('Genome Assembly', 'string'),
                   ('Genome Source', 'string'),
                   ('Genome Gender', 'string'),
                   ]
    chart = {}
    chart['table_description'] = description
    result = []
    conf = confs['configurations'][0]
    sql = """
select experiment_id,
       project_id,
       species_id,
       genome_id,
       annotation_id,
       template_file,
       read_length,
       mismatches,
       exp_description,
       expDate,
       CellType,
       RNAType,
       Compartment,
       Bioreplicate,
       partition,
       paired
from experiments
where project_id='%(projectid)s'
      and experiment_id='%(replicateid)s'""" % conf
    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()

    species_id = rows[0][2]
    genome_id = rows[0][3]
    annotation_id = rows[0][4]
    result.append(int(rows[0][6]))
    result.append(int(rows[0][7]))
    result.append(rows[0][8])
    result.append(str(rows[0][9]))
    # Use labels instead of the raw values
    mapping = get_cell_display_mapping(dbs)
    result.append(mapping.get(rows[0][10], rows[0][10]))
    mapping = get_rna_extract_display_mapping(dbs)
    result.append(mapping.get(rows[0][11], rows[0][11]))
    mapping = get_localization_display_mapping(dbs)
    result.append(mapping.get(rows[0][12], rows[0][12]))
    result.append(rows[0][13])
    result.append(rows[0][14])
    result.append(rows[0][15])
    if not result[-1] is None:
        result[-1] = ord(result[-1])
    sql = """
select species_id,
       species,
       genus,
       sp_alias,
       abbreviation
from species_info
where species_id='%s'
""" % species_id
    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()
    result.append(rows[0][1])

    sql = """
select annotation_id,
       species_id,
       annotation,
       location,
       version,
       source
from annotation_files where annotation_id='%s'
""" % annotation_id
    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()
    result.append(rows[0][4])
    result.append(rows[0][5])

    sql = """
select genome_id,
       species_id,
       genome,
       location,
       assembly,
       source,
       gender
from genome_files where genome_id='%s'
""" % genome_id
    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()
    result.append(rows[0][4])
    result.append(rows[0][5])
    result.append(rows[0][6])
    chart['table_data'] = [result, ]
    return chart
Beispiel #3
0
def experiment_info(dbs, confs):
    """XXX Needs refactoring"""
    conf = confs['configurations'][0]
    chart = {}
    chart['table_description'] = [('Read Length', 'number'),
                                  ('Mismatches', 'number'),
                                  ('Description', 'string'),
                                  ('Date', 'string'),
                                  ('Cell Type', 'string'),
                                  ('RNA Type', 'string'),
                                  ('Localization', 'string'),
                                  ('Bio Replicate', 'string'),
                                  ('Partition', 'string'),
                                  ('Paired', 'number'),
                                  ('Species', 'string'),
                                  ('Annotation Version', 'string'),
                                  ('Annotation Source', 'string'),
                                  ('Genome Assembly', 'string'),
                                  ('Genome Source', 'string'),
                                  ('Genome Gender', 'string'),
                                  ]

    conf = confs['configurations'][0]

    meta = get_experiment_dict(confs)

    result = []

    sql = """
select experiment_id,
       project_id,
       species_id,
       genome_id,
       annotation_id,
       template_file,
       read_length,
       mismatches,
       exp_description,
       expDate,
       CellType,
       RNAType,
       Compartment,
       Bioreplicate,
       partition,
       paired
from experiments
%s
order by
    experiment_id;""" % get_experiment_where(confs, meta)
    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()

    if not rows:
        chart['table_data'] = [[None] * len(chart['table_description'])]
        return chart

    species_id = rows[0][2]
    genome_id = rows[0][3]
    annotation_id = rows[0][4]
    result.append(int(rows[0][6]))
    result.append(int(rows[0][7]))
    result.append(rows[0][8])
    result.append(str(rows[0][9]))
    # Use labels instead of the raw values
    mapping = get_cell_display_mapping(dbs)
    result.append(mapping.get(rows[0][10], rows[0][10]))
    mapping = get_rna_extract_display_mapping(dbs)
    result.append(mapping.get(rows[0][11], rows[0][11]))
    mapping = get_localization_display_mapping(dbs)
    result.append(mapping.get(rows[0][12], rows[0][12]))
    result.append(rows[0][13])
    result.append(rows[0][14])
    result.append(rows[0][15])
    if not result[-1] is None:
        result[-1] = ord(result[-1])

    sql = """
select species_id,
       species,
       genus,
       sp_alias,
       abbreviation
from species_info
where species_id='%s'
""" % species_id
    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()
    result.append(rows[0][1])

    sql = """
select annotation_id,
       species_id,
       annotation,
       location,
       version,
       source
from annotation_files where annotation_id='%s'
""" % annotation_id
    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()
    result.append(rows[0][4])
    result.append(rows[0][5])

    sql = """
select genome_id,
       species_id,
       genome,
       location,
       assembly,
       source,
       gender
from genome_files where genome_id='%s'
""" % genome_id
    cursor = dbs[conf['projectid']]['RNAseqPipelineCommon'].query(sql)
    rows = cursor.fetchall()
    cursor.close()
    result.append(rows[0][4])
    result.append(rows[0][5])
    result.append(rows[0][6])
    chart['table_data'] = [result, ]
    return chart