Commit 3dd46446 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

check formats

parent 86b67132
......@@ -28,8 +28,9 @@ import copy as _copy
from urlparse import urlparse
from jflow.config_reader import JFlowConfigReader
# import custom types
# import custom types and custom formats
from workflows.types import *
from workflows.formats import *
# define all input type available
......@@ -71,18 +72,6 @@ def inputfile(file):
else:
return urlfile(file)
class Formats(object):
ANY = "any"
BAM = "bam"
FASTQ = "fastq"
FASTA = "fasta"
SFF = "sff"
QUAL = "qual"
FLOW = "flow"
HTML = "html"
class MultipleParameters(object):
def __init__(self, types, required, choices, excludes, default, actions):
self.types = types
......@@ -627,6 +616,9 @@ class AbstractInputFile(AbstractIOFile):
except:
return [input, False]
def check(self, ifile):
eval(self.file_format)(ifile)
class AbstractOutputFile(AbstractIOFile):
"""
......@@ -667,6 +659,7 @@ class InputFile(StrParameter, AbstractInputFile):
jflow_config_reader = JFlowConfigReader()
new_path = os.path.join(jflow_config_reader.get_tmp_directory(), input)
if is_local: new_path = input
self.check(new_path)
return new_path
......@@ -752,6 +745,9 @@ class InputFileList(ParameterList, AbstractInputFile):
for path in path2test:
jflow_config_reader = JFlowConfigReader()
new_vals.append(os.path.join(jflow_config_reader.get_tmp_directory(), path))
# now that all files are downloaded and ok, check the format
for cfile in new_vals:
self.check(cfile)
return new_vals
class OutputFileList(ParameterList, AbstractOutputFile):
......
......@@ -17,6 +17,8 @@
from jflow.workflow import Workflow
from jflow.parameter import InputFileList, InputFile
from workflows.formats import Formats
class Alignment (Workflow):
......@@ -24,9 +26,9 @@ class Alignment (Workflow):
return "Align reads against a reference genome"
def define_parameters(self, function="process"):
self.add_input_file_list("read_1", "Which read1 files should be used", required=True)
self.add_input_file_list("read_2", "Which read2 files should be used (if single end, leave empty)")
self.add_input_file("reference_genome", "Which genome should the read being align on", required=True)
self.add_input_file_list("read_1", "Which read1 files should be used", file_format=Formats.FASTQ, required=True)
self.add_input_file_list("read_2", "Which read2 files should be used (if single end, leave empty)", file_format=Formats.FASTQ)
self.add_input_file("reference_genome", "Which genome should the read being align on", required=True, file_format=Formats.FASTA)
def process(self):
# index the reference genome
......
......@@ -19,7 +19,7 @@ import os
from subprocess import Popen, PIPE
from jflow.component import Component
from jflow.parameter import Formats
from workflows.formats import Formats
from weaver.function import ShellFunction
from weaver.abstraction import Map
......
......@@ -19,7 +19,7 @@ import os
from subprocess import Popen, PIPE
from jflow.component import Component
from jflow.parameter import Formats
from workflows.formats import Formats
from weaver.function import PythonFunction, ShellFunction
......
#
# Copyright (C) 2012 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from jflow import seqio
import os
import sys
class Formats(object):
ANY = "any"
BAM = "bam"
FASTQ = "fastq"
FASTA = "fasta"
SFF = "sff"
def fastq(ifile):
try:
reader = seqio.FastqReader(ifile)
nb_seq = 0
for id, desc, seq, qualities in reader:
nb_seq += 1
# only check the first 10 sequences
if nb_seq == 10: break
except:
sys.stderr.write("Error: The provided file '" + ifile + "' is not a fastq file!\n")
sys.exit(1)
def fasta(ifile):
try:
reader = seqio.FastaReader(ifile, wholefile=True)
nb_seq = 0
for id, desc, seq, qualities in reader:
nb_seq += 1
# only check the first 10 sequences
if nb_seq == 10: break
except:
sys.stderr.write("Error: The provided file '" + ifile + "' is not a fasta file!\n")
sys.exit(1)
def sff(ifile):
try:
reader = seqio.SFFReader(ifile)
nb_seq = 0
for id, desc, seq, qualities in reader:
nb_seq += 1
# only check the first 10 sequences
if nb_seq == 10: break
except:
sys.stderr.write("Error: The provided file '" + ifile + "' is not a sff file!\n")
sys.exit(1)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment