Пример #1
0
def fetch_genome_files(self, params, gbk_dir):
    gfu = GenomeFileUtil(self.callback_url)
    gbk = gfu.genome_to_genbank({'genome_ref':params['input_file']})
    gbk_file = gbk["genbank_file"]["file_path"]
    base = ntpath.basename(gbk_file).rsplit(".", 1)[0]
    name_gbff =  base + ".gbff"
    name_gbk = base + ".gbk"
    shutil.copy(gbk_file, gbk_dir)
    gbff_path = os.path.join(gbk_dir, name_gbff)
    gbk_path = os.path.join(gbk_dir, name_gbk)
    shutil.move(gbff_path, gbk_path)
    return base, gbk_path
Пример #2
0
    def run_CGView(self, ctx, params):
        """
        This example function accepts any number of parameters and returns results in a KBaseReport
        :param params: instance of mapping from String to unspecified object
        :returns: instance of type "ReportResults" -> structure: parameter
           "report_name" of String, parameter "report_ref" of String
        """
        # ctx is the context object
        # return variables are: output
        #BEGIN run_CGView
        print('Starting run_kellyhuangCGView function. Params=')
        print(params)
        # Validating workspace_name and input_file is present
        print('Validating parameters.')
        if 'workspace_name' not in params:
            raise ValueError(
                'Parameter workspace_name is not set in input arguments')
        workspace_name = params['workspace_name']
        if 'input_file' not in params:
            raise ValueError(
                'Parameter input_file is not set in input arguments')

        input_file = params['input_file']

        # Set up CCT project_folder
        subprocess.call(
            "cd /opt/cgview_comparison_tool && ./update_cogs.sh && cgview_comparison_tool.pl -p project",
            shell=True)

        # Turn genome object to Genbank file
        gfu = GenomeFileUtil(self.callback_url)
        gbk = gfu.genome_to_genbank({'genome_ref': input_file})
        gbk_file = gbk["genbank_file"]["file_path"]
        subprocess.call([
            "cp", gbk_file,
            "/opt/cgview_comparison_tool/project/reference_genome"
        ])
        base = ntpath.basename(gbk_file).rsplit(".", 1)[0]
        name_gbff = base + ".gbff"
        name_gbk = base + ".gbk"
        from_path = "/opt/cgview_comparison_tool/project/reference_genome/" + name_gbff
        print("===== from", from_path)
        to_path = "/opt/cgview_comparison_tool/project/reference_genome/" + name_gbk
        print("===== to", to_path)
        subprocess.call(["mv", from_path, to_path])

        # Add Genbank file to project_folder/reference_genome
        # Generate map from Genbank file
        # subprocess.call("cgview_comparison_tool.pl -p project", shell=True)
        os.chdir("/opt/cgview_comparison_tool")
        proc = subprocess.Popen([
            "cgview_comparison_tool.pl", "-p",
            "/opt/cgview_comparison_tool/project"
        ],
                                stdout=subprocess.PIPE)
        # for line in proc.stdout:
        #     print(line)
        proc.wait()
        subprocess.call(["cgview_comparison_tool.pl", "-p", " project"],
                        shell=True)

        # Retrieve map PNG from project_folder/maps
        subprocess.call([
            "cp", "/opt/cgview_comparison_tool/project/maps/medium.png",
            self.shared_folder
        ])
        subprocess.call([
            "cp", "/opt/cgview_comparison_tool/project/maps/medium.html",
            self.shared_folder
        ])

        # Resize image
        basewidth = 900
        img = Image.open('/opt/cgview_comparison_tool/project/maps/medium.png')
        wpercent = (basewidth / float(img.size[0]))
        hsize = int((float(img.size[1]) * float(wpercent)))
        img = img.resize((basewidth, hsize), Image.ANTIALIAS)
        # img = img.resize((600, 600), Image.ANTIALIAS)
        img.save('/opt/cgview_comparison_tool/project/maps/medium1.png',
                 quality=95)
        # print("=====", os.listdir("/opt/cgview_comparison_tool/project/maps/"))
        subprocess.call([
            "cp", "/opt/cgview_comparison_tool/project/maps/medium1.png",
            self.shared_folder
        ])

        png_dir = os.path.join(self.shared_folder, 'medium1.png')
        png_dir_higher = os.path.join(self.shared_folder, 'medium.png')
        html_dir = os.path.join(self.shared_folder, 'medium.html')
        png_dict = {'path': png_dir_higher, 'name': 'Circular_Genome_Map_PNG'}
        html_dict = {'path': png_dir, 'name': 'Circular Genome Map'}
        report_client = KBaseReport(self.callback_url)
        report = report_client.create_extended_report({
            'direct_html_link_index':
            0,
            'html_links': [html_dict],
            'file_links': [png_dict],
            'workspace_name':
            params['workspace_name'],
            'summary_window_height':
            900,
            'html_window_height':
            900
        })
        # subprocess.check_output(["cd", "/opt/cgview_comparison_tool"], shell=True)
        # proj_output = subprocess.check_output(["pwd"], shell=True)
        # print("=====cd /opt/cgview_comparison_tool=====", proj_output)
        #
        # report = KBaseReport(self.callback_url)
        # report_info = report.create({'report': {'objects_created':[],
        #                                         'text_message': params['input_file']},
        #                                         'workspace_name': params['workspace_name']})
        output = {
            'report_name': report['name'],
            'report_ref': report['ref'],
        }
        #END run_CGView

        # At some point might do deeper type checking...
        if not isinstance(output, dict):
            raise ValueError('Method run_CGView return value ' +
                             'output is not type dict as required.')
        # return the results
        return [output]