I'm new in Cytoscape. I want to know how can I run an app (for example MCL clustering algorithm) multiple times with different parameters in Cytoscape. Is there any way to write an script to do that instead of running manually multiple times for different parameters?
Thanks!
Thanks Scooter.
I saw his answer.
Still I have problem with MCODE.
I figured it out by reading this paper "Cytoscape Automation: empowering workflow-based network analysis".
I want to put the script here in the case that maybe somebody has question.
From python you need to import
import requests, json
import numpy
REST_ENDPOINT = 'http://localhost:1234'
and then let's say we want to use affinity propagation clustering algorithm, then you can go to help->Automation->CyRest command API. Here you can find the app and all its parameters. You load the input network from cytoscape in the beginning.
counter = 0
ap_clusters = dict()
for i in numpy.arange(-1.0, 1.1, 0.1):
message_body = {
"preference": str(round(i,1))
}
response = requests.post(REST_ENDPOINT + '/v1/commands/cluster/ap', data =
json.dumps(message_body), headers = {'Content-Type': 'application/json'})
response_data = response.json()['data']
ap_clusters[counter] = response_data['clusters']
counter += 1
above is a code to call AP clustering multiple times from python.
For AP and MCL the code works for multiple parameters. However when I tried to call MCODE with different set of parameters, it stopped the connection and closed the cytoscape app. It can only run for on set of parameters.
This is the error:
" raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))"
here is the code for mcode algorithm:
counter = 0
mcode_clusters = dict()
for i in numpy.arange(3,6,1):
for j in numpy.arange(0.1,0.56,0.05): #----vertex weight percentage
for h in ["on","off"]:
for f in ["on","off"]:
if f=="on":
for p in [0,0.1,0.2]: #---fluffing percentage
message_body = {
"fluff" : f,
"fluffNodeDensityCutoff" : str(round(p,1)),
"haircut" : h,
"maxDepthFromStart" : str(i),
"nodeScoreCutoff": str(round(j,1))
}
response = requests.post(REST_ENDPOINT + '/v1/commands/cluster/mcode', data = json.dumps(message_body), headers = {'Content-Type': 'application/json'})
response_data = response.json()['data']
mcode_clusters[counter] = response_data['clusters']
counter += 1
If you have any solutions I really appreciate it if you could share it with me.
Thanks.
SaRa
I think this was answered by Ruth pretty clearly in cytoscape-helpdesk:
You can do all of the above. Whatever is easiest for you.
There is a library py2cytoscape that you can use to issue commands to cytoscape from > python. Info can be found here: https://py2cytoscape.readthedocs.io/en/latest/
for more info on automation in cytoscape check out: http://manual.cytoscape.org/en/stable/Programmatic_Access_to_Cytoscape_Features_Scripting.html
But you can also run it through automation. You can create a text file with each of > your commands (for example a list of commands like: cluster mcl attribute="correlation" network=1234") and then go to Tools --> execute batch file to > execute the whole file. I am not sure if support loops. If you want to loop through anything I would recommend using python.
Thanks,
Ruth
I'll just add that currently, looping isn't supported in batch files.
-- scooter
In regard to my problem, I have to say that:
There are two mcode in cytoscape. One is in clusterMaker and the other belongs to cytoscape. When I tried to call mcode, I used the command "'/v1/commands/cluster/mcode'" I called the one in clusterMaker however the parameters' name was based on the one in cytoscape. I changed the command to "'/v1/commands/mcode/cluster'" and the the problem is solved now.
Many thanks.
SaRa
Related
I'm trying to setup the basic suite of spidermon monitors as described here I did a quick Google search and also found this. So I made a quick monitors.py, then copy and pasted the code in there.
I then proceeded to do this:
SPIDERMON_ENABLED = True
SPIDERMON_SPIDER_CLOSE_MONITORS = (
'spidermon.contrib.scrapy.monitors.SpiderCloseMonitorSuite',
)
in my settings.py in the scrapy project.
It keeps raising this error:
spidermon.exceptions.NotConfigured: You should specify a minimum number of items to check against
Which I believe I've done (SPIDERMON_MIN_ITEMS = 10 # "SPIDERMON_MIN_ITEMS" - at the top of the file).
What am I doing wrong? I just want to setup the pre-defined monitors and then optimize them later.
Spidermon couldn't find a valid value for SPIDERMON_MIN_ITEMS in the settings. This must be an integer value bigger than zero otherwise it'll throw the error described. SPIDERMON_ADD_FIELD_COVERAGE set is also mandatory in order to use all the monitors available in this MonitorSuite.
In order to run the built-in close MonitorSuite SpiderCloseMonitorSuite from Spidermon project, please confirm if the settings.py file - located in the root directory of your scrapy project - have the variables below:
EXTENSIONS = {
'spidermon.contrib.scrapy.extensions.Spidermon': 500,
}
SPIDERMON_ENABLED = True
SPIDERMON_MIN_ITEMS = 10
SPIDERMON_ADD_FIELD_COVERAGE = True
SPIDERMON_SPIDER_CLOSE_MONITORS = (
'spidermon.contrib.scrapy.monitors.SpiderCloseMonitorSuite',
)
I am trying to learn ML models for predicting stock prices and initially, I tried using DataReader
import pandas_datareader as web
df = web.DataReader('AAPL', data_source='yahoo', start='2016-01-01', end='2021-08-01')
But I get a RemoteDataError and kept hitting a dead end trying to figure it out so I tried using tiingo
https://tiingo-python.readthedocs.io/en/latest/readme.html
I read through the documentation and tried passing a dictionary with 'api_key' as a key
into my tiingo client, ie.
from tiingo import TiingoClient
client = TiingoClient()
config = {}
config['session'] = True
config['api_key'] = 'my_api_key'
client = TiingoClient(config)
The documentation says I can now use TiingoClient to make API calls, however,
RuntimeError: Tiingo API Key not provided. Please provide via environment variable or config argument.
It is quite challenging learning the ML models and its syntax but what compounds the difficulty for me is what some data-scientests consider to be trivial as they don't typically deal with gathering or scraping data. Maybe my question is trivial but I've spent about an hour trying to figure out how to import data properly for stock prices and the only method that worked for me so far is
df = web.get_data_yahoo('stock symbol')
but I would like to grasp the other ways of importing stock prices via Tiingo and DataReader so if anyone can provide explanations/tips/suggestions I'd greatly appreciate it.
EDIT: for my tiingo account I did not buy any subscription plan for using their data as I was under the impression I can access data for free with my api-key
This is what I use, but its identical to what you are using it seems.
config = {}
config['session'] = True
config['api_key'] = "key here"
client = TiingoClient(config)
Remove this line: TiingoClient()
Could someone walk me through the steps to get the IIS from a Pyomo model using gurobipy?
opt = SolverFactory('gurobi',solver_io='python')
As a reference, this is what I use in JuMP
function getIIS(m::JuMP.Model)
grb_model = m.internalModel.inner
num_constrs = Gurobi.num_constrs(grb_model)
Gurobi.computeIIS(grb_model)
iis_constrs = Gurobi.get_intattrarray(grb_model, "IISConstr", 1, num_constrs)
m.linconstr[find(iis_constrs)]
end
So, basically I need access to the internal gurobi model to run the computeIIS function, and then I need a way to map the array of rows to the actual Pyomo constraints.
thanks!
You can pass this as an option to Gurobi when you call
the solve function by using options_string. Then, Gurobi's Model.write() function will write the file. In this case, you would write a .ilp file, but other file formats exist for different purposes. An example:
solver_parameters = "ResultFile=model.ilp" # write an ILP file to print the IIS
Then, you would add options_string when you call the solve function:
results = solver.solve(instance, options_string=solver_parameters)
You can also string multiple options together with the following syntax. Note the leading empty space within the quotes for the LogToConsole and ResultFile options:
solver_parameters = "TimeLimit=60" # set time limit (seconds)
solver_parameters += " LogToConsole=0" # 0 = turn off console output
solver_parameters += " ResultFile=model.ilp" # write a MIP start file to warm start
The documentation found here applies to solving a model with Gurobi, and the examples at the bottom work with any Gurobi file format:
http://www.gurobi.com/documentation/8.0/refman/solving_a_model2.html
Finally, this link explains the different file formats that Gurobi can write: http://www.gurobi.com/documentation/8.0/refman/model_file_formats.html#sec:FileFormats
See this Pyomo example using suffixes. I believe it's doing what you want.
https://github.com/Pyomo/pyomo/blob/master/examples/pyomo/suffixes/gurobi_ampl_iis.py
How to organize a dictionary of available commands for a Telegram bot? How do good programmers do it? I know that writing dozens of if statements is a bad idea, as well as a switch statement.
For now it's implemented using switch:
The bot receives a command
Finds it in a switch
Processes the command
Sends the response to the user
But when there are dozens of commands, the switch operator becomes hard to maintain. What is the common way to solve this problem?
I'm not a Python coder, but it seems that your problem should be solved with with an associative array data structure regardless the language you use. The actual name of the structure may vary from language to language: for example, in C++ it is called map, and in Python it is.. dictionary! Thus, you several times wrote the relevant keyword in your question (even in the original language).
Bearing the above in mind, a sketch of your program may look like this:
#!/usr/bin/python
# Command processing functions:
def func1():
return "Response 1"
def func2():
return "Response 2"
# Commands dictionary:
d = {"cmd1":func1, "cmd2":func2}
# Suppose this command was receiced by the bot:
command_received = "cmd1"
# Processing:
try:
response = d[command_received]()
except KeyError:
response = "Unknown command"
# Sending response:
print response
I'm trying to organize a large number of CloudWatch alarms for maintainability, and the web console grays out the name field on an edit. Is there another method (preferably something scriptable) for updating the name of CloudWatch alarms? I would prefer a solution that does not require any programming beyond simple executable scripts.
Here's a script we use to do this for the time being:
import sys
import boto
def rename_alarm(alarm_name, new_alarm_name):
conn = boto.connect_cloudwatch()
def get_alarm():
alarms = conn.describe_alarms(alarm_names=[alarm_name])
if not alarms:
raise Exception("Alarm '%s' not found" % alarm_name)
return alarms[0]
alarm = get_alarm()
# work around boto comparison serialization issue
# https://github.com/boto/boto/issues/1311
alarm.comparison = alarm._cmp_map.get(alarm.comparison)
alarm.name = new_alarm_name
conn.update_alarm(alarm)
# update actually creates a new alarm because the name has changed, so
# we have to manually delete the old one
get_alarm().delete()
if __name__ == '__main__':
alarm_name, new_alarm_name = sys.argv[1:3]
rename_alarm(alarm_name, new_alarm_name)
It assumes you're either on an ec2 instance with a role that allows this, or you've got a ~/.boto file with your credentials. It's easy enough to manually add yours.
Unfortunately it looks like this is not currently possible.
I looked around for the same solution but it seems neither console nor cloudwatch API provides that feature.
Note:
But we can copy the existing alram with the same parameter and can save on new name
.