original_docstring:  Download sequence read data from ENA 
docstring: Download sequence read data from ENA
docstring_tokens: Download sequence read data from ENA
code: def download(
      outdir,
      batch,
      file,
      accession,
      project,
      species,
      query,
      filter,
      scheme,
      ftp,
      limit,
      submitted
  ):
      """ Download sequence read data from ENA """
  
      if file:
          df = pandas.read_csv(file)
          df.columns = [c.lower() for c in df.columns]
          if 'accession' in df:
              accession = df['accession'].tolist()
              project, species, query = (None,) * 3
          elif 'project' in df:
              project = df['project']
              accession, species, query = (None,) * 3
          else:
              print('Could not find columns: accession or project in CSV.')
  
      Path(outdir).mkdir(exist_ok=True, parents=True)
  
      survey = Survey(outdir=outdir)
  
      if query is not None:
          if Path(query).exists():
              query_csv = Path(query)
              survey.query_from_csv(query_csv)
          else:
              raise ValueError(f'Query file does not exist: {query}')
      else:
          survey.query_ena(
              sample=accession,
              study=project,
              species=species,
              term=query,
              scheme=scheme,
              submitted_fastq=submitted
          )
  
          print(survey.query)
  
          query_csv = Path(f"{outdir}/query.csv")
          survey.query_to_csv(query_csv)
  
      if filter is not None:
          survey.filter_query(filter)
  
      if batch > 0:
          batches = survey.batch(batch_size=batch)
          batches = survey.batch_output(
              batches, outdir=Path(outdir)
          )
      else:
          batches = [(
              Path(outdir), query_csv
          )]
  
      for batch_path, batch_csv in batches:
          ascp = MiniAspera()
          ascp.download_batch(
              file=batch_csv,
              outdir=batch_path,
              limit_download=limit,
              ftp=ftp
          )
code_tokens: def download ( outdir , batch , file , accession , project , species , query , filter , scheme , ftp , limit , submitted ) : if file : df = pandas . read_csv ( file ) df . columns = [ c . lower ( ) for c in df . columns ] if 'accession' in df : accession = df [ 'accession' ] . tolist ( ) project , species , query = ( None , ) * 3 elif 'project' in df : project = df [ 'project' ] accession , species , query = ( None , ) * 3 else : print ( 'Could not find columns: accession or project in CSV.' ) Path ( outdir ) . mkdir ( exist_ok = True , parents = True ) survey = Survey ( outdir = outdir ) if query is not None : if Path ( query ) . exists ( ) : query_csv = Path ( query ) survey . query_from_csv ( query_csv ) else : raise ValueError ( f'Query file does not exist: {query}' ) else : survey . query_ena ( sample = accession , study = project , species = species , term = query , scheme = scheme , submitted_fastq = submitted ) print ( survey . query ) query_csv = Path ( f"{outdir}/query.csv" ) survey . query_to_csv ( query_csv ) if filter is not None : survey . filter_query ( filter ) if batch > 0 : batches = survey . batch ( batch_size = batch ) batches = survey . batch_output ( batches , outdir = Path ( outdir ) ) else : batches = [ ( Path ( outdir ) , query_csv ) ] for batch_path , batch_csv in batches : ascp = MiniAspera ( ) ascp . download_batch ( file = batch_csv , outdir = batch_path , limit_download = limit , ftp = ftp )
short_docstring: Download sequence read data from ENA
short_docstring_tokens: Download sequence read data from ENA
comment: """ Download sequence read data from ENA """