def read_same_samples_file(filename, out_prefix):
    """Reads a file containing same samples."""
    # The same samples
    same_samples = []

    # Creating the extraction files
    gold_file = None
    try:
        gold_file = open(out_prefix + ".gold_samples2keep", 'w')
    except IOError:
        msg = "{}: can't create file".format(out_prefix + ".gold_samples2keep")
        raise ProgramError(msg)

    source_file = None
    try:
        source_file = open(out_prefix + ".source_panel_samples2keep", 'w')
    except IOError:
        msg = ("{}: can't create "
               "file".format(out_prefix + ".source_panel_samples2keep"))
        raise ProgramError(msg)

    with open(filename, 'r') as input_file:
        for line in input_file:
            row = line.rstrip("\r\n").split("\t")

            # Getting the samples
            gold_sample = tuple(row[:2])
            source_sample = tuple(row[2:])
            same_samples.append((gold_sample, source_sample))

            # Printing files
            print >>gold_file, "\t".join(gold_sample)
            print >>source_file, "\t".join(source_sample)

    # Closing the files
    gold_file.close()
    source_file.close()

    return same_samples
def read_same_samples_file ( filename , out_prefix ) : same_samples = [ ] gold_file = None try : gold_file = open ( out_prefix + ".gold_samples2keep" , 'w' ) except IOError : msg = "{}: can't create file" . format ( out_prefix + ".gold_samples2keep" ) raise ProgramError ( msg ) source_file = None try : source_file = open ( out_prefix + ".source_panel_samples2keep" , 'w' ) except IOError : msg = ( "{}: can't create " "file" . format ( out_prefix + ".source_panel_samples2keep" ) ) raise ProgramError ( msg ) with open ( filename , 'r' ) as input_file : for line in input_file : row = line . rstrip ( "\r\n" ) . split ( "\t" ) gold_sample = tuple ( row [ : 2 ] ) source_sample = tuple ( row [ 2 : ] ) same_samples . append ( ( gold_sample , source_sample ) ) print >> gold_file , "\t" . join ( gold_sample ) print >> source_file , "\t" . join ( source_sample ) gold_file . close ( ) source_file . close ( ) return same_samples
Reads a file containing same samples.