Re: [galaxy-dev] problem with python output

2013-07-10 Thread Saket Choudhary
On 11 July 2013 04:31, Saket Choudhary  wrote:
> Apologies if my  previous suggestion confused you :
> http://dev.list.galaxyproject.org/error-while-writing-to-pdf-in-python-tp4660463p4660464.html
>
>
> You may first generate the pdf :
>
> input_file = sys.argv[1]
> output_file = sys.argv[2]
> #txt_in = options.exp_data # + '.txt' ## NOT REQUIRED
>
> mydata = np.loadtxt(input_file)
> plt.figure(1)
> plt.plot(mydata[:,0],mydata[:,1],label = "Feature");
> plt.plot(mydata[:,0],mydata[:,2], label = "Variance");
> plt.xlabel('Distance from feature(bp)');
> plt.ylabel('Score');
> plt.title(sys.argv[1]);
> plt.legend(loc="best")
> pdf_out = output_file + '.pdf'
> plt.savefig(pdf_out)
>
>
> ## Write back to the output file
> ## You can do a shutil.move too [http://docs.python.org/2/library/shutil.html]
> ## like this : shutil.move(pdf_out,output_file)

> data = file(output_file, 'rb').read()

Sorry the above line should be

  data = file(pdf_file, 'rb').read()

> fp = open(output_file, 'wb')
> fp.write(data)
> fp.close()
>
> I tried it locally and it worked. But this is under the assumptio that
> I am passing your python code the input-file from the Galaxy interface
> itself . I just created a CSV and ran the tool. The CSV was simple
> enough :
> 0 1 2
> 2 3 6
>
> Saket
>
> On 11 July 2013 00:19, vijayalakshmi  wrote:
>> Hi,
>>
>>   I am trying to integrate a tool into galaxy. The tool runs in two parts -
>> 1) Computes correlation and provides an ouput 'txt' file (Java)  2)
>> Takes the previously ouput txt file and outputs a 'pdf' file. (Python)
>>
>> I am having trouble with the second tool. If I provide a sample 'txt' file
>> as input, it's working fine. But if I run it in galaxy, it is not working
>> (for some reason it is not reading the 'txt' file from the previous output).
>> Below is the code.
>>
>>
>> #!/usr/bin/python
>>
>> import sys, os
>> import numpy as np
>> import matplotlib.pyplot as plt
>>
>> input_file = sys.argv[1]
>> output_file = sys.argv[2]
>>
>> print 'Number of arguments:', len(sys.argv), 'arguments.'
>> print 'Argument List:', str(sys.argv)
>>
>> txt_in = input_file + '.txt'
>> mydata = np.loadtxt(txt_in)
>> plt.figure(1)
>> plt.plot(mydata[:,0],mydata[:,1],label = "Feature");
>> plt.plot(mydata[:,0],mydata[:,2], label = "Variance");
>> plt.xlabel('Distance from feature(bp)');
>> plt.ylabel('Score');
>> plt.title(sys.argv[1]);
>> plt.legend(loc="best")
>> pdf_out = output_file + '.pdf'
>> plt.savefig(pdf_out)
>>
>> data = file(pdf_out, 'rb').read()
>> fp = open(output_file, 'wb')
>> fp.write(data)
>> fp.close()
>> os.remove(txt_in)
>> os.remove(pdf_out)
>>
>> Below is the xml code.
>>
>> 
>>for the given BAM file 
>>
>> java -jar Extraction.jar
>> $input_bam_file   $ref_filename   $ref_filetype $output1
>> 
>>  plot.py   $output1$out_file1
>> 
>>
>>   
>> > help="Choose an input BAM file"/>
>> > label="Reference/Coordination file" help="Choose a reference file"/>
>> 
>> Custom
>> refGene
>> GFF
>> BED
>> 
>>   
>>   
>>
>>   
>>   
>> 
>>
>> I am forcing the input to be 'tx't and the output to be 'pdf' in the python
>> script. When I run the code, it is not showing any errors but it's not
>> showing any output either. I am able to download the first output 'txt' file
>> but there is no download button option in the right pane of galaxy for the
>> second part.
>>
>> Any help is appreciated!
>>
>> Thanks,
>> VJ.
>>
>> ___
>> Please keep all replies on the list by using "reply all"
>> in your mail client.  To manage your subscriptions to this
>> and other Galaxy lists, please use the interface at:
>>   http://lists.bx.psu.edu/
>>
>> To search Galaxy mailing lists use the unified search at:
>>   http://galaxyproject.org/search/mailinglists/
___
Please keep all replies on the list by using "reply all"
in your mail client.  To manage your subscriptions to this
and other Galaxy lists, please use the interface at:
  http://lists.bx.psu.edu/

To search Galaxy mailing lists use the unified search at:
  http://galaxyproject.org/search/mailinglists/


Re: [galaxy-dev] problem with python output

2013-07-10 Thread Saket Choudhary
Apologies if my  previous suggestion confused you :
http://dev.list.galaxyproject.org/error-while-writing-to-pdf-in-python-tp4660463p4660464.html


You may first generate the pdf :

input_file = sys.argv[1]
output_file = sys.argv[2]
#txt_in = options.exp_data # + '.txt' ## NOT REQUIRED

mydata = np.loadtxt(input_file)
plt.figure(1)
plt.plot(mydata[:,0],mydata[:,1],label = "Feature");
plt.plot(mydata[:,0],mydata[:,2], label = "Variance");
plt.xlabel('Distance from feature(bp)');
plt.ylabel('Score');
plt.title(sys.argv[1]);
plt.legend(loc="best")
pdf_out = output_file + '.pdf'
plt.savefig(pdf_out)


## Write back to the output file
## You can do a shutil.move too [http://docs.python.org/2/library/shutil.html]
## like this : shutil.move(pdf_out,output_file)
data = file(output_file, 'rb').read()
fp = open(output_file, 'wb')
fp.write(data)
fp.close()

I tried it locally and it worked. But this is under the assumptio that
I am passing your python code the input-file from the Galaxy interface
itself . I just created a CSV and ran the tool. The CSV was simple
enough :
0 1 2
2 3 6

Saket

On 11 July 2013 00:19, vijayalakshmi  wrote:
> Hi,
>
>   I am trying to integrate a tool into galaxy. The tool runs in two parts -
> 1) Computes correlation and provides an ouput 'txt' file (Java)  2)
> Takes the previously ouput txt file and outputs a 'pdf' file. (Python)
>
> I am having trouble with the second tool. If I provide a sample 'txt' file
> as input, it's working fine. But if I run it in galaxy, it is not working
> (for some reason it is not reading the 'txt' file from the previous output).
> Below is the code.
>
>
> #!/usr/bin/python
>
> import sys, os
> import numpy as np
> import matplotlib.pyplot as plt
>
> input_file = sys.argv[1]
> output_file = sys.argv[2]
>
> print 'Number of arguments:', len(sys.argv), 'arguments.'
> print 'Argument List:', str(sys.argv)
>
> txt_in = input_file + '.txt'
> mydata = np.loadtxt(txt_in)
> plt.figure(1)
> plt.plot(mydata[:,0],mydata[:,1],label = "Feature");
> plt.plot(mydata[:,0],mydata[:,2], label = "Variance");
> plt.xlabel('Distance from feature(bp)');
> plt.ylabel('Score');
> plt.title(sys.argv[1]);
> plt.legend(loc="best")
> pdf_out = output_file + '.pdf'
> plt.savefig(pdf_out)
>
> data = file(pdf_out, 'rb').read()
> fp = open(output_file, 'wb')
> fp.write(data)
> fp.close()
> os.remove(txt_in)
> os.remove(pdf_out)
>
> Below is the xml code.
>
> 
>for the given BAM file 
>
> java -jar Extraction.jar
> $input_bam_file   $ref_filename   $ref_filetype $output1
> 
>  plot.py   $output1$out_file1
> 
>
>   
>  help="Choose an input BAM file"/>
>  label="Reference/Coordination file" help="Choose a reference file"/>
> 
> Custom
> refGene
> GFF
> BED
> 
>   
>   
>
>   
>   
> 
>
> I am forcing the input to be 'tx't and the output to be 'pdf' in the python
> script. When I run the code, it is not showing any errors but it's not
> showing any output either. I am able to download the first output 'txt' file
> but there is no download button option in the right pane of galaxy for the
> second part.
>
> Any help is appreciated!
>
> Thanks,
> VJ.
>
> ___
> Please keep all replies on the list by using "reply all"
> in your mail client.  To manage your subscriptions to this
> and other Galaxy lists, please use the interface at:
>   http://lists.bx.psu.edu/
>
> To search Galaxy mailing lists use the unified search at:
>   http://galaxyproject.org/search/mailinglists/
___
Please keep all replies on the list by using "reply all"
in your mail client.  To manage your subscriptions to this
and other Galaxy lists, please use the interface at:
  http://lists.bx.psu.edu/

To search Galaxy mailing lists use the unified search at:
  http://galaxyproject.org/search/mailinglists/


Re: [galaxy-dev] problem with python output

2013-07-10 Thread Peter Cock
On Wed, Jul 10, 2013 at 8:03 PM, Björn Grüning
 wrote:
> Hi VJ,
>
> you only can have one  tag in a tool, afaik. You can try to
> write it with cheetah and concatenate several shell commands with && or
> you can extend your python script to call your java tool at first step.
>
> Cheers,
> Bjoern
>

Also this part will break - Galaxy is telling you the filename,
if you add .txt to it then it no longer points to a file on disk:

>> input_file = sys.argv[1]
>> ...
>> txt_in = input_file + '.txt'

Likewise Galaxy has told you which output filename to use,
if you add .pdf to it Galaxy won't find it:

>> output_file = sys.argv[2]
>> ..
>> pdf_out = output_file + '.pdf'

The tool should just use the filenames Galaxy tells it
(and they will end in .dat regardless of the datatype).

Peter

___
Please keep all replies on the list by using "reply all"
in your mail client.  To manage your subscriptions to this
and other Galaxy lists, please use the interface at:
  http://lists.bx.psu.edu/

To search Galaxy mailing lists use the unified search at:
  http://galaxyproject.org/search/mailinglists/


Re: [galaxy-dev] problem with python output

2013-07-10 Thread Björn Grüning
Hi VJ,

you only can have one  tag in a tool, afaik. You can try to
write it with cheetah and concatenate several shell commands with && or
you can extend your python script to call your java tool at first step.

Cheers,
Bjoern

> Hi,
> 
> 
>   I am trying to integrate a tool into galaxy. The tool runs in two
> parts - 1) Computes correlation and provides an ouput 'txt' file
> (Java)  2) Takes the previously ouput txt file and outputs a 'pdf'
> file. (Python)
> 
> 
> I am having trouble with the second tool. If I provide a sample 'txt'
> file as input, it's working fine. But if I run it in galaxy, it is not
> working (for some reason it is not reading the 'txt' file from the
> previous output).  Below is the code.
> 
> 
> 
> 
> #!/usr/bin/python
> 
> 
> import sys, os
> import numpy as np
> import matplotlib.pyplot as plt
> 
> 
> input_file = sys.argv[1]
> output_file = sys.argv[2]
> 
> 
> print 'Number of arguments:', len(sys.argv), 'arguments.'
> print 'Argument List:', str(sys.argv)
> 
> 
> txt_in = input_file + '.txt'
> mydata = np.loadtxt(txt_in)
> plt.figure(1)
> plt.plot(mydata[:,0],mydata[:,1],label = "Feature");
> plt.plot(mydata[:,0],mydata[:,2], label = "Variance");
> plt.xlabel('Distance from feature(bp)');
> plt.ylabel('Score');
> plt.title(sys.argv[1]);
> plt.legend(loc="best")
> pdf_out = output_file + '.pdf'
> plt.savefig(pdf_out)
> 
> 
> data = file(pdf_out, 'rb').read() 
> fp = open(output_file, 'wb')
> fp.write(data)
> fp.close()
> os.remove(txt_in)
> os.remove(pdf_out)
> 
> 
> Below is the xml code.
> 
> 
> 
>for the given BAM file 
> 
> 
> java -jar Extraction.jar
> $input_bam_file   $ref_filename   $ref_filetype $output1
> 
>  plot.py   $output1
>  $out_file1
> 
>   
>   
> 
>  label="Reference/Coordination file" help="Choose a reference file"/>
> 
> Custom
> refGene
> GFF
> BED
> 
>   
>   
>
>   
>   
> 
> 
> 
> I am forcing the input to be 'tx't and the output to be 'pdf' in the
> python script. When I run the code, it is not showing any errors but
> it's not showing any output either. I am able to download the first
> output 'txt' file but there is no download button option in the right
> pane of galaxy for the second part.
> 
> 
> Any help is appreciated!
> 
> 
> Thanks,
> VJ.
> ___
> Please keep all replies on the list by using "reply all"
> in your mail client.  To manage your subscriptions to this
> and other Galaxy lists, please use the interface at:
>   http://lists.bx.psu.edu/
> 
> To search Galaxy mailing lists use the unified search at:
>   http://galaxyproject.org/search/mailinglists/



___
Please keep all replies on the list by using "reply all"
in your mail client.  To manage your subscriptions to this
and other Galaxy lists, please use the interface at:
  http://lists.bx.psu.edu/

To search Galaxy mailing lists use the unified search at:
  http://galaxyproject.org/search/mailinglists/