bash
-
Loop through lines in a file
while read p; do echo "$p" done <peptides.txt
python
-
handle exceptions
while True: ... try: ... x = int(input("Please enter a number: ")) ... break ... except ValueError: ... print("Oops! That was no valid number. Try again...") ## string
-
replace() method
txt = "I like bananas" x = txt.replace("bananas", "apples")
list
-
list comprehension
[v for v in my_list for _ in range(3)] ## dictionary
-
delete a key from a dictionary
a_dict.pop('John')
-
subset a dictionary
myDict = {key:val for key, val in myDict.items() if val != 42}
pandas
-
split a column into multiple
user_df['name'].str.split(pat = ' ', expand = True)
-
drop duplicated rows
df.drop_duplicates()
-
selected rows based on a condition
new = df[~df.filter(regex='^node').isin([3,7,18]).any(1)] df.drop(df[df.score < 50].index)
R
-
subset data to contain only columns whose names match a condition
df[ , grepl( "ABC" , names( df ) ) ]
-
vectorize any funciton
vectorized_substr <- base::Vectorize(substr)
ggplot2
-
beta-diversity
p2 = plot_ordination(GP1, GP.ord, type="samples", color="SampleType", shape="human") p2 + geom_polygon(aes(fill=SampleType)) + geom_point(size=5) + ggtitle("samples")
-
change default shape types
scale_shape_manual(values=c(3, 16))