Esempio n. 1
0
            if a != '':
                normal_spin_axis = a
        else:
            assert False, "%s option is not supported" % opt

    if input_path == None:
        print 'No input file was provided.\nYou need to specify an input file\n(e.g. backSPIN -i path/to/your/file/foo.cef)\n'
        sys.exit()
    if outfiles_path == None:
        print 'No output file was provided.\nYou need to specify an output file\n(e.g. backSPIN -o path/to/your/file/bar.cef)\n'
        sys.exit()

    try:
        if verbose:
            print 'Loading file.'
        input_cef = CEF_obj()
        input_cef.readCEF(input_path)

        data = array(input_cef.matrix)

        if feature_fit:
            if verbose:
                print "Performing feature selection"
            ix_features = feature_selection(data, feature_genes, verbose=verbose)
            if verbose:
                print "Selected %i genes" % len(ix_features)
            data = data[ix_features, :]
            input_cef.matrix = data.tolist()
            input_cef.row_attr_values = atleast_2d( array( input_cef.row_attr_values ))[:,ix_features].tolist()
            input_cef.update()
        
Esempio n. 2
0
from Cef_tools import CEF_obj
import numpy as numpy

input_CEF = "BackSPIN_Output_CEF"
output_Clusters = "CLUSTERS_OUTFILE"
output_Gene_Sets = "GENE_SET_OUTFILE"

cef = CEF_obj()
cef.readCEF(input_CEF)
your_array = cef.matrix
attribute_values_list2 = cef.col_attr_names
attribute_values_list1 = cef.row_attr_values
rowvals_list = numpy.transpose(attribute_values_list1)

varListr = ['CellId', 'bRUNID']

numLevel = numpy.alen(attribute_values_list2)
covals_last = numpy.transpose(cef.col_attr_values[numLevel - 1])
covals_gene = numpy.transpose(cef.col_attr_values[0])

covals = numpy.column_stack((covals_gene, covals_last))
covalsFinal = numpy.vstack((varListr, covals))

numpy.savetxt(output_Clusters, covalsFinal, delimiter=",", fmt="%s")
numpy.savetxt(output_Gene_Sets, rowvals_list, delimiter=",", fmt="%s")

# End writing clusters and gene sets.
Esempio n. 3
0
            outfiles_path = a
        elif opt in ('-c', '--clus_attr'):
            clustering_attribute = str(a)
        elif opt in ('-p', '--processes'):
            n_processes = int(a)
        elif opt in ('-s', '--stanfolder'):
            stan_folder = str(a)
        else:
            assert False, "%s option is not supported" % opt

    # Determine the format of the input and read it
    input_format = input_path.split('.')[-1]
    if input_format == 'cef':
        # Load the cef file
        from Cef_tools import CEF_obj
        cef = CEF_obj()
        try:
            print('Loading CEF')
            cef.readCEF(input_path)
        except:
            print('Error in loading CEF file')

    elif input_format == 'loom':
        # Load the loom file
        import loompy
        print("Connecting to the .loom file")
        ds = loompy.connect(input_path)
    else:
        print(
            'The format specified is not accepted. Please provide a .loom or .cef file'
        )
Esempio n. 4
0
# in Zeisel et al. Cell types in the mouse cortex and hippocampus revealed by 
# single-cell RNA-seq Science 2015 (PMID: 25700174, doi: 10.1126/science.aaa1934). 
#
# Building using pyinstaller:
# pyinstaller -F backSPIN.py -n backspin-mac-64-bit
'''

from Cef_tools import CEF_obj
from numpy import genfromtxt
import numpy as numpy
import csv

input_file = "SAMPLE_FILE_FROM_SEQGEQ"
output_file = "BackSPIN_Input_CEF_fName"
date_ran = "DATE_TIME_SCRIPT_RAN"

Arr_values = genfromtxt(input_file, delimiter=',')
gene_names = genfromtxt(input_file, delimiter=',', dtype=str)

with open(input_file, 'rb') as f:
    reader = csv.reader(f)
    cell_names = next(reader)

cef = CEF_obj()
cef.add_header('Date ran', date_ran)

cef.set_matrix(Arr_values[1:, 1:])
cef.add_row_attr('Gene', gene_names[1:, :1])
cef.add_col_attr('CellName', cell_names[1:])
cef.writeCEF(output_file)