flowcraft/templates/split_fasta.py
def main(sample_id, assembly, min_size):
    """Main executor of the split_fasta template.

    Parameters
    ----------
    sample_id : str
        Sample Identification string.
    assembly : list
        Assembly file.
    min_size : int
        Minimum contig size.

    """

    logger.info("Starting script")

    f_open = open(assembly, "rU")

    entry = (x[1] for x in groupby(f_open, lambda line: line[0] == ">"))

    success = 0

    for header in entry:
        headerStr = header.__next__()[1:].strip()
        seq = "".join(s.strip() for s in entry.__next__())
        if len(seq) >= min_size:
            with open(sample_id + '_' + headerStr.replace(" ","_").replace("=","_") + '.fasta', "w") as output_file:
                output_file.write(">" + sample_id + "_" + headerStr.replace(" ","_").replace("=","_") + "\\n" + seq + "\\n")
                success += 1

    f_open.close()

    logger.info("{} sequences sucessfully splitted.".format(success))
def main(sample_id, assembly, min_size):
    logger.info("Starting script")

    f_open = open(assembly, "rU")

    entry = (x[1] for x in groupby(f_open, lambda line: line[0] == ">"))

    success = 0

    for header in entry:
        headerStr = header.__next__()[1:].strip()
        seq = "".join(s.strip() for s in entry.__next__())
        if len(seq) >= min_size:
            with open(sample_id + '_' + headerStr.replace(" ","_").replace("=","_") + '.fasta', "w") as output_file:
                output_file.write(">" + sample_id + "_" + headerStr.replace(" ","_").replace("=","_") + "\\n" + seq + "\\n")
                success += 1

    f_open.close()

    logger.info("{} sequences sucessfully splitted.".format(success))
def main ( sample_id , assembly , min_size ) : logger . info ( "Starting script" ) f_open = open ( assembly , "rU" ) entry = ( x [ 1 ] for x in groupby ( f_open , lambda line : line [ 0 ] == ">" ) ) success = 0 for header in entry : headerStr = header . __next__ ( ) [ 1 : ] . strip ( ) seq = "" . join ( s . strip ( ) for s in entry . __next__ ( ) ) if len ( seq ) >= min_size : with open ( sample_id + '_' + headerStr . replace ( " " , "_" ) . replace ( "=" , "_" ) + '.fasta' , "w" ) as output_file : output_file . write ( ">" + sample_id + "_" + headerStr . replace ( " " , "_" ) . replace ( "=" , "_" ) + "\\n" + seq + "\\n" ) success += 1 f_open . close ( ) logger . info ( "{} sequences sucessfully splitted." . format ( success ) )
Main executor of the split_fasta template.

    Parameters
    ----------
    sample_id : str
        Sample Identification string.
    assembly : list
        Assembly file.
    min_size : int
        Minimum contig size.
Main executor of the split_fasta template .