Skip to content
Snippets Groups Projects
parse_meta.py 4.51 KiB
Newer Older
Gervaise Henry's avatar
Gervaise Henry committed
#!/usr/bin/env python3

import argparse
import pandas as pd
Gervaise Henry's avatar
Gervaise Henry committed
import warnings
Gervaise Henry's avatar
Gervaise Henry committed
warnings.simplefilter(action='ignore', category=FutureWarning)

Gervaise Henry's avatar
Gervaise Henry committed
def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-r', '--repRID', help="The replicate RID.", required=True)
    parser.add_argument('-m', '--metaFile',
                        help="The metadata file to extract.", required=True)
    parser.add_argument('-p', '--parameter',
                        help="The parameter to extract.", required=True)
Gervaise Henry's avatar
Gervaise Henry committed
    args = parser.parse_args()
    return args


def main():
    args = get_args()
    metaFile = pd.read_csv(args.metaFile, sep=",", header=0)

    # Check replicate RID metadata from 'File.csv'
Gervaise Henry's avatar
Gervaise Henry committed
    if (args.parameter == "repRID"):
        if (len(metaFile.Replicate_RID.unique()) > 1):
            print("There are multiple replicate RID's in the metadata: " +
                  " ".join(metaFile.Replicate_RID.unique()))
            exit(1)
        if not (metaFile.Replicate_RID.unique() == args.repRID):
            print("Replicate RID in metadata does not match run parameters: " +
                  metaFile.Replicate_RID.unique() + " vs " + args.repRID)
            exit(1)
        else:
            rep = metaFile["Replicate_RID"].unique()[0]
Gervaise Henry's avatar
Gervaise Henry committed
            print(rep)
Gervaise Henry's avatar
Gervaise Henry committed
        if (len(metaFile[metaFile["File_Type"] == "FastQ"]) > 2):
            print("There are more then 2 fastq's in the metadata: " +
                  " ".join(metaFile[metaFile["File_Type"] == "FastQ"].RID))
            exit(1)

    # Check experiment RID metadata from 'Experiment.csv'
    if (args.parameter == "expRID"):
        if (len(metaFile.Experiment_RID.unique()) > 1):
            print("There are multiple experoment RID's in the metadata: " +
                  " ".join(metaFile.Experiment_RID.unique()))
            exp = metaFile["Experiment_RID"].unique()[0]
            print(exp)

    # Check study RID metadata from 'Experiment.csv'
    if (args.parameter == "studyRID"):
        if (len(metaFile.Study_RID.unique()) > 1):
            print("There are multiple study RID's in the metadata: " +
                  " ".join(metaFile.Study_RID.unique()))
            study = metaFile["Study_RID"].unique()[0]
    # Get endedness metadata from 'Experiment Settings.csv'
    if (args.parameter == "endsMeta"):
Gervaise Henry's avatar
Gervaise Henry committed
        if (metaFile.Paired_End.unique() == "Single End"):
            endsMeta = "se"
Gervaise Henry's avatar
Gervaise Henry committed
        elif (metaFile.Paired_End.unique() == "Paired End"):
            endsMeta = "pe"
Gervaise Henry's avatar
Gervaise Henry committed
        else:
            endsMeta = "uk"
        print(endsMeta)
    # Manually get endness count from 'File.csv'
    if (args.parameter == "endsManual"):
Gervaise Henry's avatar
Gervaise Henry committed
        if (len(metaFile[metaFile["File_Type"] == "FastQ"]) == 1):
Gervaise Henry's avatar
Gervaise Henry committed
        elif (len(metaFile[metaFile["File_Type"] == "FastQ"]) == 2):
            endsManual = "pe"
        print(endsManual)
    # Get strandedness metadata from 'Experiment Settings.csv'
Gervaise Henry's avatar
Gervaise Henry committed
    if (args.parameter == "stranded"):
        if (metaFile.Has_Strand_Specific_Information.unique() == "yes"):
            stranded = "stranded"
Gervaise Henry's avatar
Gervaise Henry committed
        elif (metaFile.Has_Strand_Specific_Information.unique() == "no"):
            stranded = "unstranded"
Gervaise Henry's avatar
Gervaise Henry committed
        else:
            print("Stranded metadata not match expected options: " +
                  metaFile.Has_Strand_Specific_Information.unique())
Gervaise Henry's avatar
Gervaise Henry committed
            exit(1)
        print(stranded)
    # Get spike-in metadata from 'Experiment Settings.csv'
Gervaise Henry's avatar
Gervaise Henry committed
    if (args.parameter == "spike"):
        if (metaFile.Used_Spike_Ins.unique() == "yes"):
            spike = "yes"
        elif (metaFile.Used_Spike_Ins.unique() == "no"):
            spike = "no"
        else:
            print("Spike-ins metadata not match expected options: " +
                  metaFile.Used_Spike_Ins.unique())
Gervaise Henry's avatar
Gervaise Henry committed
            exit(1)
        print(spike)

    # Get species metadata from 'Experiment.csv'
    if (args.parameter == "species"):
Gervaise Henry's avatar
Gervaise Henry committed
        if (metaFile.Species.unique() == "Mus musculus"):
            species = "Mus musculus"
Gervaise Henry's avatar
Gervaise Henry committed
        elif (metaFile.Species.unique() == "Homo sapiens"):
            species = "Homo sapiens"
Gervaise Henry's avatar
Gervaise Henry committed
        else:
            print("Species metadata not match expected options: " +
                  metaFile.Species.unique())
Gervaise Henry's avatar
Gervaise Henry committed
            exit(1)
        print(species)
Gervaise Henry's avatar
Gervaise Henry committed

    # Get read length metadata from 'Experiment Settings.csv'
    if (args.parameter == "readLength"):
        readLength = metaFile.Read_Length.unique()
        print(str(readLength).strip('[]'))
Gervaise Henry's avatar
Gervaise Henry committed
if __name__ == '__main__':