Exemple #1
0
def plotSV(svDF, refDF, uniprotPath, args):
    if args.verbose:
        logging.info(
            "iAnnotateSV: Will now try to plot Each Structural Variants")
    upDF = None
    if (os.path.isfile(uniprotPath)):
        upDF = hp.ReadFile(uniprotPath)
    else:
        if args.verbose:
            logging.fatal(
                "iAnnotateSV: %s file does not exist!!, Please use it to plot structural variants",
                uniprotPath)
            sys.exit()

    vsv.VisualizeSV(svDF, refDF, upDF, args)
Exemple #2
0
portTalkingTo = helper.namesAndPorts.get('A')

# Paths to where communication files are stored
pathToAnnToChanFile = './Supplemental Text Files/Ann/Ann-_Chan.txt'
pathToAnnToJanFile = './Supplemental Text Files/Ann/Ann-_Jan.txt'

# Paths to where the resulting log files from communication will be stored
pathToAnnChanLogFile = './Supplemental Text Files/Ann/AnnChanLog.txt'
pathToAnnJanLogFile = './Supplemental Text Files/Ann/AnnJanLog.txt'

# Cleaf log files at the start of the session
helper.WriteToLogFile(pathToAnnChanLogFile, 'w', '')
helper.WriteToLogFile(pathToAnnJanLogFile, 'w', '')

# Reading communication material from the text files
contentAnnToJan = helper.ReadFile(pathToAnnToJanFile)
contentAnnToChan = helper.ReadFile(pathToAnnToChanFile)

# Set this upon keyboard interrupt to let the threads know they have to exit
exitEvent = threading.Event()


# ---------------------------------------------------------------
# This class can be instantiated to create a multithreaded server
# ---------------------------------------------------------------
class ThreadedTCPServer(ThreadingMixIn, TCPServer):
    """Handle requests in a separate thread."""


# ----------------------------------------------------
# Request handler for the server portion of the agents
Exemple #3
0
# Port number for Chan + 1000
listeningport = helper.namesAndPorts.get('Chan')

# Closest router Chan will be sending msgs to
talkingport = helper.namesAndPorts.get('E')

# Communication files path
chantojan_file = './Communication Files/Chan/Chan-Jan.txt'
chantoann_file = './Communication Files/Chan/Chan-Ann.txt'

# Communication Log files
chanjanlog_file = './Communication Files/Chan/Chan-JanLog.txt'
chanannlog_file = './Communication Files/Chan/Chan-AnnLog.txt'

# Traverse communication btw agents from the text files
chantojan_comm = helper.ReadFile(chantojan_file)
chantoann_comm = helper.ReadFile(chantoann_file)

# Make sure log files are empty first
helper.WriteToLogFile(chanjanlog_file, 'w', '')
helper.WriteToLogFile(chanannlog_file, 'w', '')


# Class can be instantiated to create a multi-threaded server
class ServerThread(ThreadingMixIn, TCPServer):
    """Handle requests in a separate thread."""


# Request handler for the server portion of the agents
class RequestHandler(BaseRequestHandler):
    def handle(self):
Exemple #4
0
def main(command=None):

    parser = argparse.ArgumentParser(
        prog='iAnnotateSV.py',
        description='Annotate SV based on a specific human reference',
        usage='%(prog)s [options]')
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        dest="verbose",
                        help="make lots of noise [default]")
    parser.add_argument(
        "-r",
        "--refFileVersion",
        action="store",
        dest="refVersion",
        required=True,
        metavar='hg19',
        help="Which human reference file to be used, hg18,hg19 or hg38")
    parser.add_argument("-rf",
                        "--refFile",
                        action="store",
                        dest="refFile",
                        required=False,
                        metavar='hg19.sv.table.txt',
                        help="Human reference file location to be used")
    parser.add_argument("-ofp",
                        "--outputFilePrefix",
                        action="store",
                        dest="outFilePrefix",
                        required=True,
                        metavar='test',
                        help="Prefix for the output file")
    parser.add_argument("-o",
                        "--outputDir",
                        action="store",
                        dest="outDir",
                        required=True,
                        metavar='/somedir',
                        help="Full Path to the output dir")
    parser.add_argument(
        "-i",
        "--svFile",
        action="store",
        dest="svFilename",
        required=True,
        metavar='svfile.txt',
        help="Location of the structural variants file to annotate")
    parser.add_argument("-d",
                        "--distance",
                        action="store",
                        dest="distance",
                        default=3000,
                        required=False,
                        metavar='3000',
                        help="Distance used to extend the promoter region")
    parser.add_argument(
        "-a",
        "--autoSelect",
        action="store_true",
        dest="autoSelect",
        default=True,
        help="Auto Select which transcript to be used[default]")
    parser.add_argument(
        "-c",
        "--canonicalTranscripts",
        action="store",
        dest="canonicalTranscripts",
        required=False,
        metavar='canonicalExons.txt',
        help=
        "Location of canonical transcript list for each gene. Use only if you want the output for specific transcripts for each gene."
    )
    parser.add_argument("-p",
                        "--plotSV",
                        action="store_true",
                        dest="plotSV",
                        help="Plot the structural variant in question")
    parser.add_argument(
        "-u",
        "--uniprotFile",
        action="store",
        dest="uniprot",
        required=False,
        metavar='uniprot.txt',
        help=
        "Location of UniProt list contain information for protein domains. Use only if you want to plot the structural variant"
    )
    parser.add_argument("-rr",
                        "--repeatFile",
                        action="store",
                        dest="rrFilename",
                        required=False,
                        metavar='RepeatRegionFile.tsv',
                        help="Location of the Repeat Region Bed File")
    parser.add_argument(
        "-dgv",
        "--dgvFile",
        action="store",
        dest="dgvFilename",
        required=False,
        metavar='DGvFile.tsv',
        help="Location of the Database of Genomic Variants Bed File")
    parser.add_argument("-cc",
                        "--cosmicConsensusFile",
                        action="store",
                        dest="ccFilename",
                        required=False,
                        metavar='CosmicConsensus.tsv',
                        help="Location of the Cosmic Consensus TSV file")
    parser.add_argument("-cct",
                        "--cosmicCountsFile",
                        action="store",
                        dest="cctFilename",
                        required=False,
                        metavar='cosmic_fusion_counts.tsv',
                        help="Location of the Cosmic Counts TSV file")
    args = ""
    if (command is None):
        args = parser.parse_args()
    else:
        args = parser.parse_args(command.split())

    # Create Logger if verbose
    loggeroutput = args.outDir + "/" + args.outFilePrefix + "_iAnnotateSV.log"
    logging.basicConfig(
        filename=loggeroutput,
        filemode='w',
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        datefmt='%m/%d/%Y %I:%M:%S %p',
        level=logging.DEBUG)

    coloredlogs.install(level='DEBUG')

    # Check if file for canonical transcript is given or not
    if (args.canonicalTranscripts):
        args.autoSelect = False
    this_dir, this_filename = os.path.split(__file__)
    if (args.refVersion == 'hg18' or args.refVersion == 'hg19'
            or args.refVersion == 'hg38'):
        if (args.refFile):
            pass
        else:
            refFile = args.refVersion + ".sv.table.txt"
            refFile = os.path.join(this_dir, "data/references", refFile)
        if (args.rrFilename):
            rrPath = args.rrFilename
        else:
            rrFilename = args.refVersion + "_repeatRegion.tsv"
            rrPath = os.path.join(this_dir, "data/repeat_region", rrFilename)
        if (args.dgvFilename):
            dgvPath = args.dgvFilename
        else:
            dgvFilename = args.refVersion + "_DGv_Annotation.tsv"
            dgvPath = os.path.join(this_dir,
                                   "data/database_of_genomic_variants",
                                   dgvFilename)
        if (args.ccFilename):
            ccPath = args.ccFilename
        else:
            ccFilename = "cancer_gene_census.tsv"
            ccPath = os.path.join(this_dir, "data/cosmic", ccFilename)
        if (args.cctFilename):
            cctPath = args.cctFilename
        else:
            cctFilename = "cosmic_fusion_counts.tsv"
            cctPath = os.path.join(this_dir, "data/cosmic", cctFilename)
        if (args.uniprot):
            uniprotPath = args.uniprot
        else:
            upFilename = args.refVersion + ".uniprot.spAnnot.table.txt"
            uniprotPath = os.path.join(this_dir, "data/UcscUniprotdomainInfo",
                                       upFilename)

    else:
        if (args.verbose):
            logging.fatal(
                "iAnnotateSV: Please enter correct reference file version. Values can be: hg18 or hg19 or hg38"
            )
            sys.exit()
    (refDF) = hp.ReadFile(refFile)
    NewRefDF = hp.ExtendPromoterRegion(refDF, args.distance)
    svDF = hp.ReadFile(args.svFilename)
    annDF = processSV(svDF, NewRefDF, args)
    plotDF = annDF.copy()
    # Print to TSV file
    outFilePrefixPath = args.outDir + "/" + args.outFilePrefix + "_functional.txt"
    annDF.to_csv(outFilePrefixPath, sep='\t', index=False)
    # Add External Annotations
    if args.verbose:
        logging.info("iAnnotateSV: Adding External Annotations...")
    makeCommandLineForAEA = "-r " + rrPath + " -d " + dgvPath + " -c " + ccPath + " -cct " + cctPath + " -s " + \
        outFilePrefixPath + " -ofp " + args.outFilePrefix + "_Annotated" + " -o " + args.outDir
    aea.main(makeCommandLineForAEA)
    # Plot if required
    if (args.plotSV):
        plotSV(plotDF, NewRefDF, uniprotPath, args)

    if (args.verbose):
        logging.info("iAnnotateSV: Finished Running the Annotation Process!!!")
