# -*- coding: utf-8 -*-

"""
Copyright [2009-2017] EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
     http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import operator as op

import luigi

from databases.rfam.clans import parse

from tasks.config import rfam

from tasks.utils.fetch import FetchTask
from tasks.utils.writers import CsvOutput


class RfamClansCSV(luigi.Task):

    def requires(self):
        conf = rfam()
        return FetchTask(
            remote_path=conf.query('clans.sql'),
            local_path=conf.raw('clans.tsv'),
        )

    def output(self):
        conf = rfam()
        return CsvOutput(
            conf.clans,
            ['id', 'name', 'description', 'family_count'],
            op.methodcaller('writeable'),
        )

    def run(self):
        with self.requires().output.open('r') as raw:
            self.output().populate(parse(raw))

@@ -671,22 +671,16 @@
 rfam
-.clans
  import 
 pars
@@ -675,21 +675,21 @@
  import 
-parse
+clans
 %0A%0Afrom t
@@ -717,48 +717,8 @@
 am%0A%0A
-from tasks.utils.fetch import FetchTask%0A
 from
@@ -755,16 +755,61 @@
 vOutput%0A
+from tasks.utils.mysql import MysqlQueryTask%0A
 %0A%0Aclass 
@@ -900,13 +900,18 @@
 urn 
-Fetch
+MysqlQuery
 Task
@@ -928,43 +928,46 @@
     
-remote_path=conf.
+db=conf,%0A            
 query
-('
+=
 clans.
-sql')
+QUERY
 ,%0A  
@@ -1335,16 +1335,22 @@
 opulate(
+clans.
 parse(ra

Use MysqlQueryTask for getting clan data