
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))


import operator as op

import luigi

from databases.rfam import clans

from tasks.config import rfam

from tasks.utils.writers import CsvOutput
from tasks.utils.mysql import MysqlQueryTask


class RfamClansCSV(luigi.Task):

    def requires(self):
        conf = rfam()
        return MysqlQueryTask(
            db=conf,
            query=clans.QUERY,
            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(clans.parse(raw))

Use MysqlQueryTask for getting clan data
Use MysqlQueryTask for getting clan data

  
  import operator as op
  
  import luigi
  
- from databases.rfam.clans import parse
+ from databases.rfam import clans
  
  from tasks.config import rfam
  
- from tasks.utils.fetch import FetchTask
  from tasks.utils.writers import CsvOutput
+ from tasks.utils.mysql import MysqlQueryTask
  
  
  class RfamClansCSV(luigi.Task):
  
      def requires(self):
          conf = rfam()
-         return FetchTask(
+         return MysqlQueryTask(
-             remote_path=conf.query('clans.sql'),
+             db=conf,
+             query=clans.QUERY,
              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))
+             self.output().populate(clans.parse(raw))
  
Use MysqlQueryTask for getting clan data
## Code Before:

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))

## Instruction:
Use MysqlQueryTask for getting clan data
## Code After:

import operator as op

import luigi

from databases.rfam import clans

from tasks.config import rfam

from tasks.utils.writers import CsvOutput
from tasks.utils.mysql import MysqlQueryTask


class RfamClansCSV(luigi.Task):

    def requires(self):
        conf = rfam()
        return MysqlQueryTask(
            db=conf,
            query=clans.QUERY,
            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(clans.parse(raw))
