Exemplo n.º 1
0
    usage = parser.format_usage()
    parser.description = desc1 + '      ' + usage + desc2
    parser.usage = argparse.SUPPRESS
    args = parser.parse_args()
    
    # Get the token from the config file if one is not provided.
    if args.token is None:
        authdata = _read_inifile()
        args.token = authdata['token']
     
    # Workaround for extraneous delimiter tacked on the end of references.
    if args.genomeref[-2:] == '||':
        args.genomeref = args.genomeref[:-2]
    
    # Get the genome object from the workspace.
    wsClient = Workspace(url=args.wsURL, token=args.token)
    try:
        # The get() method returns an array of tuples where the first element is
        # the object's metadata (which is valid json) and the second element is
        # the object's data (which is not valid json).
        object = wsClient.get({ 'objects': [ args.genomeref ] })
        genome = json.loads(object[0][1])

    except WorkspaceServerError as e:
        sys.stderr.write('Failed to get genome using reference %s\n' %(args.genomeref))
        exit(1)

    # Create a worker for running the algorithm.
    worker = ProbAnnotationWorker(genome['id'])
        
    # Run the probabilistic annotation algorithm.
    complexesFile = os.path.join(args.templatedir, '..', 'Complexes.tsv')
    helper.readComplexesFile(complexesFile, includeLinenum=False)
    template['complexes'] = [helper.complexes[key] for key in helper.complexes]

    # Add the template reactions.
    reactionsFile = os.path.join(args.templatedir, 'Reactions.tsv')
    helper.readReactionsFile(reactionsFile, includeLinenum=False)
    template['reactions'] = [helper.reactions[key] for key in helper.reactions]

    # Add the template compounds (constructed from reagents in reactions).
    template['compounds'] = [helper.compounds[key] for key in helper.compounds]

    # Add the template comp compounds (constructed from reagents in reactions).
    template['compcompounds'] = [
        helper.compCompounds[key] for key in helper.compCompounds
    ]

    # Save a local copy for easy reference.
    filename = os.path.join(args.templatedir, args.id + '.json')
    json.dump(template, open(filename, 'w'), indent=4)

    # Save the Model Template typed object to the specified workspace path. An existing typed object
    # is overwritten with the updated data.
    wsClient = Workspace(args.wsurl)
    output = wsClient.create({
        'objects': [[args.ref, 'modeltemplate', {}, template]],
        'overwrite':
        1
    })
    exit(0)
Exemplo n.º 3
0
    parser.usage = argparse.SUPPRESS
    args = parser.parse_args()

    # Get the token from the config file if one is not provided.
    if args.token is None:
        authdata = _read_inifile()
        args.token = authdata['token']

    # Workaround for extraneous delimiter tacked on the end of references.
    if args.genomeref[-2:] == '||':
        args.genomeref = args.genomeref[:-2]
    if args.templateref[-2:] == '||':
        args.templateref = args.templateref[:-2]

    # Get the genome object from the workspace (for the features).
    wsClient = Workspace(url=args.wsURL, token=args.token)
    genome = getObject(wsClient, args.genomeref, args.token)

    # Get the template object from the workspace (for the complexes and roles).
    template = getObject(wsClient, args.templateref, args.token)

    # Build a dictionary to look up roles in the template by ID.
    roles = dict()
    for index in range(len(template['roles'])):
        roles[template['roles'][index]['id']] = index

    # Create a dictionary to map a complex to a list of roles as defined in the template.
    complexesToRoles = dict()
    for index in range(len(template['complexes'])):
        complexId = template['complexes'][index]['id']
        if len(template['complexes'][index]['complexroles']) > 0:
Exemplo n.º 4
0
                'compartmentId']
            reagent['coefficient'] = cpd['stoich']
            reagent[
                'isCofactor'] = 0  # @todo Is this set separately from value in compound?
            rxn['reagents'].append(reagent)
        del rxn['equation']  # Remove after converting to reagent format
        biochem['reactions'].append(rxn)

    # Create the compartment list from the dictionary assembled above.
    biochem['compartments'] = list()
    for id in compartments:
        biochem['compartments'].append(compartments[id])

    # Add the aliases from all of the aliases files.
    print(('Reading aliases from %s ...' % (args.aliasdir)))
    compoundAliases, reactionAliases = helper.readAliasFiles(args.aliasdir)
    biochem['compound_aliases'] = compoundAliases
    biochem['reaction_aliases'] = reactionAliases

    # Save the Biochemistry typed object to the specified workspace path. An existing typed object
    # is overwritten with the updated data.
    print(('Saving typed object to %s ...' % (args.ref)))
    wsClient = Workspace(args.wsurl)
    output = wsClient.create({
        'objects': [[args.ref, 'biochemistry', {}, biochem]],
        'overwrite':
        1
    })

    #    json.dump(biochem, open('master.json', 'w'), indent=4)
    exit(0)
Exemplo n.º 5
0
            else:
                print 'WARNING: Compound %s is not defined in the list of compounds' %(cpd['compound'])
            # Add compartment the first time it is found.
            if cpd['compartmentId'] not in compartments:
                compartments[cpd['compartmentId']] = { 'id': cpd['compartmentId'], 'name': 'Compartment'+cpd['compartmentId'], 'hierarchy': 3}
            reagent['compartment_ref'] = '~/compartments/id/'+cpd['compartmentId']
            reagent['coefficient'] = cpd['stoich']
            reagent['isCofactor'] = 0 # @todo Is this set separately from value in compound?
            rxn['reagents'].append(reagent)
        del rxn['equation'] # Remove after converting to reagent format
        biochem['reactions'].append(rxn)

    # Create the compartment list from the dictionary assembled above.
    biochem['compartments'] = list()
    for id in compartments:
        biochem['compartments'].append(compartments[id])

    # Add the aliases from all of the aliases files.
    print 'Reading aliases from %s ...' %(args.aliasdir)
    compoundAliases, reactionAliases = helper.readAliasFiles(args.aliasdir)
    biochem['compound_aliases'] = compoundAliases
    biochem['reaction_aliases'] = reactionAliases

    # Save the Biochemistry typed object to the specified workspace path. An existing typed object
    # is overwritten with the updated data.
    print 'Saving typed object to %s ...' %(args.ref)
    wsClient = Workspace(args.wsurl)
    output = wsClient.create( { 'objects': [ [ args.ref, 'biochemistry', {}, biochem ] ], 'overwrite': 1 });
    
#    json.dump(biochem, open('master.json', 'w'), indent=4)
    exit(0)