def __init__(self, model, without_transports=True, timeout=10 * 60):
     '''
     :param model: cobra Model
     '''
     self.model = load_network_model(model)
     self.model.solver.configuration.timeout = timeout
     self.without_transports = without_transports
def generate_angular_friendly_model():
    '''
    This function convert json model into angular friendly json
    '''
    model = load_network_model()
    model_json = json.load(open('../dataset/network/recon2.json'))

    reactions, metabolites = model_json['reactions'], model_json['metabolites']
    model_json = defaultdict(dict)
    model_json['pathways'] = defaultdict(list)

    for m in metabolites:
        m['reactions'] = [
            r.id for r in model.metabolites.get_by_id(m['id']).reactions
        ]
        model_json['metabolites'][m['id']] = m

    for r in reactions:
        # r['gene_reaction_rule'], r['notes'] = [], {}
        del r['gene_reaction_rule']
        del r['notes']

        model_json['reactions'][r['id']] = r
        model_json['pathways'][r.get('subsystem', 'NOpathway')].append(r['id'])

    json.dump(model_json, open('../outputs/ng-recon.json', 'w'))
Esempio n. 3
0
    def __init__(self, network_model="recon2", metrics='mean'):
        model = load_network_model(network_model)
        features = defaultdict(list)

        for r in model.reactions:
            features[r.subsystem].append(r.id)

        super().__init__(features, metrics)
    def __init__(self,
                 reference_label='healthy',
                 network_model='recon2',
                 **kwargs):
        '''
        :param str reference_label: label of refence values in the calculation
        :param str dataset_name: name of metabolitics network
        '''
        model = load_network_model(network_model)

        feature_groups = seq(model.reactions) \
                         .map(lambda r: (r.subsystem, '%s_dif' % r.id)) \
                         .filter(lambda x: not cb.Model.is_transport_subsystem(x[0])) \
                         .group_by_key() \
                         .to_dict()

        super().__init__(reference_label, feature_groups, **kwargs)
Esempio n. 5
0
def coverage_test_metabolites():

    model = load_network_model('recon2')

    X, y = SkUtilsIO('../datasets/diseases/BC.csv') \
        .from_csv(label_column='stage')

    X, y = X[:24], y[:24]

    X = FeatureRenaming(load_metabolite_mapping('toy')) \
        .fit_transform(X, y)

    X = generate_complete_data(model, X, y)
    X = DictInput(StandardScaler()).fit_transform(X, y)

    X = map_dict_list(X, value_func=lambda k, v: v + np.random.normal(0, 0.1))

    SkUtilsIO('../outputs/coverage_test#metabolites.json',
              gz=True).to_json(X, y)
Esempio n. 6
0
def coverage_test_generate():

    model = load_network_model('recon2')

    X, y = SkUtilsIO(
        '../datasets/coverage_test/coverage_test#metabolites.json',
        gz=True).from_json()

    df = pd.DataFrame.from_records(X)
    transformer = MetaboliticsTransformer(model)

    t = time()
    X_ref = transformer.fit_transform(X, y)

    SkUtilsIO('../outputs/coverage_test#coverage=1.json',
              gz=True).to_json(X_ref, y)

    print('Ref done!')
    print(time() - t)

    for i in range(100):

        for coverage in np.linspace(0.95, 0.05, 19):

            selected_metabolite = np.random.choice(
                df.columns,
                int(np.ceil(len(model.metabolites) * coverage)),
                replace=False)

            t = time()
            X_selected = df[selected_metabolite].to_dict('records')
            X_t = transformer.fit_transform(X_selected, y)
            print(time() - t)

            name = 'coverage=%f#iteration=%d' % (coverage, i)

            SkUtilsIO('../outputs/coverage_test#%s.json' % name,
                      gz=True).to_json(X_t, y)
            print('%s done!' % name)
Esempio n. 7
0
def parse_naming_files():

    df = pd.read_csv('../datasets/naming/recon-store-metabolites.tsv',
                     sep='\t')

    model = load_network_model('recon2')
    mappings = defaultdict(dict)

    for i, row in df.iterrows():
        m = '%s_c' % row['abbreviation']

        if m not in model.metabolites:
            continue

        for k in row.keys()[1:]:
            if type(row[k]) == str:
                mappings[k][row[k]] = m

    for k, v in mappings.items():
        db = k.replace('Id', '')

        with open('../outputs/%s-mapping.json' % db, 'w') as f:
            json.dump(v, f)
 def __init__(self, network_model="recon2", reference_label='healthy'):
     self.model = load_network_model(network_model)
     self.reference_label = reference_label