Add 2d annotation to list of files user Kantale

From PyPedia
Revision as of 20:15, 29 February 2012 by Kantale (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Documentation

Takes a two dimensional dictionary and annotates a list of files. The annotation dictionary should have the form: annotation[column[key1]][column[key2]]. key1 and key2 are integer values indexes of the columns of the list of files, column is the (i,e, tabular split) of the lines of the files. List of files should have of course the same format. For each input file it creates an output file with the name: outputDir + / + baseName of the input file + suffix. The output file contains the columns key1 and key2 of the input files. The output files are usually used for horizontal concatenation of the input files.

Parameters

<inputs>
</inputs>


Return

None

See also

Add_polyphen_annotation_to_SNPs_from_SeattleSeqAnnotation_outputs_user_Kantale

Code

def User_Kantalle_add_2d_annotation_to_list_of_files(listOfFiles=None, key1=None, key2=None, annotation=None, outputDir=None, outputSuffix=None, splitValue="\t", numberOfFirstLinesToIgnore=0):
	
	for file in listOfFiles:
		basename = Get_basename_of_filename_user_Kantale(file)
		
		outputFilename = outputDir + "/" + basename + outputSuffix
		outputFile = open(outputFilename, "w")
		
		inputFile = open(file)
		print file
		
		lineCounter = 0
		while True:
			inputLine = inputFile.readline()
			if inputLine == "": break
			
			lineCounter += 1
			if lineCounter <= numberOfFirstLinesToIgnore: continue
			
			splittedInputLine = inputLine.replace("\n", "").split(splitValue)
			
			key1Value = splittedInputLine[key1]
			key2Value = splittedInputLine[key2]
		
			outputLine = [key1Value, key2Value]
		
			if annotation.has_key(key1Value):
				if annotation[key1Value].has_key(key2Value):
					outputLine += [annotation[key1Value][key2Value]]
				else:
					outputLine += [splitValue]
			else:
				outputLine += [splitValue]
			
			outputFile.write(reduce(lambda x,y:x+splitValue+y, outputLine) + "\n")
		
		outputFile.close()
		inputFile.close()

Unit Tests

def uni1():
   return True

Development Code

def User_Kantalle_add_2d_annotation_to_list_of_files():
	pass

Permissions

Documentation Permissions

Kantale

Code Permissions

Kantale

Unit Tests Permissions

Kantale

Permissions Permissions

Kantale

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox