galaxy相关

参考学习网站:https://www.baidu.com/link?url=EJCDOltrqJR7pLE7mdINZZJpKvI030-h6dAQoCazvjq&wd=&eqid=9a4caae20000dd88000000025e9fb09d

1. galaxy每次刷新时,页面东西不变:galaxy中config下的tool_conf.xml里注册ID 与tools的xml里ID不能相同

2. galaxy中command命令的执行:

(1) python3    '$__tool_directory__/ephemeris.py' 

                  --input='$begin'

                  --inputct='$target'

                  --output='$out_ephemeris'

(2) python3 $'/root/galaxy/tools/myTools/aurora_throat/ASI_prepro_fits.py'

                --input='$input'

                --output='$out_file1'

 

(3)执行编译后的fortran代码

$__tool_directory__/tji95

     $input

     $TAPE7

     $TAPE8

     $TAPE16

或者:

'$__tool_directory__/tji95'

             '$input'

             '$TAPE7'

              '$TAPE8'
               '$TAPE16'

或者执行绝对路径:

$'/root/galaxy/tools/myTools/rigidity_cutoff/tji95' 

              '$input'

              '$TAPE7'

              '$TAPE8'

               '$TAPE16'

 

错误的命令方式:   '$/root/galaxy/tools/myTools/auroar_throat/ASI_prepro_fits.py'

 

记住:--input=‘$targe’的等号两边一定不能有空格!!!!!!!,不能写成--input = '$target'

否则报错:

3.xml 的inputs和outputs实际传递参数时,系统会自动加上用户的存储路径信息

4.  commond里面的如何处理多个输出文件

--output1='$out_file1'

--output2='$out_file2'

解析时:

    parser = OptionParser()
    parser.add_option("-i", "--input", type='string', default=INPUTFILE_DEFAULT)#,default=OUTPUTFILE_DEFAULT
    parser.add_option("-o", "--output1", type='string', default=OUTPUTFILE_DEFAULT)
    parser.add_option("-u", "--output2", type='string', default=OUTPUTFILE_DEFAULT)

   output_jpg = option.output1
   output_txt = option.output2

或者

--output="$out_file1>$out_file2"        将整个字符串传递给output,     $out_file1实际等于“/galaxy/database/files/000/……”,$out_file2等于“/galaxy/database/files/000/……” 

解析时:

 output_file = option.output[1].split('>')
        output_file1 = output_file[0]
        output_file2 = output_file[1]
    print(out_fig)
    out_fig.savefig(output_file1,format='eps',papertype='a6',orientation='portrait')
    print('File saved to: ', output_file1)

5. galaxy的命令行判断语句if else 需要空行

 

$__tool_directory__/ap8ae8
        $outputfilename
        #if (str($coordtype.coordtype) == '2'):
           #set $l_fromfile_start = '1'
           #set $l_fromfile_end = '2'
           #set $l_fromfile_gap = '1'
           #set $BB0_fromfile_start = '1'
           #set $BB0_fromfile_end = '2'
           #set $BB0_fromfile_gap = '1'
           #set $coord = '2'
           $set $xlatstart = $coordtype.xlatstart
           #set $xlatend = $coordtype.xlatend
           #set $xlatgap = $coordtype.xlatgap
           #set $xlongstart = $coordtype.xlongstart
           #set $xlongend = $coordtype.xlongend
           #set $xlonggap = $coordtype.xlonggap
           #set $heightstart = $coordtype.heightstart
           #set $heightend = $coordtype.heightend
           #set $heightgap = $coordtype.heightgap
        #elif (str($coordtype.coordtype) == '1'):
           #set $coord = '1'
           #set $l_fromfile_start = $coordtype.l_fromfile_start
           #set $l_fromfile_end = $coordtype.l_fromfile_end
           #set $l_fromfile_gap = $coordtype.l_fromfile_gap
           #set $BB0_fromfile_start = $coordtype.BB0_fromfile_start
           #set $BB0_fromfile_end = $coordtype.BB0_fromfile_end
           #set $BB0_fromfile_gap = $coordtype.BB0_fromfile_gap
           #set $xlatstart = '1'
           #set $xlatend = '2'
           #set $xlatgap = '1'
           #set $xlongstart = '1'
           #set $xlongend = '2'
           #set $xlonggap = '1'
           #set $heightstart = '1'
           #set $heightend = '1'
           #set $heightgap = '1'
        #else:
        #end if

        $coord

       $l_fromfile_start
        $l_fromfile_end
        $l_fromfile_gap
        $BB0_fromfile_start
        $BB0_fromfile_end
        $BB0_fromfile_gap
        $xlatstart
        $xlatend
        $xlatgap
        $xlongstart
        $xlongend
        $xlonggap
        $yearstart
        $yearend
        $yeargap
        $heightstart
        $heightend
        $heightgap
        $model
        $fluxtype
        $E1
        $E2
    </command>

        代码报错如下:

Error in the Python code which Cheetah generated for this template: ================================================================================ expected an indented block (cheetah_DynamicallyCompiledCheetahTemplate_1566376021_12_53765.py, line 139

由于#else和#end if语句之间没有空行造成的错误。


  6.galayx的xml里面命令行参数传递给程序时,都是当成字符串来处理。param里面设置integer ,float等type是对用户输入格式进行设置,与传递参数的格式无关

7.galaxy上传工具操作步骤

(1)编写xml代码和工具代码

如UVI_prepro_cdf.xml:

<tool id="UVI_prepro_cdf" name="PreUVI_CDF" version="1.1.0">
    <description>preprocess UVI aurora image in cdf format</description>
    <requirements>
        <requirement type="package" version="3.7.1">python</requirement>
    </requirements>
    <command detect_errors="aggressive">
        jupyter nbconvert --to script '$__tool_directory__/UVI_prepro_cdf.ipynb' --log-level='ERROR'  &amp;&amp; python3
'$__tool_directory__/UVI_prepro_cdf.py'
        --input='$input'
        --output='$out_file1'

    </command>
    <inputs>
        <param   format="cdf" name="input" type="data" label="Choose Dataset in Cdf Format" />
    </inputs>
    <outputs>
        <data format_source="zip" name="out_file1" metadata_source="input"/>
    </outputs>
    <tests>
        <test>
            <param name="input" value="1.bed"/>
            <output name="out_file1" file="sort_out1.bed"/>
        </test>
    </tests>
    <help>
.. class:: infomark

**TIP:** The input file should be ultraviolet aurora data files in cdf formati. You can choose single or multiple files.

-----

**Introduction**

The tool can read raw ultraviolet aurora in cdf format,denoise,stretch gray scale and smooth image with median filter. The gray value greater than 500 is set to 0, and then grayscale is mapped between 0 and 255. It has been tested with polar satellite aurora data. One cdf file can produce a series of pictures corresponding to one day. The output picture is saved in unit8 format.

    </help>
    <citations></citations>
</tool>
 

 

Oval_segmentation.py:

#!/usr/bin/env python
# coding: utf-8

# In[ ]:


import numpy as np
from skimage import io,exposure
import cv2
from PIL import Image
import keras
from keras.models import load_model
import segmentation_models
from segmentation_models.losses import dice_loss
from segmentation_models.metrics import iou_score
import cdflib
import os
from skimage import filters,exposure
from skimage.morphology import disk
import skimage.filters.rank as sfr
import matplotlib.pyplot as plt
import sys
import argparse
import shutil
if __name__=='__main__':
    path0 = '/home/zhongjia/aurora_data/UVI_data/19961229T191909.png'
    path1 = '/home/zhongjia/aurora_data/ASI_data/'
    save0 = '/home/zhongjia/aurora_data/2016event/'
    save1 = '/home/zhongjia/aurora_data/2017event/'
    parser = argparse.ArgumentParser(description='manual to this script')
    parser.add_argument('--input', type=str, default = None)#输入图像数据
    #parser.add_argument('--cdf2png', type=int, default=32)#读取cdf格式转换为png
    parser.add_argument('--output', type=str, default=32)#去噪参数
    args = parser.parse_args()
    inputloc = args.input
    outputloc = args.output
    # 导入model
    #读取CDF原始图像
    #while (1<9): 
     #  print("yes")

model = load_model('/home/zhongjia/galaxy/tools/myTools/aurora_segment/oval_unet_resnet_block_32_smalldice.h5') #此处必须写绝对路径,不能”./oval_unet_resnet_block_32_smalldice.h5“,因为python程序单独运行时,“./"表示py程序同级目录下,但     #是此处py程序是被xml程序调用,而xml程序是被其他程序调用,”./"应>该是调用xml的程序的同级目录
    # 数据img预处理(输入模型之前)
    #print("hello")
    target_size = 224
    img = Image.open(inputloc)
    img = np.asarray(img.resize((target_size,target_size), Image.ANTIALIAS)) #改变尺寸
    img = np.expand_dims(img,axis=-1) #通道数为1
    img = img/255. #归一化
    #print("hello1")
    # 利用模型进行预测
    img = img.reshape(1,224,224,1)
    Y_preds = model.predict(img) #预测
    binary_thresh = 0.5  #二值化的阈值
    Y_preds_b = (Y_preds>binary_thresh).astype(np.uint8) #将预测mask二值化
    #print("hello2")    
    #将预测结果resize到原始图像尺寸
    Y_preds_ori = np.asarray(Image.fromarray(np.squeeze(Y_preds_b)).resize((200,228),Image.ANTIALIAS)) #resize回原尺寸
    outloc = os.path.join(os.path.dirname(inputloc),'temp.png')
    cv2.imwrite(outloc,Y_preds_ori*255)
    shutil.copyfile(outloc,outputloc)
    os.remove(outloc)
    print("Succeed!")

将xml文件和.py文件放在同一个目录下:~/galaxy/tools/myTools/aurora_segment/

(2)修改注册表文件tool_conf.xml

在~/galaxy/config/tool_conf.xml添加注册工具名称和ID

<section id="hgv" name="Phenotype Association">
    <tool file="evolution/codingSnps.xml" />
    <tool file="evolution/add_scores.xml" />
    <tool file="phenotype_association/sift.xml" />
    <tool file="phenotype_association/linkToGProfile.xml" />
    <tool file="phenotype_association/linkToDavid.xml" />
    <tool file="phenotype_association/ldtools.xml" />
    <tool file="phenotype_association/master2pg.xml" />
  </section>
  <section id="aurora_prepro" name="Preprocess Aurora Data">
    <tool file="myTools/aurora_segment/UVI_prepro_cdf.xml" />
    <tool file="myTools/aurora_segment/UVI_prepro_png.xml" />
    <tool file="myTools/aurora_throat/ASI_prepro_png.xml" />
    <tool file="myTools/aurora_throat/ASI_prepro_fits.xml" />
  </section>
  <section id="aurora_classify" name="Classify Aurora Morphology">
    <tool file="myTools/aurora_throat/ASI_throat_classify.xml" />
    <tool file="myTools/aurora_classifier/ASI_classify.xml" />
  </section>
  <section id="aurora_segment" name="Extract Aurora Oval Boundary">
    <tool file="myTools/aurora_segment/Oval_segment.xml" />
  </section>
  <section id="cuttoff_rigidity" name="Calculate Cutt-off Rigidity">
    <tool file="myTools/rigidity_cutoff/tji95.xml" />
  </section>
  <section id="ephemeris_compute" name="Calculate Planet Ephemeris">
    <tool file="myTools/jpl_eph/ephemeris.xml" />
  </section>
  <section id="geopack_tool" name="Geopack Tool">
    <tool file="myTools/geopack2008/Field_Line_Trace_tool.xml" />
    <tool file="myTools/geopack2008/geopack_tool.xml" />
  </section>
  <section id="chaos6" name="CHAOS">
    <tool file="myTools/CHAOS/chaos6_tool.xml" />
    <tool file="myTools/CHAOS/chaos6_globalmap.xml" />
  </section>
  <section id="apae" name="AP8/AE8">
    <tool file="myTools/ap8ae8/ap8ae8.xml"/>
  </section>
</toolbox>
(3)启动galaxy:bash  ~/galaxy/run.sh 或者sh ~/galaxy/run.sh

即可看见galaxy页面工具是否加载成功

 

7.galaxy的fork功能与文件命令 

galaxy的工具命令规则是,xml文件的文件名与xml内容的工具ID一致。可能是因为for平台工具到用户目录下后,用户目录下的工具id是需要更改的,为了将来更改id方便,统一文件名字与ID

8. ispace  fork工具后修改py文件

ispace 根据xml里面工具id + ipynb后缀确定修改的文件。因此需要先将修改的py文件复制为ipynb文件,在xml里面添加一句转换为py文件的命令,这样主程序import py 文件时依然能找到。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值