Exemple #5
0
talkingport = helper.namesAndPorts.get('A')

# Communication path storage
anntochan_file = './Supplemental Text Files/Ann/Ann-Chan.txt'
anntojan_file = './Supplemental Text Files/Ann/Ann-Jan.txt'

# Log file storage
annchan_logfile = './Supplemental Text Files/Ann/Ann-ChanLog.txt'
annjan_logfile = './Supplemental Text Files/Ann/Ann-JanLog.txt'

# Clearing log files
helper.WriteToLogFile(annchan_logfile, 'w', '')
helper.WriteToLogFile(annjan_logfile, 'w', '')

# reading communication files
anntojan_comm = helper.ReadFile(anntojan_file)
anntochan_comm = helper.ReadFile(anntochan_file)

threadingEvent = threading.Event()

# multithreaded server initiation
class ServerThread(ThreadingMixIn, TCPServer):
    """Handle multiple requests separately."""

# request handler class
class RequestHandler(BaseRequestHandler):
    def handle(self):

        # socket connecting to client here
        packetgoingin = self.request.recv(4096)
        packetgoingindecoded = pickle.loads(packetgoingin)
def run(svDFA, refPath, ctPath, allctPath, upPath, verbose):
    if (os.path.isfile(upPath)):
        upDF = hp.ReadFile(upPath)
    else:
        if (verbose):
            logging.critical(
                "iAnnotateSV::AnnotationForKinaseDomain: Location of Uniprot Annoation file is incorrect!!!"
            )
        sys.exit(1)
    if (os.path.isfile(ctPath)):
        ctDF = hp.ReadFile(ctPath)
    else:
        if (verbose):
            logging.warn(
                "iAnnotateSV::AnnotationForKinaseDomain: Location of assay specific canonical transcript file is incorrect!!!"
            )
        ctDF = pd.DataFrame()
    if (os.path.isfile(allctPath)):
        allctDF = hp.ReadFile(allctPath)
    else:
        if (verbose):
            logging.critical(
                "iAnnotateSV::AnnotationForKinaseDomain: Location of all canonical transcript file is incorrect!!!"
            )
        sys.exit(1)
    if (os.path.isfile(refPath)):
        refDF = hp.ReadFile(refPath)
        refDF.columns = refDF.columns.str.replace('#', '')
    else:
        if (verbose):
            logging.critical(
                "iAnnotateSV::AnnotationForKinaseDomain: Location of reference based annotation file is incorrect!!!"
            )
        sys.exit(1)
    svDF = svDFA.copy()
    svDF.insert(loc=9, column='kinase_domain1', value=None)
    svDF.insert(loc=13, column='kinase_domain2', value=None)
    #svDF["kinase_domain1"] = None
    #svDF["kinase_domain2"] = None
    for count, row in svDFA.iterrows():
        # print row
        if (verbose):
            logging.info(
                "iAnnotateSV::AnnotateForKinaseDomain: Checking Entry %d in Uniprot data",
                count)
        chr1 = str(row.loc['chr1'])
        chr2 = str(row.loc['chr2'])
        if (chr1.startswith('chr')):
            chr1 = chr1
        else:
            chr1 = "chr" + chr1
        if (chr2.startswith('chr')):
            chr2 = chr2
        else:
            chr2 = "chr" + chr2
        pos1 = int(row.loc['pos1'])
        pos2 = int(row.loc['pos2'])
        gene1 = str(row.loc['gene1'])
        gene2 = str(row.loc['gene2'])
        site1 = str(row.loc['site1'])
        site2 = str(row.loc['site2'])

        try:
            transcript1 = ctDF.Transcripts[ctDF.Gene[ctDF.Gene ==
                                                     gene1].index.tolist()[0]]
        except IndexError:
            try:
                transcript1 = allctDF.Transcripts[allctDF.Gene[
                    allctDF.Gene == gene1].index.tolist()[0]]
            except IndexError:
                transcript1 = None
        try:
            transcript2 = ctDF.Transcripts[ctDF.Gene[ctDF.Gene ==
                                                     gene2].index.tolist()[0]]
        except IndexError:
            try:
                transcript2 = allctDF.Transcripts[allctDF.Gene[
                    allctDF.Gene == gene2].index.tolist()[0]]
            except IndexError:
                transcript2 = None
        fusion = str(row.loc['fusion'])

        kanno1 = None
        kanno2 = None

        if (fusion != "-"):
            # First Gene +, Second Gene -
            fusionevent = re.search(r'\{(.*)\}', fusion)
            if (fusionevent):
                eventType = fusionevent.group(1)
                if (":" in eventType):
                    # print fusion, fusionevent, eventType
                    (egene1, egene2) = (str(eventType)).split(":")

                    if (transcript1):
                        kanno1 = getKinaseInfo(chr1, pos1, gene1, egene1,
                                               egene2, transcript1, refDF,
                                               upDF)
                    else:
                        kanno1 = None

                    if (transcript2):
                        kanno2 = getKinaseInfo(chr2, pos2, gene2, egene1,
                                               egene2, transcript2, refDF,
                                               upDF)
                    else:
                        kanno2 = None
                else:
                    kanno1 = None
                    kanno2 = None
            else:
                kanno1 = None
                kanno2 = None
            svDF.loc[count, 'kinase_domain1'] = kanno1
            svDF.loc[count, 'kinase_domain2'] = kanno2

    return (svDF)
Exemple #7
0
# Communication path storage
jantochan_file = './Supplemental Text Files/Jan/Jan-Chan.txt'
jantoann_file = './Supplemental Text Files/Jan/Jan-Ann.txt'

# Log file storage
janchan_logfile = './Supplemental Text Files/Jan/Jan-ChanLog.txt'
janann_logfile = './Supplemental Text Files/Jan/Jan-AnnLog.txt'
janairforce_logfile = './Supplemental Text Files/Jan/Jan-AirForceLog.txt'

# Clearing log files
helper.WriteToLogFile(janchan_logfile, 'w', '')
helper.WriteToLogFile(janann_logfile, 'w', '')
helper.WriteToLogFile(janairforce_logfile, 'w', '')

# reading communication files.
jantochan_comm = helper.ReadFile(jantochan_file)
jantoann_comm = helper.ReadFile(jantoann_file)

threadingEvent = threading.Event()


# multithreaded server initiation
class ServerThread(ThreadingMixIn, TCPServer):
    """Handle requests in a separate thread."""


#request handler class
class RequestHandler(BaseRequestHandler):
    def handle(self):

        # socket connecting to client here.